llvm 属性::NoUnwind

lur*_*her 5 c++ exception llvm

我在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(); } }
Run Code Online (Sandbox Code Playgroud)

我看到一些调用(例如,对 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);
Run Code Online (Sandbox Code Playgroud)

由于此调用是使用 CallInst 而不是 InvokeInst 创建的,因此我认为调用本身不能抛出异常,因此我想知道在此上下文中 Unwind 属性的用途是什么?

ech*_*sto 4

这意味着您不必担心生成异常处理代码或进行优化,就好像异常可以通过该代码段传播一样,因为您已经说过它不会传播。如果一个碰巧通过那里,那么它应该正确传播到程序中的下一个堆栈帧。