https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107908
Bug ID: 107908 Summary: A null pointer dereference bug was missed by UBsan at -O0 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 NULL-pointer-dereference, 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/x7jo7eYYh % cat a.c int a; int main() { int *c; for (int d = 0; d < 1; d++) *c == (a = 0); __builtin_printf("%d\n", *c); } % % gcc-tk -O0 -fsanitize=undefined -fno-sanitize-recover=all a.c &&./a.out 1 % gcc-tk -O1 -fsanitize=undefined -fno-sanitize-recover=all -w a.c &&./a.out a.c:5:5: runtime error: load of null pointer of type 'int' % gcc-tk -O3 -fsanitize=undefined -fno-sanitize-recover=all -w a.c &&./a.out a.c:5:5: runtime error: load of null pointer of type 'int' %