Ralf Karrenberg
2012-May-15 16:18 UTC
[LLVMdev] CloneFunctionInto() overwrites alignment attribute
Hi everybody, I am trying to clone a function body into an existing declaration. That declaration has the same number of parameters but they differ in type and alignment. Fortunately, it does not care about the type. Unfortunately, CloneFunctionInto() copies the attributes from the old function to the new one unconditionally, overwriting the alignment attribute. Also, the Attribute interface does not allow me to change the alignment of a parameter afterwards ("Attempt to change alignment!" assertion). Removing the attribute and setting it again is also not allowed. Note that I don't want to exclude the arguments from cloning (not adding them to the ValueMap) since the main point of using CloneFunctionInto() is that I don't have to manually rewire them. I think it is generally not a good idea to just blindly copy and overwrite all attributes (including function attributes) since it might more often be the case that CloneFunctionInto() is used exactly to copy some code into a different signature. Any ideas? I am willing to submit a trivial patch that allows to control this behavior via a parameter to CloneFunctionInto() with a default value that does not change the current behavior. Cheers, Ralf
Ralf Karrenberg
2012-May-16 12:37 UTC
[LLVMdev] CloneFunctionInto() overwrites alignment attribute
Short update: It is possible to get around the problem by the following workaround: 1) create a temporary function declaration tmpF 2) tmpF->setAttributes(targetF->getAttributes) 3) CloneFunctionInto(targetF, sourceF, ...) 4) targetF->copyAttributesFrom(tmpF) 5) delete tmpF Storing the attributes of the target and calling setAttributes() after cloning does not work, apparently setAttributes() silently ignores alignments. Cheers, Ralf On 5/15/12 6:18 PM, Ralf Karrenberg wrote:> Hi everybody, > > I am trying to clone a function body into an existing declaration. > That declaration has the same number of parameters but they differ in > type and alignment. > Fortunately, it does not care about the type. > Unfortunately, CloneFunctionInto() copies the attributes from the old > function to the new one unconditionally, overwriting the alignment > attribute. > Also, the Attribute interface does not allow me to change the alignment > of a parameter afterwards ("Attempt to change alignment!" assertion). > Removing the attribute and setting it again is also not allowed. > > Note that I don't want to exclude the arguments from cloning (not adding > them to the ValueMap) since the main point of using CloneFunctionInto() > is that I don't have to manually rewire them. > > I think it is generally not a good idea to just blindly copy and > overwrite all attributes (including function attributes) since it might > more often be the case that CloneFunctionInto() is used exactly to copy > some code into a different signature. > > Any ideas? > I am willing to submit a trivial patch that allows to control this > behavior via a parameter to CloneFunctionInto() with a default value > that does not change the current behavior. > > Cheers, > Ralf > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >