lli and exceptions

Hi,

I have a bunch of cpp files that I compile with clang to bitcode:

/data/kais/clang/bin_gcc-6.2.0/bin/clang-3.9 -O0 -fexceptions -fcxx-exceptions -std=c++11 -I/data/kais/clang/test/src/runtime -I/data/kais/clang/test/src/scripts -emit-llvm -c /data/kais/clang/test/src/runtime/*.cpp /data/kais/clang/test/src/scripts/*.cpp

Then, I use lli to run this testfunction (test.test.cpp):

void notify(int i); // implemented in different compilationunit: notify.cpp / notify.bc

struct Obj
{
    Obj()
    {
        notify(0);
    }

    ~Obj()
    {
        notify(1);
    }
};

int test_func_123()
{
    try
    {
        Obj obj;
        notify(4);
        throw 4; // this exception is not supposed to leave jitcode
    }
    catch(int i) // because its caught here
    {
        notify(2);
    }

    notify(3);
    return 0;
}

extern "C" void test_func()
{
    test_func_123();
}

This is the notify func (notify.bc):

void notify(int i)
{
    printf("%d\n", i);
}

So even though there is lots of code generated, only very little is used by the test func.

The expected output is:
0
4
1
2
3

But this happens when i run it with lli:

/data/kais/clang/bin_gcc-6.2.0/bin/lli -entry-function=test_func -extra-module=notify.bc -extra-module=exception.bc -extra-module=map.bc -extra-module=memory.bc -extra-module=string.bc -extra-module=thread.bc -extra-module=type_id.bc -extra-module=value.bc test.test.bc
0
4
terminate called after throwing an instance of 'int'
#0 0x00000000016713ca llvm::sys::PrintStackTrace(llvm::raw_ostream&) /data/kais/clang/src/lib/Support/Unix/Signals.inc:402:0
#1 0x0000000001671792 PrintStackTraceSignalHandler(void*) /data/kais/clang/src/lib/Support/Unix/Signals.inc:470:0
#2 0x000000000166f8aa llvm::sys::RunSignalHandlers() /data/kais/clang/src/lib/Support/Signals.cpp:44:0
#3 0x0000000001670c7c SignalHandler(int) /data/kais/clang/src/lib/Support/Unix/Signals.inc:246:0
#4 0x00007fe800950850 __restore_rt (/lib64/libpthread.so.0+0xf850)
#5 0x00007fe7ff573875 __GI_raise (/lib64/libc.so.6+0x32875)
#6 0x00007fe7ff574e51 __GI_abort (/lib64/libc.so.6+0x33e51)
#7 0x00007fe7ffde5f6d __gnu_cxx::__verbose_terminate_handler() /data/kais/gcc-6.2.0/build/x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/../../../../src/libstdc++-v3/libsupc++/vterminate.cc:95:0
#8 0x00007fe7ffde3f26 __cxxabiv1::__terminate(void (*)()) /data/kais/gcc-6.2.0/build/x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:51:0
#9 0x00007fe7ffde3f71 (/data/kais/gcc-6.2.0/bin/lib64/libstdc++.so.6+0x96f71)
#10 0x00007fe7ffde4188 (/data/kais/gcc-6.2.0/bin/lib64/libstdc++.so.6+0x97188)
#11 0x00007fe800d70b3c
Stack dump:
0. Program arguments: /data/kais/clang/bin_gcc-6.2.0/bin/lli -entry-function=test_func -extra-module=notify.bc -extra-module=exception.bc -extra-module=map.bc -extra-module=memory.bc -extra-module=string.bc -extra-module=thread.bc -extra-module=type_id.bc -extra-module=value.bc test.test.bc
Aborted

Does the error mean it doesnt find a matching catch-handler?

Moving around the source of test_func() in its cpp file seems to have impact on whether it runs or crashs.

Adding seemingly unrelated option (-time-passes) also makes it work:
/data/kais/clang/bin_gcc-6.2.0/bin/lli -entry-function=test_func -extra-module=notify.bc -extra-module=exception.bc -extra-module=map.bc -extra-module=memory.bc -extra-module=string.bc -extra-module=thread.bc -extra-module=type_id.bc -extra-module=value.bc -time-passes test.test.bc
0
4
1
2
3