[llvm-commits] PR2765 Patch
Andrew Lenharth
andrewl at lenharth.org
Tue Oct 7 10:20:13 PDT 2008
The following is a patch for
http://llvm.org/bugs/show_bug.cgi?id=2765
It shouldn't change the behavior in the common case (pure cloning) but
does the correct thing when removing arguments durring clone. Passes
all tests. Ok to commit?
Andrew
Index: lib/Transforms/Utils/CloneFunction.cpp
===================================================================
--- lib/Transforms/Utils/CloneFunction.cpp (revision 57242)
+++ lib/Transforms/Utils/CloneFunction.cpp (working copy)
@@ -81,8 +81,24 @@
#endif
// Clone any attributes.
- NewFunc->copyAttributesFrom(OldFunc);
+ if (NewFunc->arg_size() == OldFunc->arg_size())
+ NewFunc->copyAttributesFrom(OldFunc);
+ else {
+ //Some arguments were deleted with the ValueMap. Copy arguments one by one
+ for (Function::const_arg_iterator I = OldFunc->arg_begin(),
+ E = OldFunc->arg_end(); I != E; ++I)
+ if (Argument* Anew = dyn_cast<Argument>(ValueMap[I]))
+ Anew->addAttr( OldFunc->getAttributes()
+ .getParamAttributes(I->getArgNo() + 1));
+ NewFunc->setAttributes(NewFunc->getAttributes()
+ .addAttr(0, OldFunc->getAttributes()
+ .getRetAttributes()));
+ NewFunc->setAttributes(NewFunc->getAttributes()
+ .addAttr(~0, OldFunc->getAttributes()
+ .getFnAttributes()));
+ }
+
// Loop over all of the basic blocks in the function, cloning them as
// appropriate. Note that we save BE this way in order to handle cloning of
// recursive functions into themselves.
More information about the llvm-commits
mailing list