[llvm-commits] [llvm] r57254 - /llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp

Andrew Lenharth alenhar2 at cs.uiuc.edu
Tue Oct 7 11:08:39 PDT 2008


Author: alenhar2
Date: Tue Oct  7 13:08:38 2008
New Revision: 57254

URL: http://llvm.org/viewvc/llvm-project?rev=57254&view=rev
Log:
Correctly set attributes when removing args during cloning.  Fixes PR2765

Modified:
    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp

Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=57254&r1=57253&r2=57254&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Tue Oct  7 13:08:38 2008
@@ -81,7 +81,23 @@
 #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





More information about the llvm-commits mailing list