This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
exceptions and optimization
- To: egcs-bugs at cygnus dot com
- Subject: exceptions and optimization
- From: Alex Achenbach <achenbac at stud dot uni-frankfurt dot de>
- Date: Mon, 27 Jul 1998 18:12:57 +0200
I don't know whether this has come up yet, but there's a bug in
support for exceptions in egcs 1.0.3a when any optimization (-O#)
is turned on for a source module containing functions that a
stack frame unwind path leads through (but that do not actually
catch/check exceptions themselves).
The following code (two modules) triggers the bug:
--- x.cc ------------------------------------------------
#include <iostream>
void foo(); // potential thrower
int main() {
try {
foo();
}
catch (int) { cout << "gotcha" << endl; }
return 0;
}
--- y.cc ------------------------------------------------
#include <iostream>
void foo() {
throw 4; // will segfault if -O1, -O2, or -O3
}
---------------------------------------------------------
(eg compiled as g++ -O2 x.cc y.cc -o xy )
In y.cc::foo(), the throw will segfault. The reason seems to be
that optimization removes the exception table of any function
that does not itself catch/check exceptions (just a guess).
The problem does not occur if either foo() is defined as
void foo() throw (int) { /* ... */ }
in y.cc, or is changed to
void foo() {
try {
throw 4;
}
catch (...) {
throw;
}
}
Cheers,
Alex
--
_____________________________________________________________________
Alexander Achenbach achenbac@stud.uni-frankfurt.de
_____________________________________________________________________