Can the llvm interpreter handle a C ++ exception?

My source code is as follows:

test.cpp:

void func(){ throw "abc"; } int main(){ try{ func(); } catch(...){ } } 
  • I compiled code with clang

     clang -S -emit-llvm test.cpp 
  • then pushed it with lli :

     lli -force-interpreter test.ll 

and then crashed:

termination with an uncaught exception of type char const*

I am working with a macbook (llvm3.6).

+4
source share
1 answer

The answer is yes.

  • compile C ++ code with clang++ instead of clang
  • remove the -force-interpreter option
  • add option - jit-enable-eh

I slightly modified your test:

 #include <stdio.h> void func(){ throw "test"; } int main(){ try{ func(); } catch(...){ printf("Gotcha\n"); } } 

Result:

$ clang ++ -S -emit-llvm test.cpp
$ lli -jit-enable-eh test.ll
Caught

+2
source

All Articles