LLVM how to set Attributes::NoUnwind to Function?

1.7k Views Asked by At

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

There are 1 best solutions below

4
On BEST ANSWER

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))