Bug 43365 - [4.5 Regression] Destructor not called when returning in exception handler
Summary: [4.5 Regression] Destructor not called when returning in exception handler
Status: VERIFIED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P1 normal
Target Milestone: 4.5.0
Assignee: Richard Henderson
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-03-14 13:55 UTC by Erik Johansson
Modified: 2010-04-12 20:50 UTC (History)
5 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2010-03-15 18:53:26


Attachments
Sample code that triggers the error (162 bytes, text/plain)
2010-03-14 13:57 UTC, Erik Johansson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Johansson 2010-03-14 13:55:33 UTC
When returning from a function in an exception handler, the destructor for objects local to the function is never called.

The attached program returns 0 (as expected) when compiled with:
gcc version 4.4.3 (Debian 4.4.3-3)

The same program returns 1 when compiled with:
gcc version 4.5.0 20100310 (experimental) [trunk revision 157334] (Debian 20100310-1)

Configured with: ../src/configure -v --with-pkgversion='Debian 20100310-1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs --enable-languages=c,ada,c++,java,fortran,objc,obj-c++ --prefix=/usr/lib/gcc-snapshot --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --disable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.5-snap/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.5-snap --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.5-snap --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --with-arch-32=i486 --with-tune=generic --disable-werror --enable-checking=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Comment 1 Erik Johansson 2010-03-14 13:57:59 UTC
Created attachment 20103 [details]
Sample code that triggers the error

With gcc 4.4.3:
/usr/bin/g++ -o exception exception.cc && ./exception; echo $?
0

With gcc 4.5.0:
/usr/lib/gcc-snapshot/bin/g++ -o exception exception.cc && ./exception; echo $?
1
Comment 2 H.J. Lu 2010-03-14 17:27:20 UTC
It is caused by revision 151696:

http://gcc.gnu.org/ml/gcc-cvs/2009-09/msg00443.html
Comment 3 Richard Biener 2010-03-15 13:13:20 UTC
Or is a latent bug in ehopt.
Comment 4 Richard Henderson 2010-03-16 23:02:55 UTC
Subject: Bug 43365

Author: rth
Date: Tue Mar 16 23:02:35 2010
New Revision: 157499

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157499
Log:
        PR middle-end/43365
        * tree-eh.c (replace_goto_queue): Also replace in the eh_seq.
        (lower_try_finally): Save and restore eh_seq around the expansion
        of the try-finally.

Added:
    trunk/gcc/testsuite/g++.dg/eh/pr43365.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-eh.c

Comment 5 Richard Biener 2010-03-17 15:24:27 UTC
Fixed.
Comment 6 Erik Johansson 2010-04-12 20:50:10 UTC
Tested with latest Debian gcc-snapshot on the code where I originally saw the problem and it works now. Thank you very much.

Tested with:
gcc (Debian 20100408-1) 4.5.0 20100408 (prerelease) [gcc-4_5-branch revision 158131]
Comment 7 ian@gcc.gnu.org 2010-06-14 06:57:53 UTC
Subject: Bug 43365

Author: ian
Date: Mon Jun 14 06:57:36 2010
New Revision: 160704

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160704
Log:
Avoid crash when exception landing pad becomes unreachable.

Bring over trunk patch for PR 43365.

Modified:
    branches/gccgo/gcc/tree-eh.c