[llvm-commits] PR2765 Patch

Devang Patel dpatel at apple.com
Tue Oct 7 11:00:04 PDT 2008


On Oct 7, 2008, at 10:20 AM, Andrew Lenharth wrote:

> 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?

yes, looks good.
>
>
> 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.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-
Devang






More information about the llvm-commits mailing list