Wrong code: i586-mingw32msvc-g++ (GCC) 4.4.4 (on Ubuntu) Correct code: i586-mingw32msvc-g++ (Gentoo 4.5.2 p1.0, pie-0.4.5) 4.5.2 Build with: i586-mingw32msvc-g++ -O0 -fstack-protector -o wtf.exe wtf.cpp Apparent problem: The function theCompilerWorks() returns false due to the return value true in the al register being clobbered by __Unwind_SjLj_Unregister. The problem only occurs at -O0 in this test case, but the original program fails at -O2. May be related to: Bug 30047 mentions a return value being clobbered by __Unwind_SjLj_Unregister. Testcase: ----- extern "C" void abort(void); void a() {} void (*volatile doNothing)() = a; struct TheCompilerWorks { TheCompilerWorks() {} ~TheCompilerWorks() {} char unusedArray[340]; }; bool theCompilerWorks() { TheCompilerWorks harmlessObject; doNothing(); return true; } int main() { if (!theCompilerWorks()) abort(); } -----
I can reproduce the failure on i686-linux when gcc-4.4.5 is configured with --enable-languages=c,c++ --disable-dwarf2 --enable-sjlj-exceptions, mimicking mingw/mingw-w64. gcc-4.5.2 appears to work though.
Fixed on trunk for 4.5 by r146570: Author: uweigand Date: Wed Apr 22 11:31:56 2009 New Revision: 146570 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146570 Log: * function.c (expand_function_end): Do not emit a jump to the "naked" return label for fall-through returns. * except.c (sjlj_emit_function_exit): Always place the call to the unregister function at the location installed by expand_function_end. This seems to have been intended to fix SJLJ miscompilation on SPU, see the thread starting <http://gcc.gnu.org/ml/gcc-patches/2009-04/msg01265.html>. Backporting this change to 4.4.5 solves the test case failure there too.
*** Bug 30047 has been marked as a duplicate of this bug. ***
*** Bug 48519 has been marked as a duplicate of this bug. ***
Confirmed bug is fixed beginning with 4.4.5