Fixed a crash when cloning a function into a function with
authorPekka Jaaskelainen <pekka.jaaskelainen@tut.fi>
Thu, 7 Mar 2013 16:46:43 +0000 (16:46 +0000)
committerPekka Jaaskelainen <pekka.jaaskelainen@tut.fi>
Thu, 7 Mar 2013 16:46:43 +0000 (16:46 +0000)
different size argument list and without attributes in the
arguments.

llvm-svn: 176632

llvm/lib/Transforms/Utils/CloneFunction.cpp

index a309bce..63d7a1d 100644 (file)
@@ -94,9 +94,12 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
     //Some arguments were deleted with the VMap. 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>(VMap[I]))
-        Anew->addAttr(OldFunc->getAttributes()
-                       .getParamAttributes(I->getArgNo() + 1));
+      if (Argument* Anew = dyn_cast<Argument>(VMap[I])) {
+        AttributeSet attrs = OldFunc->getAttributes()
+          .getParamAttributes(I->getArgNo() + 1);
+        if (attrs.getNumSlots() > 0)
+          Anew->addAttr(attrs);
+      }
     NewFunc->setAttributes(NewFunc->getAttributes()
                            .addAttributes(NewFunc->getContext(),
                                           AttributeSet::ReturnIndex,