The current -fdelete_null_pointer_checks implementation makes assumptions that the target processor will trap on reads or writes to address zero. Unfortunately, these assumptions are target (often operating system) specific.
Here's a test case for AIX: void abort(); int test(char *ptr) { int x = *ptr; return ptr ? x+1: 2; } int main() { if(test(0) != 2) abort(); } When compiled with mainline this aborts when compiled at -O2 or higher, and passes when compiled at -O1 or lower. AIX allows reads from but not writes to address zero. Other targets, specifically those without virtual memory often allow both reading and writing to address zero. I propose we should add target macros, TARGET_NULL_POINTER_READABLE and TARGET_NULL_POINTER_WRITABLE and control the effects of the -fdelete_null_pointer_checks with that. The current situation is that these transformations are enabled automatically at -O2 without regard to the target environment. -- Summary: flag_delete_null_pointer_checks is target specific Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: roger at eyesopen dot com CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: powerpc-ibm-aix5.2.0.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21305