@@ -530,14 +530,13 @@ Value* PromoteBools::getOrCreatePromotedValue(Value* value)
530530    return  newValue;
531531}
532532
533- template <typename  T>
534- void  PromoteBools::setPromotedAttributes (T* newCallOrFunc, const  AttributeList& attributeList)
533+ void  PromoteBools::setPromotedAttributes (Function* newFunction, AttributeList& attributeList)
535534{
536-     auto  getPromoted = [this , &newCallOrFunc ](llvm::Attribute attr)
535+     auto  getPromoted = [this , &newFunction ](llvm::Attribute attr)
537536        {
538537            if  (attr.isTypeAttribute ())
539538            {
540-                 return  attr.getWithNewType (newCallOrFunc ->getContext (),
539+                 return  attr.getWithNewType (newFunction ->getContext (),
541540                    getOrCreatePromotedType (attr.getValueAsType ()));
542541            }
543542            else 
@@ -547,28 +546,35 @@ void PromoteBools::setPromotedAttributes(T* newCallOrFunc, const AttributeList&
547546        };
548547
549548    //  set function attributes
549+     AttrBuilder attrBuilder (newFunction->getContext ());
550550    for  (const  auto & attr : attributeList.getFnAttrs ())
551551    {
552-         newCallOrFunc-> addFnAttr (getPromoted (attr));
552+         attrBuilder. addAttribute (getPromoted (attr));
553553    }
554+     newFunction->addFnAttrs (attrBuilder);
554555
555-     for  (const  auto & attr : attributeList.getRetAttrs ())
556+     //  set return attributes
557+     attrBuilder.clear ();
558+     for  (const  auto  &attr : attributeList.getRetAttrs ())
556559    {
557-         newCallOrFunc-> addRetAttr (getPromoted (attr));
560+         attrBuilder. addAttribute (getPromoted (attr));
558561    }
562+     newFunction->addRetAttrs (attrBuilder);
559563
560564    //  set params' attributes
561-     for  (size_t  i = 0 ; i < newCallOrFunc ->arg_size (); i++)
565+     for  (size_t  i = 0 ; i < newFunction ->arg_size (); i++)
562566    {
563567        if  (!attributeList.hasParamAttrs (i))
564568        {
565569            continue ;
566570        }
567571
572+         attrBuilder.clear ();
568573        for  (const  auto & attr : attributeList.getParamAttrs (i))
569574        {
570-             newCallOrFunc-> addParamAttr (i,  getPromoted (attr));
575+             attrBuilder. addAttribute ( getPromoted (attr));
571576        }
577+         newFunction->addParamAttrs (i, attrBuilder);
572578    }
573579}
574580
@@ -889,7 +895,7 @@ CallInst* PromoteBools::promoteIndirectCallOrInlineAsm(CallInst* call)
889895        call
890896    );
891897    newCall->setCallingConv (call->getCallingConv ());
892-     setPromotedAttributes ( newCall,  call->getAttributes ());
898+     newCall-> setAttributes ( call->getAttributes ());
893899    newCall->setDebugLoc (call->getDebugLoc ());
894900    return  newCall;
895901}
@@ -962,7 +968,7 @@ CallInst* PromoteBools::promoteCall(CallInst* call)
962968        call
963969    );
964970    newCall->setCallingConv (call->getCallingConv ());
965-     setPromotedAttributes ( newCall,  call->getAttributes ());
971+     newCall-> setAttributes ( call->getAttributes ());
966972    newCall->setDebugLoc (call->getDebugLoc ());
967973    return  newCall;
968974}
0 commit comments