This is the mail archive of the
mailing list for the GCC project.
Re: C++: Letting compiler know asm block can call function that can throw?
On Thu, Mar 29, 2012 at 10:47 AM, Stephan Bergmann <firstname.lastname@example.org> wrote:
> On 03/29/2012 09:44 AM, Jakub Jelinek wrote:
>> On Thu, Mar 29, 2012 at 09:05:29AM +0200, Stephan Bergmann wrote:
>>> In LibreOffice's ever-beloved low-level code to synthesize calls to
>>> C++ virtual functions, I'm having the following problem (on Linux
>>> x86_64). The function callVirtualMethod
>>> effectively does the following:
>>> First, call dummy_can_throw_anything that can potentially throw (see
>>> below for why that's there). ?Second, in an asm block, call some
>>> virtual function (that can potentially throw). ?Third, call
>>> x86_64::fill_struct that can potentially throw (it doesn't, but
>>> nobody bothered to annotate it as "throw ()").
>> If the asm isn't in headers, but just in a single short source file
>> or two, you could try compiling that file with -fnon-call-exceptions.
>> It is nothing I'd recommend for the whole codebase though.
> Turns out I had to move the callVirtualMethod function containing the asm
> into a source file of its own, anyway. ?(Otherwise, even if it no longer
> explicitly called functions that can throw, and thus no longer had
> corresponding .gcc_except_table entries, exception throwing still lead to
> std::terminate. ?There are other functions in the same source file
> callVirtualMethod was originally in that do have .gcc_except_table entries.
> ?Kind of invalidates my previous explanation of why exception handling
> bailed out to std::terminate. ?Looks like I haven't groked it yet, anyway.)
> So an explicit -fnon-call-exceptions on the command line seems to indeed
> help. ?Unfortunately, moving that into a
> ?#pragma GCC optimize ("non-call-exceptions")
> at the top of the source file that defines callVirtualMethod (and nothing
> more) does *not* work. ?Is that a bug?
The optimize pragma has only very limited support for this kind of options,
so yes, it's techincally a bug but don't hold your breath.
> Anyway, would it be worthwhile filing an RFE for an asm annotation telling
> the compiler that it contains code that can throw?
I suppose yes.