https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107912
Bug ID: 107912 Summary: UBsan at -O0 missed a signed integer overflow Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch 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: --- `gcc-trunk -O0 -fsanitize=undefined -fno-sanitize-recover=all` misses the signed integer overflow, while `gcc-trunk -Ox -fsanitize=address -fno-sanitize-recover=all` (x=1, 2, 3, or s) can detect it. Compiler explorer: https://godbolt.org/z/n8qs3z6v4 % cat a.c unsigned short a; int b; int main() { int c = b = -2147483648; a = (c && 0 == c) - b; __builtin_printf("%d\n", a); } % % gcc-tk -O0 -fsanitize=undefined -fno-sanitize-recover=all a.c &&./a.out 0 % gcc-tk -O1 -fsanitize=undefined -fno-sanitize-recover=all -w a.c &&./a.out a.c:5:21: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself % gcc-tk -O3 -fsanitize=undefined -fno-sanitize-recover=all -w a.c &&./a.out a.c:5:21: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself %