Bug 24075 - Destructor called with wrong argument after exception with -fcse-follow-jumps -O1
Summary: Destructor called with wrong argument after exception with -fcse-follow-jumps...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-09-27 04:36 UTC by Flash Sheridan
Modified: 2021-11-26 11:24 UTC (History)
3 users (show)

See Also:
Host:
Target: arm-softfloat-linux-gnu
Build:
Known to work:
Known to fail: 3.4.5
Last reconfirmed: 2005-10-18 16:13:47


Attachments
Preprocessed source file (286 bytes, text/plain)
2005-09-27 04:38 UTC, Flash Sheridan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Flash Sheridan 2005-09-27 04:36:28 UTC
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
Comment 1 Flash Sheridan 2005-09-27 04:38:49 UTC
Created attachment 9816 [details]
Preprocessed source file

PalmSource bug #110057.
Comment 2 Richard Earnshaw 2005-10-18 16:13:47 UTC
Confirmed still fails on the 3.4 branch (arm-elf cross).  The failure mode is that we have

  virtual_frame_pointer <= hard_frame_pointer

  ...
  cond_jump somewhere

  var <= virtual_frame_pointer

The initial assignment is special since the assignment will be adjusted once the offset between the virtal and hard frame pointers is known.  However, when cse-follow-jumps is enabled the second assignment is replaced with

  var <= hard_frame_pointer

This second assignment is not special so it remains this way after the virtual->hard addressing is crystalized.  This means that we have the wrong value in var at this point.

Note that it's not surprising that you can't reproduce this with a series of -f options, since -O is needed to turn on GCC's optimization framework: without it cse isn't run at all!

IMO we probably shouldn't be recording a cse for a set of the virtual frame pointer.