exceptions and optimization
Alex Achenbach
achenbac@stud.uni-frankfurt.de
Mon Jul 27 09:12:00 GMT 1998
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
_____________________________________________________________________
More information about the Gcc-bugs
mailing list