[LLVMdev] Question about changes to llvm::Argument::addAttr(AttributeSet AS) API

Bill Wendling wendling at apple.com
Mon Feb 4 16:32:57 PST 2013


On Jan 30, 2013, at 8:20 PM, Christian Schafmeister <chris.schaf at verizon.net> wrote:

> 
> Hi,
> 
> I recently upgraded to the latest LLVM build and encountered a problem where the API for Argument::addAttr has changed.
> 
> Previously it was Argument::addAttr(Attribute A) and I was able to work with this.
> 
> The latest build has changed the method addAttr so that it requires an AttributeSet argument (Argument::addAttr(AttributeSet AS).
> 
Yes.

> I'm not sure how to adjust to this change. The AttributeSet object seems to store an array of Attribute(s) to construct an AttributeSet argument for addAttr I need to know the index of the Argument in the function?
> 
That's correct.

> I can follow the lead of this code from Core.cpp:
> 
> void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
>   Argument *A = unwrap<Argument>(Arg);
>   AttrBuilder B(PA);
>   A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1,  B));
> }
> 
> 
> Is this all I need?  What does the A->getArgNo()+1 provide? The index of the argument in the function argument list+1?
> 
Yes. :-) It's the index of the argument into the list. The indices go like this:

Index number
------------
     0       <- The attribute for the return
    ~0U      <- The index for the function
1, 2, ..., n <- The indexes for the arguments to the function

The argument number that you get from "A->getArgNo()" is 0-based, so you need the "+ 1" to get the correct index into the AttributeSet.

> Is this change to the API described anywhere?
> 
No. It hasn't been written up. We typically don't do write-ups for API changes. However, we do list the thing we do change in the ReleaseNotes (these changes haven't made it there though).

-bw





More information about the llvm-dev mailing list