我在里面跑 http://llvm.org/demo以下片段:
class X { public: ~X() __attribute((nothrow)); };
void a(X* p);
void nothr() throw();
void b() { try { X x; a(&x); } catch (X* foo) { nothr(); } }
我看到一些调用(例如,对 func_llvm_eh_typeid_for)设置了 Attribute::NoUnwind:
CallInst* int32_71 = CallInst::Create(func_llvm_eh_typeid_for, const_ptr_43, "", label_49);
int32_71->setCallingConv(CallingConv::C);
int32_71->setTailCall(false);
AttrListPtr int32_71_PAL;
{
SmallVector<AttributeWithIndex, 4> Attrs;
AttributeWithIndex PAWI;
PAWI.Index = 4294967295U; PAWI.Attrs = 0 | Attribute::NoUnwind;
Attrs.push_back(PAWI);
int32_71_PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
}
int32_71->setAttributes(int32_71_PAL);
由于此调用是使用 CallInst 而不是 InvokeInst 创建的,我认为调用本身不会抛出,因此我想知道在此上下文中 Unwind 属性的用途是什么?
最佳答案
这意味着您不必担心生成异常处理代码或优化,就好像异常可以通过该代码部分传播一样,因为您已经说过它不会。如果一个碰巧通过那里,那么它应该正确传播到程序中的下一个堆栈帧。
关于c++ - llvm 属性::NoUnwind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7573535/