* g++: exceptions thrown from asm declarations
@ 2004-09-22 14:50 Stephan Bergmann
2004-09-22 17:45 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Stephan Bergmann @ 2004-09-22 14:50 UTC (permalink / raw)
To: gcc
Hi all.
I have the following problematic code (used within OpenOffice.org's UNO
component model to synthesize calls to C++ class member functions):
void dummy(); // can throw anything
namespace {
static void inner(bool b) {
if (b) dummy(); // never called
asm(/* make a call to a function that may throw */);
}
}
void outer(bool b) { // always called as outer(false)
try {
inner(b);
} catch (...) {
// handle...
}
}
With g++ 3.3, this works fine: outer does not inline the call to inner,
and since inner might call dummy (which could throw exceptions), an
error-handling range is spanned around the call to inner within outer.
The call to dummy in inner (which actually is never taken at runtime) is
a hack to ensure that the compiler assumes that inner may throw
exceptions, as the compiler obviously assumes that asm declarations do
not throw exceptions (an assumption that is violated in this case).
With g++ 3.4, this no longer works: inner is static and only called
from outer, so it is inlined there. There is still an error-handling
range spanned around the call to dummy, but no longer around the asm
declaration. If, at runtime, an exception is thrown from the asm
declaration, it is thus not caught by the catch handler.
In the current case, the solution is easy: If I remove the static from
inner, g++ 3.4 obviously no longer considers it for inlining (this could
be considered an error: functions within unnamed namespaces should be
treated the same as static functions here). However, that still has two
drawbacks:
- If a future g++ version is smart enough to inline both static
functions and functions within unnamed namespaces, the problem reappears
(and has to be worked around with more drastic measures, like moving
inner to a different translation unit).
- The call to dummy is a hack, and it would be nice to get rid of it.
The real solution would be to somehow specify that (the call instruction
within) the asm declaration can throw exceptions. Is that possible in
g++? I did not find anything about that in the manual.
-Stephan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: g++: exceptions thrown from asm declarations
2004-09-22 14:50 g++: exceptions thrown from asm declarations Stephan Bergmann
@ 2004-09-22 17:45 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2004-09-22 17:45 UTC (permalink / raw)
To: Stephan Bergmann; +Cc: gcc
On Wed, Sep 22, 2004 at 03:22:15PM +0200, Stephan Bergmann wrote:
> - If a future g++ version is smart enough to inline both static
> functions and functions within unnamed namespaces, the problem reappears
> (and has to be worked around with more drastic measures, like moving
> inner to a different translation unit).
__attribute__((noinline)) will fix this.
> - The call to dummy is a hack, and it would be nice to get rid of it.
Indeed.
> The real solution would be to somehow specify that (the call instruction
> within) the asm declaration can throw exceptions. Is that possible in
> g++?
No. Really, this is the sort of thing that needs to be written
entirely in assembly.
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-09-22 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-22 14:50 g++: exceptions thrown from asm declarations Stephan Bergmann
2004-09-22 17:45 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).