https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91434
Bug ID: 91434 Summary: gcc optimization behaviour is inconsistent with -O2 with 4.1.2 and 4.9.4 Product: gcc Version: 4.9.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rajawrite at gmail dot com Target Milestone: --- Created attachment 46706 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46706&action=edit member variable is not set to NULL when destructor is called manually once and self destruction In our project, we moved from g++ 4.1.2 to 4.9.4. There is behaviour change with member variable setting to NULL when manually called destructor and during self destruction. ouput with gcc 4.9.4: ===================== cds-build15:1044> /usr/local/bin/g++ -O2 sample1.cpp -o sample1.o cds-build15:1045> ./sample1.o FSPGI ctor1 FSPI ctor FSPG ctor FSPGI ctor FSPGI dtor m_g is not NULL FSPG dtor FSPI dtor FSPGI dtor m_g is not NULL FSPG dtor *** Error in `./sample1.o': double free or corruption (fasttop): 0x000000000137c010 *** ======= Backtrace: ========= /lib64/libc.so.6(+0x81499)[0x7fd25345e499] ouput with gcc 4.9.4 with -fno-tree-dse: ======================================== cds-build15:1048> /usr/local/bin/g++ -O2 -fno-tree-dse sample1.cpp -o sample1.o cds-build15:1049> ./sample1.o FSPGI ctor1 FSPI ctor FSPG ctor FSPGI ctor FSPGI dtor m_g is not NULL FSPG dtor FSPI dtor FSPGI dtor cds-build15:1050> output with g++ 4.1.2: ====================== cds-build3:1011> g++ -O2 sample1.cpp -o sample1.o cds-build3:1012> ./sample1.o FSPGI ctor1 FSPI ctor FSPG ctor FSPGI ctor FSPGI dtor m_g is not NULL FSPG dtor FSPI dtor FSPGI dtor cds-build3:1013> Please check if this is the correct behviour and -fno-tree-dse should be used for this code and impact of disabling dse.