-
Type:
Enhancement
-
Resolution: Won't Implement
-
Priority:
Not Prioritized
-
Code Generation Tools
-
CODEGEN-14178
-
C29_1.0.0.LTS
-
default
-
To tell the compiler to handle a null pointer dereference like any other pointer dereference, use the option -fno-delete-null-pointer-checks.
This example code intentionally dereferences a NULL pointer.
#include <stdlib.h>
void external_call();
void ub_example()
{
external_call();
unsigned int *const addr = NULL;
(*addr) = 0xdeadbeef;
external_call();
}
Build it with optimization -O1 or higher ...
c29clang -O1 -S file.c
Inspect the assembly file to see a very minimal function ...
ub_example: ; @ub_example
; %bb.0:
CALL @external_call
The rest of the function, including the return instruction, is optimized away.
Consider changing the compiler to only optimize away the expression that contains undefined behavior. Or something else that is more friendly.