https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109090
Bug ID: 109090
Summary: UBSan signed integer overflow check missing.
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: cbossut21 at gatech dot edu
Target Milestone: ---
$ cat test.c
int printf(const char *, ...);
int a = 3181903460;
int *b, *c = &a;
int **d = &b;
void main(void) {
*d = c;
*b = 0 > *c + *c;
printf("checksum = %X\n", a);
}
UBSan doesn't emit any runtime error messages reporting overflow for the most
recent version of gcc. However in gcc-7 UBSan reports overflow, and the using
the -fwrapv flag produces different output.
$ gcc-7 -O3 -fsanitize=undefined test.c ; ./a.out
test.c:7:15: runtime error: signed integer overflow: -1113063836 * 2 cannot be
represented in type 'int'
checksum = 0
$ gcc-trunk -fwrapv -O3 -fsanitize=undefined test.c ; ./a.out
checksum = 0
$ gcc-trunk -O3 -fsanitize=undefined test.c ; ./a.out
checksum = 1
$ gcc-trunk -fsanitize=undefined test.c ; ./a.out
checksum = 1