Attributes & CloneFunctionInto

Hi,

I am again struggling to find my way around the Attribute classes.
What I want to do is clone a function into a declaration where some parameters may have a different alignment.
CloneFunctionInto in debug mode hits an assertion which is marked with a FIXME (Attributes.cpp:673).
I would be totally fine with any kind of workaround, e.g. removing all attributes from the target declaration, then cloning, and then setting the correct attributes.
However, I can't find a way to modify an existing alignment *in any way* without hitting an assertion (the other one being line 727 for removeAttributes). I've also tried using addAttributes() and setAttributes() to set the alignment to 0, but this seems to be ignored...

Any help on this? :slight_smile:

Thanks,
Ralf

Hi,

I am again struggling to find my way around the Attribute classes.
What I want to do is clone a function into a declaration where some parameters may have a different alignment.
CloneFunctionInto in debug mode hits an assertion which is marked with a FIXME (Attributes.cpp:673).
I would be totally fine with any kind of workaround, e.g. removing all attributes from the target declaration, then cloning, and then setting the correct attributes.
However, I can't find a way to modify an existing alignment *in any way* without hitting an assertion (the other one being line 727 for removeAttributes). I've also tried using addAttributes() and setAttributes() to set the alignment to 0, but this seems to be ignored...

SAFECode clones a function to change the alignment of byval arguments. You can look at the code at http://llvm.org/viewvc/llvm-project/safecode/branches/release_32/lib/BaggyBoundsChecks/BaggyBoundsChecks.cpp?revision=177641&view=markup.

Note that the code works with LLVM 3.2.

-- John T.

Hi John,

thanks for the pointer. However, I'd rather avoid rolling a custom implementation. After all, it's not like I want to do something drastically different...
I had sorted out the problem for 3.2 as well as a previous version of 3.3 trunk, but the API changed about a hundred times. Now as it apparently has stabilized, I moved to a the 3.3 release branch just to find that even my previous workarounds don't work anymore.

I can't understand why the API of llvm::Function does not simply provide two functions
- setAttribute(unsigned paramIdx, AttributeKind A) and
- removeAttribute(unsigned paramIdx, AttributeKind A).

Cheers,
Ralf

Hi everybody,

for the record, I managed to work around the issue:
- create a temporary function declaration tmpFn with the type and attributes of the target function newFn
- remove all attributes of newFn (unintuitive: one has to use "newFn->setAttributes" with an empty AttributeSet)
- CloneFunctionInto(newFn, origFn, ...)
- copy attributes back from tmpFn (newFn->copyAttributesFrom(tmpFn))
- erase tmpFn

Cheers,
Ralf