https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66191
Bug ID: 66191 Summary: GCC optimizes away if clause checking similar but not same condition Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: DoDoEntertainment at gmail dot com Target Milestone: --- Created attachment 35561 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35561&action=edit Program that causes issue, executable, preprocessed output, GCC info, etc. Hello everyone, this is my first GCC bug report so please tell me if something is missing. I've added all required by 'https://gcc.gnu.org/bugs/' in provided tar.gz file. The bug happens when using optimization level O2 or higher. Consider this chunk of code: static const double double0_15[]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0}; static double _int2double(unsigned i){ if (i<16) return double0_15[i]; else return _int2double(i/16)*16.0+double0_15[i%16]; } double int2double(int i){ if (i<0) return -_int2double(-i); else return _int2double(i); } If 'int2double' is called with negative value (see attached tar.gz for complete example that reproduces the bug) then if clause in '_int2double' is skipped which causes a segfault if i<-16. The code chunk is taken from free computer algebra system Giac (http://www-fourier.ujf-grenoble.fr/~parisse/giac.html). In attached tar.gz you can find the minimal program that reproduces the issue, preprocessed outputs (.ii, .o and .s files) and invocation log (everything GCC prints to stderr while working, including build configuration, correct version etc.). The system is fully updated ArchLinux with GCC 4.9.2. I've also attached full debug output of clang compiler for convenience because the same program can be compiled with clang without causing error.