Setup: arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3 built with crosstool-0.29, running on proprietary ARM hardware. Does not happen with CodeSourcery's 3.4.3 arm-none-linux-gnueabi 2005Q1B, so it's possible that this bug is of historical interest only. On the other hand, I don't have a non-CodeSourcery crosstool build later than 3.4.1, so I can't be sure it's fixed in the Free Software Tree. The code below prints "Destructing o (35092)" when compiled with -O1 -fcse-follow-jumps, but "Destructing o (-1)" when compiled with -O1 without -fcse-follow-jumps. Oddly, the problem did not occur when compiling with -fcse-follow-jumps plus all the optimizations listed as constituting -O1 in the gcc-3.4.4 documentation. Here's the source code:
extern "C" void printf(const char*,...); class o { public: int id; o(int i) : id(i) { printf("Constructing o (%d)\n", id); } ~o() { printf("Destructing o (%d)\n", id); } }; void f2(void) { o o_ary[1] = {-1}; throw (int)64; } int main(void) { printf("Entering main\n"); try { f2(); } catch (int i) { printf("Caught %d\n", i); } printf("Exiting main\n"); } (Based on a more complicated test case by Kenneth Albanowski.) Here's the target session, with -fcse-follow-jumps: ~ # /opt/palmos/tests/compiler/tmp/110057_eh_case22B_O1_fcse-follow-jumps.kj Entering main Constructing o (-1) Destructing o (35092) Destructing o (-1098326664) Destructing o (-1098326568) Destructing o (1076856328) Destructing o (0) Destructing o (35004) Destructing o (35360) Destructing o (1) Destructing o (35260) Destructing o (-1098326524) Destructing o (-1) Caught 64 Exiting main Here's a session without -fcse-follow-jumps: ~ # /opt/palmos/tests/compiler/tmp/110057_eh_case22B_O1.kj Entering main Constructing o (-1) Destructing o (-1) Caught 64 Exiting main (An x86 checking build of gcc 3.4.3 agreed.) Here's the host session: 161> /opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/arm-softfloat-linux-gnu-g+ + -O1 -fcse-follow-jumps -v -save-temps -o /exported/device_root/opt/palmos/tests/compiler/ tmp/110057_eh_case22B_O1_fcse-follow-jumps.kj ../cpp/eh_samples/110057_eh_case22B.cpp Reading specs from /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/ gcc/arm-softfloat-linux-gnu/3.4.1/specs Configured with: /home/kennetha/crosstool-0.29/build/arm-softfloat-linux-gnu/gcc-3.4.1- glibc-2.3.3/gcc-3.4.1/configure --target=arm-softfloat-linux-gnu --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3 --with-float=soft --with- headers=/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/arm-softfloat-linux-gnu/ include --with-local-prefix=/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/arm- softfloat-linux-gnu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable- __cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long Thread model: posix gcc version 3.4.1 /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../libexec/gcc/arm- softfloat-linux-gnu/3.4.1/cc1plus -E -quiet -v -iprefix /home/opt/crosstool/arm-softfloat-linux- gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat-linux-gnu/3.4.1/ -D_GNU_SOURCE - D__ARM_ARCH_3__ ../cpp/eh_samples/110057_eh_case22B.cpp -msoft-float -fcse-follow-jumps -O1 -o 110057_eh_case22B.ii ignoring duplicate directory "/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../include/c++/3.4.1" ignoring duplicate directory "/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../include/c++/3.4.1/arm-softfloat-linux-gnu" ignoring duplicate directory "/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../include/c++/3.4.1/backward" ignoring duplicate directory "/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/ arm-softfloat-linux-gnu/3.4.1/include" ignoring duplicate directory "/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/sys-include" ignoring duplicate directory "/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/../../../../include/c++/3.4.1 /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/../../../../include/c++/3.4.1/arm-softfloat-linux-gnu /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/../../../../include/c++/3.4.1/backward /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/include /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/sys-include /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/include End of search list. /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../libexec/gcc/arm- softfloat-linux-gnu/3.4.1/cc1plus -fpreprocessed 110057_eh_case22B.ii -quiet -dumpbase 110057_eh_case22B.cpp -msoft-float -auxbase 110057_eh_case22B -O1 -version -fcse-follow-jumps -o 110057_eh_case22B.s GNU C++ version 3.4.1 (arm-softfloat-linux-gnu) compiled by GNU C version 3.3.4 (pre 3.3.5 20040809). GGC heuristics: --param ggc-min-expand=90 --param ggc-min-heapsize=113332 /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/bin/as -mfpu=softfpa -o 110057_eh_case22B.o 110057_eh_case22B.s /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../libexec/gcc/arm- softfloat-linux-gnu/3.4.1/collect2 --eh-frame-hdr -dynamic-linker /lib/ld-linux.so.2 -X -m armelf_linux -p -o /exported/device_root/opt/palmos/tests/compiler/tmp/ 110057_eh_case22B_O1_fcse-follow-jumps.kj /home/opt/crosstool/arm-softfloat-linux-gnu/ gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat-linux- gnu/lib/crt1.o /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/lib/crti.o /home/opt/crosstool/arm- softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat-linux-gnu/3.4.1/crtbegin.o - L/home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat- linux-gnu/3.4.1 -L/home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/ gcc -L/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/arm-softfloat-linux- gnu/3.4.1 -L/home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/lib -L/opt/crosstool/arm-softfloat- linux-gnu/gcc-3.4.1-glibc-2.3.3/lib/gcc/arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat- linux-gnu/lib 110057_eh_case22B.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/opt/ crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/arm-softfloat-linux-gnu/ 3.4.1/crtend.o /home/opt/crosstool/arm-softfloat-linux-gnu/gcc-3.4.1-glibc-2.3.3/bin/../lib/gcc/ arm-softfloat-linux-gnu/3.4.1/../../../../arm-softfloat-linux-gnu/lib/crtn.o -- Summary: Destructor called with wrong argument after exception with -fcse-follow-jumps -O1 Product: gcc Version: 3.4.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: flash at pobox dot com CC: gcc-bugs at gcc dot gnu dot org GCC target triplet: arm-softfloat-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24075