https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108497
Bug ID: 108497 Summary: UBsan at -O1 failed to report an 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: --- For the following code, UBsan `-fsanitize=undefined -fno-sanitize-recover=all -O1` failed to report the integer-overflow, while other opt levels reported it. Interestingly, if you don't specify `-fno-sanitize-recover=all`, UBSAN can report it normally. Clang at all opt levels can detect it. Compiler explorer: https://godbolt.org/z/dE1sfcz5f % cat a.c int a, c; long *b; int main() { int d = 0, e = 0; for (; e < 2; e++) f: for (; a; a++) d % *b; d = d + 1228455618; c ^= 0 == 0; if (c) { e = 0; for (; e < 1; e++) ; goto f; } } % % gcc-tk -O1 -fsanitize=undefined -fno-sanitize-recover=all a.c && ./a.out % % gcc-tk -O2 -fsanitize=undefined -fno-sanitize-recover=all a.c && ./a.out /a.c:9:5: runtime error: signed integer overflow: 1228455618 + 1228455618 cannot be represented in type 'int' %