Correctly set attributes when removing args during cloning. Fixes PR2765
authorAndrew Lenharth <andrewl@lenharth.org>
Tue, 7 Oct 2008 18:08:38 +0000 (18:08 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Tue, 7 Oct 2008 18:08:38 +0000 (18:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57254 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/CloneFunction.cpp

index 9e3fe329928190d9963d640eb2b14506d7dba3d7..fe2a606cf710cef7c30b59d3be4fb080c35717e0 100644 (file)
@@ -81,7 +81,23 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
 #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