我的源码是这样的:
测试.cpp:
void func(){
throw "abc";
}
int main(){
try{
func();
}
catch(...){
}
}
我用
clang
编译了代码clang -S -emit-llvm test.cpp
然后用
lli
执行它:lli -force-interpreter test.ll
然后崩溃了:
terminating with uncaught exception of type
char const*
我正在使用 macbook(llvm3.6)。
最佳答案
答案是肯定的。
- 用
clang++
而不是clang
编译C++代码 - 删除选项
-force-interpreter
- 添加选项-jit-enable-eh
我对你的测试做了一些修改:
#include <stdio.h>
void func(){
throw "test";
}
int main(){
try{
func();
}
catch(...){
printf("Gotcha\n");
}
}
结果:
$clang++ -S -emit-llvm test.cpp
$lli -jit-enable-eh test.ll
Gotcha
关于c++ - llvm 解释器可以处理 c++ 异常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32111668/