https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101432
Bug ID: 101432
Summary: NULL dereferences aren't assumed to be unreachable
even with -fdelete-null-pointer-checks
-fno-isolate-erroneous-paths-dereference
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: josephcsible at gmail dot com
Target Milestone: ---
Target: x86_64-linux-gnu
Consider this C code:
#include <stddef.h>
int f(_Bool x) {
if(x) {
int *null = NULL;
return *null;
} else {
return 42;
}
}
I want this assembly:
f:
movl $42, %eax
ret
But even with -O3 -fdelete-null-pointer-checks
-fno-isolate-erroneous-paths-dereference, I get this assembly:
f:
movl $42, %eax
testb %dil, %dil
je .L1
movl 0, %eax
.L1:
ret