LLVM how to set Attributes::NoUnwind to Function?

风流意气都作罢 提交于 2020-01-15 10:14:10

问题


I think this is very simple question, but I can't resolve it. Very sad. So. When I do

llc.exe -march=cpp test.bc 

I get interesting test.cpp with this piece of code:

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());
}

But when I want to write string like PAWI.Attrs = Attribute::None | Attribute::NoUnwind;

in my project, I got error IntelliSense: no operator "=" matches these operands operand types are: llvm::Attributes = int What I need to do? All necessary headers included. [OS - Windows 7 x64, LLVM - 3.2]


回答1:


I don't know why the cpp backend generates this code. In any case attribute handing was changed in 3.2 (and will change again in 3.3). The proper way to get an attribute in 3.2 should be:

Attributes::get(Context, Attributes::NoUnwind)

(you can always pass any ArrayRef here as the second argument, to initialize the attribute set with multiple values).

The simplest way to add an attribute to a function would be:

Function->addFnAttr(Attributes::NoUnwind)

And if you want an AttributeWithIndex:

AttributeWithIndex::get(Context, ID, Attributes::NoUnwind)
// OR:
AttributeWithIndex::get(ID, Attributes::get(Context, Attributes::NoUnwind))


来源:https://stackoverflow.com/questions/16301964/llvm-how-to-set-attributesnounwind-to-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!