diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-20 15:05:24 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-20 15:05:24 -0800 |
commit | 3c663e54d30627239ca12edf6cc888a67728eb08 (patch) | |
tree | 7798822e872791303f75e4f227251db21007d02f | |
parent | 16eb1c619ee8fc7913eb9e3fec6d0117bd71a180 (diff) |
fix attribute copying in function recreation code in ExpandI64 pass
-rw-r--r-- | lib/Transforms/NaCl/ExpandI64.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/Transforms/NaCl/ExpandI64.cpp b/lib/Transforms/NaCl/ExpandI64.cpp index a8e2689003..a4fbb8c709 100644 --- a/lib/Transforms/NaCl/ExpandI64.cpp +++ b/lib/Transforms/NaCl/ExpandI64.cpp @@ -212,13 +212,25 @@ static Function *RecreateFunctionLegalized(Function *F, FunctionType *NewType) { NewFunc->addAttributes(AttributeSet::FunctionIndex, FnAttrs); NewFunc->addAttributes(AttributeSet::ReturnIndex, Attrs.getRetAttributes()); Function::arg_iterator AI = F->arg_begin(); - for (unsigned i = 0, e = F->arg_size(), j = 0; i != e; ++i, ++j, ++AI) { - AttributeSet ArgAttrs = Attrs.getParamAttributes(i); + + // We need to recreate the attribute set, with the right indexes + AttributeSet NewAttrs; + unsigned NumArgs = F->arg_size(); + for (unsigned i = 1, j = 1; i < NumArgs+1; i++, j++, AI++) { if (isIllegal(AI->getType())) { - ++j; - } else { - NewFunc->addAttributes(j + 1, ArgAttrs); + j++; + continue; + } + if (!Attrs.hasAttributes(i)) continue; + AttributeSet ParamAttrs = Attrs.getParamAttributes(i); + AttrBuilder AB; + unsigned NumSlots = ParamAttrs.getNumSlots(); + for (unsigned k = 0; k < NumSlots; k++) { + for (AttributeSet::iterator I = ParamAttrs.begin(k), E = ParamAttrs.end(k); I != E; I++) { + AB.addAttribute(*I); + } } + NewFunc->addAttributes(j, AttributeSet::get(F->getContext(), j, AB)); } F->getParent()->getFunctionList().insert(F, NewFunc); |