Why does "uwtable" prevent optimizing Invoke -> Call?


in r176827 the optimization that turns invokes with empty landing pads
into plain calls was disabled for invocations of function with the
"uwtable" attribute.

But given this code:

    struct S { ~S() {}; };

    void blackbox();
    __attribute__((__noinline__)) void inner() { blackbox(); }

    int foo() {
        S s;
        return 0;

    int bar() {
        return 0;

clang directly emits a call instruction in "bar", because there is
nothing to be cleaned up. But in "foo", it emits an invoke instruction
because of the S object. During optimization, the S object gets
optimized out and all that remains is the invoke instruction with an
empty landing pad, causing exception tables to be generated and in some
cases stopping other optimizations from being applied.

I don't see why code that has been completely optimized away should have
an effect on that function call. So AFAICT either I'm missing something
here, or clang should always emit invoke, disabling the optimization for
functions that have the uwtable attribute was wrong and the change
should be reverted.

FWIW, gcc does not generate exception tables for the above.



Some context: Apple Developer Forums
Maybe this one as well: http://llvm.org/bugs/show_bug.cgi?id=15555



Hi Björn,

:smiting my forehead: Sure! thats it, thanks a lot.


I meant to write "either I'm missing something, or clang should always
emit invoke instructions _or_ disabling the optimization was wrong".


I agree, I don't see how uwtable has anything to do with this optimization.
There must be something wrong with our CFI instead.

I went ahead and reverted this in r226850 after some discussion on IRC.

Alexander Poddey wrote:
sorry this one had gone into the wrong thread!