我认为这是一个很简单的问题,但我无法解决。非常难过。 所以。当我这样做时
llc.exe -march=cpp test.bc
我通过这段代码得到了有趣的 test.cpp:
AttrListPtr func__Z2f1i_PAL;
{
SmallVector<AttributeWithIndex, 4> Attrs;
AttributeWithIndex PAWI;
PAWI.Index = 4294967295U; PAWI.Attrs = Attribute::None | Attribute::NoUnwind;
Attrs.push_back(PAWI);
func__Z2f1i_PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
}
但是当我想写像 PAWI.Attrs = Attribute::None | 这样的字符串时属性::NoUnwind;
在我的项目中,我收到错误IntelliSense:没有运算符“=”匹配这些操作数操作数类型为:llvm::Attributes = int
我需要做什么?
包括所有必需的 header 。 [操作系统 - Windows 7 x64、LLVM - 3.2]
最佳答案
我不知道为什么cpp后端会生成这段代码。无论如何,属性处理在 3.2 中已更改(并且将在 3.3 中再次更改)。在 3.2 中获取属性的正确方法应该是:
Attributes::get(Context, Attributes::NoUnwind)
(您始终可以在此处传递任何 ArrayRef 作为第二个参数,以使用多个值初始化属性集)。
向函数添加属性的最简单方法是:
Function->addFnAttr(Attributes::NoUnwind)
如果你想要一个AttributeWithIndex
:
AttributeWithIndex::get(Context, ID, Attributes::NoUnwind)
// OR:
AttributeWithIndex::get(ID, Attributes::get(Context, Attributes::NoUnwind))
关于LLVM 如何将 Attributes::NoUnwind 设置为 Function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16301964/