std::uncaught_exception() returns true after catching an exception thrown with std::rethrow_exception

Bug #1439451 reported by Chris Halse Rogers
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Confirmed
Medium
gcc-4.9 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

See attached testcase.

On debugging, it seems that std::rethrow_exception isn't incrementing __cxa_get_globals()->uncaughtExceptions, so when the exception is caught it's decremented from 0 to MAXINT.

ProblemType: Bug
DistroRelease: Ubuntu 15.04
Package: libstdc++6 4.9.2-10ubuntu12
ProcVersionSignature: Ubuntu 3.19.0-10.10-generic 3.19.2
Uname: Linux 3.19.0-10-generic x86_64
ApportVersion: 2.17-0ubuntu1
Architecture: amd64
CurrentDesktop: Unity
Date: Thu Apr 2 10:50:37 2015
Dependencies:
 gcc-4.9-base 4.9.2-10ubuntu12
 gcc-5-base 5-20150328-0ubuntu2
 libc6 2.21-0ubuntu4
 libgcc1 1:5-20150328-0ubuntu2
 multiarch-support 2.21-0ubuntu4
InstallationDate: Installed on 2013-08-06 (603 days ago)
InstallationMedia: Ubuntu 13.04 "Raring Ringtail" - Release amd64 (20130424)
SourcePackage: gcc-4.9
UpgradeStatus: Upgraded to vivid on 2013-08-06 (603 days ago)

Related branches

Revision history for this message
In , Dmitry Prokoptsev (dprokoptsev) wrote :

After using std::rethrow_exception() (and catching the exception), all subsequent calls to std::uncaught_exception() return `true', which is obviously not the way it was meant to work.

A simple test case is attached.

Revision history for this message
In , Dmitry Prokoptsev (dprokoptsev) wrote :

Created attachment 33394
A simple test case.

Revision history for this message
In , Dmitry Prokoptsev (dprokoptsev) wrote :

Created attachment 33395
Proposed patch

I believe the problem is that std::rethrow_exception() does not update `__cxa_eh_globals::uncaughtExceptions' (which remains zero), while __cxa_begin_catch() decrements it to -1.

A proposed patch is attached.

Revision history for this message
In , Deniz Bahadir (bagira80) wrote :

I can confirm this bug.
It even occurs with GCC 4.8.2 (on Ubuntu 14.04).

Revision history for this message
In , Ai-azuma (ai-azuma) wrote :

PR61643 shares the root cause with this PR. The behavior of the test case in PR61643 completely agrees with the analysis in Comment 2, and the proposed patch makes the test case in PR61643 work properly.

I confirmed that this bug was reproduced with 4.8.4 20140925, 4.9.2 20140924 and 5.0.0 20140928.

Revision history for this message
In , Ai-azuma (ai-azuma) wrote :

*** Bug 61643 has been marked as a duplicate of this bug. ***

Revision history for this message
In , P-bartosiewi (p-bartosiewi) wrote :

I can also confirm this bug (I have a test case with std::async and future, but it internally uses std::rethrow_exception).

Known to work: gcc 4.6.3, 4.7.2, 4.8.1
Known to fail: gcc 4.8.2, 4.9.2, clang 3.5.0
So this is a regression.

Revision history for this message
In , M. Hanselmann (hansmi) wrote :

Confirmed using GCC 5.0.0 20150125 built from source (see below) and 4.7.2 (Debian 4.7.2-5; Debian Wheezy). Tested using the test case in comment 1.

Output:
$ g++-5-20150125 -std=c++11 -o test62258 test62258.c -Wall && ./test62258
test62258: test62258.c:11: int main(): Assertion `!std::uncaught_exception()' failed.
Aborted

$ g++-5-20150125 -v
Using built-in specs.
COLLECT_GCC=g++-5-20150125
COLLECT_LTO_WRAPPER=/home/user/gcc50/bin/../libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/user/gcc50build/src-gcc-5-20150125/configure --target=x86_64-unknown-linux-gnu --prefix=/home/user/gcc50build/target-x86_64-unknown-linux-gnu --program-suffix=-5-20150125 --disable-nls --enable-c99 --enable-checking=release --enable-gnu-unique-object --enable-gold --enable-languages=c,c++ --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-linker-build-id --enable-long-long --enable-multiarch --enable-multilib --enable-shared --enable-targets=all --enable-threads=posix --with-system-zlib --with-tune=generic
Thread model: posix
gcc version 5.0.0 20150125 (experimental) (GCC)

Revision history for this message
In , M-kwiatkowski (m-kwiatkowski) wrote :

Created attachment 34683
Workaround code

For all programmers out there that may encounter this bug, I attach a workaround code.

Linking your program with it should make rethrow_exception() usable even if the library on the system is buggy.

Revision history for this message
In , M. Hanselmann (hansmi) wrote :

A few days ago I submitted a patch for this issue based on Dmitry's patch. It seems as if we can get it in after the 5.0 release.

https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00027.html

Revision history for this message
Chris Halse Rogers (raof) wrote :
Revision history for this message
Chris Halse Rogers (raof) wrote :
Changed in gcc:
importance: Unknown → Medium
status: Unknown → Confirmed
Revision history for this message
In , Redi (redi) wrote :

doko, this fails for me with 4.8.1, and 4.7.4 and 4.8.0

There are no changes between 4.8.1 and 4.8.2 that could have affected this.

Are you sure it's a regression?

Revision history for this message
Launchpad Janitor (janitor) wrote :
Download full text (5.8 KiB)

This bug was fixed in the package gcc-4.9 - 4.9.2-16ubuntu1

---------------
gcc-4.9 (4.9.2-16ubuntu1) wily; urgency=medium

  * Update to SVN 20150508 (r222909) from the gcc-4_9-branch.

gcc-4.9 (4.9.2-16) unstable; urgency=medium

  * Update to SVN 20150503 (r222750) from the gcc-4_9-branch.
    - Fix the build failure on alpha.
  * Fix gcc-itm doc-base file (Guo Yixuan). Closes: #783998.
  * On m68k, powerpcspe, sh4, sparc64, still build the libraries not
    yet built by gcc-5.
  * Update the cross-biarch patch for D and Go.
  * Apply the cross-biarch patches for every cross build. Closes: #783527.

gcc-4.9 (4.9.2-15) unstable; urgency=medium

  * Update the Linaro support to the 4.9-2015.04 release.

gcc-4.9 (4.9.2-14) unstable; urgency=medium

  * Update to SVN 20150429 (r222567) from the gcc-4_9-branch.
  * Build again libgo.
  * PR libstdc++/62258, fix for std::uncaught_exception, taken from the trunk.
    LP: #1439451.

gcc-4.9 (4.9.2-13) unstable; urgency=medium

  * Update to SVN 20150426 (r222448) from the gcc-4_9-branch.
  * Build using isl 0.14 and cloog 0.18.3.
  * Provide the /usr/include/<multiarch>/c++/<gcc version> symlink.

gcc-4.9 (4.9.2-12) experimental; urgency=medium

  * Stop building libcilkrts and libtsan, build again libasan.

gcc-4.9 (4.9.2-11) experimental; urgency=medium

  * Update to SVN 20150411 (r222011) from the gcc-4_9-branch.
    - Fix PR libstdc++/64476, PR libstdc++/60966, PR libstdc++/64239,
      PR libstdc++/64649, PR libstdc++/64584, PR libstdc++/64585,
      PR libstdc++/64646, PR middle-end/64734, PR c/61553,
      PR middle-end/63704 (ice on valid), PR target/64513 (x86),
      PR rtl-optimization/64286 (wrong code), PR tree-optimization/64563 (ice),
      PR middle-end/64391 (ice on valid), PR c++/54442 (ice on valid),
      PR target/64358 (rs6000, wrong code), PR target/63424 (AArch64, ice on
      valid), PR target/64479 (SH), PR rtl-optimization/64536, PR target/64505
      (rs6000), PR target/61413 (ARM, wrong code), PR target/64507 (SH),
      PR target/64409 (x32, ice on valid), PR c++/64487 (ice on valid),
      PR c++/64352, PR c++/64251 (rejects valid), PR c++/64297 (ice on valid),
      PR c++/64029 (ice on valid), PR c++/63657 (diagnostic), PR c++/38958
      (diagnostic), PR c++/63658 (rejects valid), PR ada/64492 (build),
      PR fortran/64528 (ice on valid), PR fortran/63733 (wrong code),
      PR fortran/56867 (wrong code), PR fortran/64244 (ice on valid),
      PR target/64795 (x86), PR middle-end/64734 (ice),
      PR rtl-optimization/64557, PR ipa/63970 (missed optimization),
      PR fortran/64230 (wrong code), PR fortran/64771 (ice on valid),
      PR fortran/57023 (wrong code), PR fortran/60922 (wrong code), PR c/64766
      (ice), PR c/64778 (ice), PR rtl-optimization/61058 (ice),
      PR middle-end/64421 (OpenMP), PR rtl-optimization/63637,
      PR rtl-optimization/60663 (error on valid asm), PR debug/64511 (ice),
      PR debug/64663 (ice), PR c++/64521 (ice), PR fortran/62044 (ice),
      PR libstdc++/64680, PR libstdc++/64649, PR target/64882 (x86),
      PR c++/64901, PR target/64938 (ICE, ARM), PR ipa/64068, PR ipa/64559,
      PR c/64824 (OpenMP), PR c/64868 (Op...

Read more...

Changed in gcc-4.9 (Ubuntu):
status: New → Fix Released
Revision history for this message
Matthias Klose (doko) wrote :

fixed in gcc-4.9 and gcc-5 in wily (15.10)

Revision history for this message
Steve Langasek (vorlon) wrote : Please test proposed package

Hello Chris, or anyone else affected,

Accepted gccgo-4.9 into trusty-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/gccgo-4.9/4.9.3-0ubuntu4 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

tags: added: verification-needed
Revision history for this message
Steve Langasek (vorlon) wrote :

This bug was not identified with gccgo, only with g++, which is not applicable to the in-progress gccgo-4.9 SRU.

tags: removed: verification-needed
Revision history for this message
Steve Langasek (vorlon) wrote : Update Released

The verification of the Stable Release Update for gccgo-4.9 has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.