public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/102317] New: signed integer overflow sanitizer cannot work well with -fno-strict-overflow
@ 2021-09-13 21:31 qinzhao at gcc dot gnu.org
  2021-09-13 21:35 ` [Bug sanitizer/102317] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2021-09-13 21:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102317

            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, marxin at gcc dot gnu.org
  Target Milestone: ---

with the latest gcc12:
$ cat wrap.c
#include <stdio.h>
#include <limits.h>

/* volatile to avoid optimization */
volatile int val;

int main(void)
{
   val = INT_MAX;
   val += 1;
   printf("%d\n", val);
   return 0;
}
$ gcc -Wall -O2 -fsanitize=signed-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=signed-integer-overflow -fno-strict-overflow -o wrap
wrap.c
$ ./wrap
-2147483648

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-02-15  1:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13 21:31 [Bug sanitizer/102317] New: signed integer overflow sanitizer cannot work well with -fno-strict-overflow qinzhao at gcc dot gnu.org
2021-09-13 21:35 ` [Bug sanitizer/102317] " pinskia at gcc dot gnu.org
2021-09-13 21:41 ` qinzhao at gcc dot gnu.org
2021-09-13 21:45 ` pinskia at gcc dot gnu.org
2021-09-13 21:57 ` jakub at gcc dot gnu.org
2021-09-13 22:01 ` qing.zhao at oracle dot com
2021-09-14  5:55 ` jakub at gcc dot gnu.org
2021-09-14 15:57 ` kees at outflux dot net
2021-09-14 16:04 ` jakub at gcc dot gnu.org
2021-09-14 18:36 ` kees at outflux dot net
2021-09-14 18:53 ` jakub at gcc dot gnu.org
2021-09-23 22:58 ` kees at outflux dot net
2023-09-07 20:53 ` qinzhao at gcc dot gnu.org
2024-02-15  1:22 ` i at maskray dot me

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).