From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0F298385841A; Sun, 31 Jul 2022 09:02:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F298385841A From: "b.buschinski at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98109] Seemingly wrong warnings from -Wnonnull when combined with -O2 -fsanitize=undefined Date: Sun, 31 Jul 2022 09:02:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: b.buschinski at googlemail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jul 2022 09:02:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98109 Bernd Buschinski changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |b.buschinski at googlemail= dot com --- Comment #4 from Bernd Buschinski -= -- I also hit this problem, but not 100% sure if this is a duplicate or not. Because as far as I can remember it used to work with GCC-11 (can not test = now only have 12) and only started failing with GCC 12. Can someone tell me if this should be a new bug or is just a duplicate? Known to fail on: - sys-devel/gcc-12.1.1_p20220625 (Gentoo) - gcc-12.1.1-1.fc36.x86_64 12.1.1 20220507 (Red Hat 12.1.1-1) (Fedora) - 12-20220319-1ubuntu1 (Ubuntu 22.04) Compiler explorer: https://godbolt.org/z/rrWffMe9x Code: #include extern void *my_memmem(const void *__haystack, size_t __haystacklen, const void *__needle, size_t __needlelen) __THROW __attribute_pure__ __nonnull ((1, 3)) __attribute__((access(__read_only__, 1, 2))) __attribute__((access(__read_only__, 3, 4))); #define CONTAINSCONST(_cstring, string)=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 \ ({=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 \ size_t const tmp_CONST_LEN =3D sizeof(string) - 1;=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ ((_cstring).length >=3D tmp_CONST_LEN &&=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 \ (my_memmem((_cstring).buffer, (_cstring).length, string, tmp_CONST_LEN= ) !=3D \ NULL));=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 \ }) struct my_string { unsigned char *buffer; unsigned long long length; }; int foo(struct my_string const *const ss) { struct my_string const str_path =3D *ss; if (CONTAINSCONST(str_path, "/") || CONTAINSCONST(str_path, ".abcd") || CONTAINSCONST(str_path, "?")) { return 1; } return 0; } // $ gcc -std=3Dgnu99 -Wall -Wextra -Walloc-zero -O2 -fsanitize=3Dundefined= -Werror test2.c -S // test2.c: In function 'foo': // test2.c:13:7: error: argument 1 is null but the corresponding size argum= ent 2 value is [5, 18446744073709551615] [-Werror=3Dnonnull] // 13 | (my_memmem((_cstring).buffer, (_cstring).length, string, tmp_CONST_LEN) !=3D \ // |=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // test2.c:26:7: note: in expansion of macro 'CONTAINSCONST' // 26 | CONTAINSCONST(str_path, ".abcd") || // | ^~~~~~~~~~~~~ // test2.c:3:14: note: in a call to function 'my_memmem' declared with attribute 'access (read_only, 3, 4)' // 3 | extern void *my_memmem(const void *__haystack, size_t __haystack= len, // | ^~~~~~~~~ // cc1: all warnings being treated as errors=