2

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]

kpdev
  • 610
  • 1
  • 7
  • 20
  • I've done some research - this code compile well with LLVM 3.1, but not LLVM 3.2. But, I don't understand why. – kpdev Apr 30 '13 at 15:16
  • So, I continue my project with LLVM 3.1. If somebody knows, why this code is writes with llc from LLVM 3.2, but dont matches the operands types - please, let me know. Thank you. – kpdev Apr 30 '13 at 16:38
  • Are you working with LLVM 3.2, or with the latest ("top-of-trunk") version? – Oak Apr 30 '13 at 19:45
  • I downloaded LLVM source code from http://llvm.org/releases/download.html#3.2 in January 05 2013 – kpdev Apr 30 '13 at 22:07
  • If somebody faced same problem - my solution (in LLVM 3.2): `llvm::AttrBuilder *atbuild = new llvm::AttrBuilder();` `atbuild->addAttribute(llvm::Attributes::NoUnwind);` `llvm::Attributes atrbs = llvm::Attributes::get(context,*atbuild);` `function->addAttribute(0,atrbs);` – kpdev May 01 '13 at 06:52
  • Huh, haven't noticed your latest comment before I posted. In any case, you can just pass Attributes::NoUnwind to the Attributes::get method, you don't need the AttrBuilder. – Oak May 01 '13 at 07:10

1 Answers1

2

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))
Oak
  • 26,231
  • 8
  • 93
  • 152
  • Some things went wront in VS: "IntelliSense: no instance of overloaded function "llvm::AttributeWithIndex::get" matches the argument list argument types are: (llvm::LLVMContext, int, llvm::Attributes)" ...Last argument must be only ArrayRef ? – kpdev May 01 '13 at 07:15
  • @kpdev I believe `function->addFnAttribute(Attributes::NoUnwind)` is the simplest way. – Oak May 01 '13 at 07:27
  • Oh, yes. `function->addFnAttr(...)` very simple. Thank you ) – kpdev May 01 '13 at 07:40
  • 1
    @kpdev you welcome! I've edited my answer to include that tidbit inside :) – Oak May 01 '13 at 07:47