From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from www523.your-server.de (www523.your-server.de [159.69.224.22]) by sourceware.org (Postfix) with ESMTPS id E20493857826 for ; Fri, 29 Jul 2022 14:27:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E20493857826 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tim-lange.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tim-lange.me DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tim-lange.me; s=default2108; h=To:Cc:Subject:From:Message-Id:Date: Content-Type:Content-Transfer-Encoding:Mime-Version:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=lF+17uoEUcGkyaD7fXZ/ey5rkG1L4hlWn77JtI9yA9w=; b=dnO28IKyQFT0pjYb5PFZFCHtVo JVe4wL1Jg4TL11StvwG/mkyFDIQv5aXWYXVylENQEEwG5OLSHaomMCllYz84l1UYlXdlqkPU1jtNv bzLJu5Sk2sRTIfTWoPDSJJHocCVOLUDZeORGhdV1ZRSdyh/YCgZ0QHFQV+JE5ZiZgVT8OB7QfqdJn wb12kqeV0zdkM3KWw9fkqGR1ZckJqCQeN3ugomt/OLwAw5MXdiLePw14YPzHuMm+oKJ/6zOzpnnPh oBU5g9kU+q8CMHOqC77RO6SoRfhRj5cv+Xav2lf1gAA0OGN3PTXhGVEOLiC63Z+y22RsbjKR9ygBs +/oK3f9Q==; Received: from sslproxy05.your-server.de ([78.46.172.2]) by www523.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1oHQxr-0004Zg-Si; Fri, 29 Jul 2022 16:27:44 +0200 Received: from [2a02:908:1861:d6a0::f4e2] (helo=localhost) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oHQxr-00059G-OA; Fri, 29 Jul 2022 16:27:43 +0200 Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 29 Jul 2022 16:27:43 +0200 Message-Id: From: "Tim Lange" Subject: GCC warns on defined behavior with Wrestrict? To: X-Mailer: aerc 0.10.0 X-Authenticated-Sender: mail@tim-lange.me X-Virus-Scanned: Clear (ClamAV 0.103.6/26615/Thu Jul 28 09:58:07 2022) X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_INFOUSMEBIZ, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2022 14:27:47 -0000 Hi everyone, while testing a new buffer overlap and restrict checker in the analyzer, it emitted a warning inside coreutils. During the discussion [0], Paul Eggert posted a link to the current draft of the next C standard [1] with new examples for the definition of 'restrict'. Especially example 3 in 6.7.3.1 is interesting: void h(int n, int * restrict p, int * restrict q, int * restrict r) { int i; for (i =3D 0; i < n; i++) p[i] =3D q[i] + r[i]; } The draft says that a call h(100, a, b, b) is *defined* behavior because 'b' is never modified inside the method. That brings up the question how GCC should handle this. At the moment, Wrestrict (and my new Wanalyzer-restrict) warns on defined behavior: /path/to/main.c:70:13: warning: passing argument 3 to =E2=80=98restrict= =E2=80=99-qualified parameter aliases with argument 4 [-Wrestrict] 70 | h(100, a, b, b); | ^ ~ But finding out that 'q' and 'r' are never modified needs a pass over the callee. Further, when the callee implementation isn't available at the point Wrestrict runs, we couldn't emit a warning at all if we don't want any false positive. I thought maybe a tradeoff would be to keep warning without checking for writes on parameters in the callee but additionally issue a fix-it hint that if the memory location the parameter points to is never written, to add the points-to const type qualifier. The addition of the const qualifier simplifies deducing that the memory location the parameter point to is never written for Wrestrict and already silences the warning. What do you think? - Tim [0] https://lists.gnu.org/archive/html/bug-gnulib/2022-07/msg00066.html [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2912