From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3C682388B6A9; Thu, 15 Dec 2022 12:02:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C682388B6A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671105752; bh=t+jTDwyK+Wg8OA0kwgZIM/P/K3oRCg9rS7GMf5GIpts=; h=From:To:Subject:Date:From; b=IYyu4Fo5sYV7rKV4gd1FRBRdmft0nwCkC5nYZcYKeno8pc93HqTnKAckgBvhFLzns gdHzZnK4htbTA5jYHcWrm0HVawAo9u5bMUtgsPYTJGVbR5cw7csHlmvPnH4crEMyRu AP+eMRMr4QvfljXnafSjjy0OHMLxOPetkY6k82AE= From: "frolov.da at phystech dot edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108127] New: FP due to combination of -Warray-bounds and UBSAN Date: Thu, 15 Dec 2022 12:02:28 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: frolov.da at phystech dot edu 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108127 Bug ID: 108127 Summary: FP due to combination of -Warray-bounds and UBSAN Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: frolov.da at phystech dot edu Target Milestone: --- I've tried to build the next example (which is a reduced example of one of = the functions from firefox): static const unsigned DECPOWERS[10] =3D { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; unsigned foo(int discard, unsigned char *lsu, unsigned char *up) { int count; unsigned cut, quot; count =3D discard; cut =3D discard - (count - 1) - 1; if (cut =3D=3D 1 - 1) { return 8; } else { quot =3D *up >> cut; cut++; return DECPOWERS[1 - cut]; } } $ gcc -O2 -fsanitize-undefined-trap-on-error -Werror=3Darray-bounds=20 -fsanitize=3Dshift,signed-integer-overflow and got an error: : In function 'foo': :16:21: error: array subscript 4294967265 is above array bounds of 'const unsigned int[10]' [-Werror=3Darray-bounds=3D] 16 | return DECPOWERS[1 - cut]; | ~~~~~~~~~^~~~~~~~~ :1:23: note: while referencing 'DECPOWERS' 1 | static const unsigned DECPOWERS[10] =3D { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000} Looks like the builtin functions of the ubsan (such as UBSAN_CHECK_SUB) does not allow optimizations and cause these false positives. If I remove the sanitizer flags then there will be no warning.=