Hide Forgot
Description of problem: GCC optimization at level -O1 or higher hides a NULL-dereference bug in an 'if' statement. Version-Release number of selected component (if applicable): gcc-4.4.5-6.el6.x86_64 and gcc-4.6.2-1.fc16.x86_64 How reproducible: Every time. Steps to Reproduce: 1. Compile the attached sample program with -O1, -O2 or -O3 Actual results: Program runs to completion, returning success. Expected results: Program should crash due to a segmentation fault attempting to dereference 'ptr' in the IF statement. Additional info: If the attached program is built with -O0, the crash does not occur (and may hang around to cause unrelated issues later that are more difficult to track down).
Created attachment 534210 [details] Sample program demonstrating the issue
That is fine, dereferencing a NULL pointer results in undefined behavior, when you reach such a statement the program can do anything, format your disk, segfault, anything else, and the compiler may optimize based on the assumption that it doesn't happen.