From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id E72DB1F45E for ; Mon, 17 Feb 2020 21:03:47 +0000 (UTC) Received: from localhost ([::1]:53018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3nYQ-0008SP-QQ for normalperson@yhbt.net; Mon, 17 Feb 2020 16:03:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40479) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3nYN-0008SF-Dn for bug-gnulib@gnu.org; Mon, 17 Feb 2020 16:03:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j3nYM-0005dg-H3 for bug-gnulib@gnu.org; Mon, 17 Feb 2020 16:03:43 -0500 Received: from mo6-p01-ob.smtp.rzone.de ([2a01:238:20a:202:5301::2]:21188) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j3nYM-0005bK-1y for bug-gnulib@gnu.org; Mon, 17 Feb 2020 16:03:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1581973418; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=RESngGh4sExeZ+S9/j6et3fCUGN6+9NJIwy4YCDsBwQ=; b=Pe7cV+81hwkwIy+zknBMwZXFsLQLW6Yw0lYGrBTQdFH2ieB0pGFFAj341a9fxbpfgw T0RJqROP58UFDcOmwVT+rWLX48NCH3A970Qj7kFqGIEn4mjf1j3Lu1Jpjf86PQw6xYRQ MyMZ6SbWx648IFHB/3yQ1+hDZMJja6n2SfFL1RuA4Ph3cX2TkW90ctUqS59d+rD3xFD4 y+zaKbbcOWICbBCH177F7SzfRm6sRXjXbSb1aMwZPNTjyq9yZzBT7MKT0eh0f/vJB8XB SvJhvVxk2RzS4bL0puQX7SK1SMQrz0+iUIpDLsZseokzlFvtdLzcDGS2xGWpSckhRhu7 fGmw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6fzxfs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.1.12 DYNA|AUTH) with ESMTPSA id g00701w1HL3QJhx (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Mon, 17 Feb 2020 22:03:26 +0100 (CET) From: Bruno Haible To: Tim =?ISO-8859-1?Q?R=FChsen?= Subject: Re: restrict Date: Mon, 17 Feb 2020 22:03:26 +0100 Message-ID: <11144704.2Qh8oC9nIl@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <82caf012-4998-2d98-52b6-8eac1ca4af72@gmx.de> References: <20200209144434.GA19087@aun.utmark.mea> <2029541.RzEzKTdQOE@omega> <82caf012-4998-2d98-52b6-8eac1ca4af72@gmx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5301::2 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert , bug-gnulib@gnu.org, Mats Erik Andersson Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hi Tim, > > Yes, and this in turn means that the ability to produce useful warnings via > > 'restrict' is limited. In this example: > > =================================================================== > > #include > > extern void memmcpy (void *restrict, const void *restrict, size_t); > > > > void shuffle (char array[10]) > > { > > memmcpy (array + 2, array, 8); > > memcpy (array + 2, array, 8); > > } > > =================================================================== > > gcc gives no warning about 'memmcpy' - because it does not know > > how many elements the function will access. gcc does give a warning > > about 'memcpy' - apparently due to custom logic in the compiler. > > The following gives you a warning, with -O2 / -O3 and -Wall: > > =================================================================== > #include > void memmcpy (void *restrict d, void *restrict s, size_t n) > { > memcpy(d, s, n); > } > > void shuffle () > { > char array[] = "abcdefg", *array2 = array + 2; > > memmcpy (array, array2 - 2, 8); > } > =================================================================== That's precisely my point: GCC can not and will not give you warnings about overlapping array slices, unless the function is one of the predefined functions (memcpy in this case). 'restrict' for optimization is designed for accesses to array (cf. the many examples regarding loops that iterate over an array). But the warnings emitted by GCC can only recognize the special case of two pointers being equal. Bruno