From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B6FF13858400; Sat, 11 Sep 2021 15:43:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6FF13858400 From: "hv at crypt dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102291] New: dubious overflow warning Date: Sat, 11 Sep 2021 15:43:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hv at crypt dot org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Sat, 11 Sep 2021 15:43:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102291 Bug ID: 102291 Summary: dubious overflow warning Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: hv at crypt dot org Target Milestone: --- The following code warns with gcc-11.2.0 (but not with 9.2.1-17ubuntu1~18.0= 4.1) in testera(), but not in testerb() which differs only by the removal of an assert. I don't understand this, and cannot see what is overflowing. This is reduced from a report against the UTF8_ACCUMULATE macro in perl sou= rce. This build of gcc was configured as follows (including the error in prefix): ../gcc/configure --prefix=3D/opt/gcc-12 --disable-gcov --disable-multilib --enable-languages=3Dc --disable-nls --disable-decimal-float % uname -a Linux zen2 5.4.0-73-generic #82~18.04.1-Ubuntu SMP Fri Apr 16 15:10:02 UTC = 2021 x86_64 x86_64 x86_64 GNU/Linux % gcc --version | head -1 gcc (GCC) 11.2.0 % cat test.c /* #include */ extern void __assert_fail (const char *__assertion, const char *__file, unsigned int __line, const char *__function) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__)); #define assert(expr) \ ((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \ if (expr) \ ; /* empty */ \ else \ __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \ })) #define __ASSERT_FUNCTION __extension__ __PRETTY_FUNCTION__ /* end assert.h */ typedef unsigned long ulong; typedef unsigned char uchar; #define FIT8(c) assert(((sizeof(c) =3D=3D 1) || (((ulong) (c)) >> 8) =3D=3D= 0)) #define BE8a(c) (FIT8(c), ((uchar) (c))) #define BE8b(c) ( ((uchar) (c))) #define NUM(c) ((c) | 0) #define TESTER(old, new) ((((ulong)(old)) << 6) | (((uchar) NUM(new)) & 0x3= f)) ulong testera(ulong ul) { return TESTER(ul, BE8a(0x80)); } ulong testerb(ulong ul) { return TESTER(ul, BE8b(0x80)); } % gcc -c test.c=20 test.c: In function 'testera': test.c:24:49: warning: overflow in conversion from 'int' to 'long unsigned = int' changes value from '((((void)4, (({...}))), 128)) & 63' to '0' [-Woverflow] 24 | #define TESTERa(old, new) ((((ulong)(old)) << 6) | (((uchar) NUM(ne= w)) & 0x3f)) | ^ test.c:27:12: note: in expansion of macro 'TESTERa' 27 | return TESTERa(ul, BE8a(0x80)); | ^~~~~~~ %=