From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 74C333858402; Mon, 13 Sep 2021 21:31:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74C333858402 From: "qinzhao at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/102317] New: signed integer overflow sanitizer cannot work well with -fno-strict-overflow Date: Mon, 13 Sep 2021 21:31:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: qinzhao at gcc dot gnu.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 cc 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: Mon, 13 Sep 2021 21:31:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102317 Bug ID: 102317 Summary: signed integer overflow sanitizer cannot work well with -fno-strict-overflow Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: qinzhao at gcc dot gnu.org CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxi= n at gcc dot gnu.org Target Milestone: --- with the latest gcc12: $ cat wrap.c #include #include /* volatile to avoid optimization */ volatile int val; int main(void) { val =3D INT_MAX; val +=3D 1; printf("%d\n", val); return 0; } $ gcc -Wall -O2 -fsanitize=3Dsigned-integer-overflow -o wrap wrap.c $ ./wrap wrap.c:10:9: runtime error: signed integer overflow: 2147483647 + 1 cannot = be represented in type 'int' -2147483648 Things work as expected: the overflow is detected and in this warning mode, the result is a wrap-around. However, the kernel builds with -fno-strict-overflow which removes possible undefined behavior, but I still want the sanitizer to catch this case. Currently it doesn't: $ gcc -Wall -O2 -fsanitize=3Dsigned-integer-overflow -fno-strict-overflow -= o wrap wrap.c $ ./wrap -2147483648=