diff options
author | John McCall <rjmccall@apple.com> | 2011-08-03 00:43:55 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-08-03 00:43:55 +0000 |
commit | 625ed88f0732272136abbe0108543ca1048d533a (patch) | |
tree | 70f0ceb69576439e56ef6d0b0d5d3e5511d3f73b /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 50f4966ceb9026f8c50247fc24ba9f6458698613 (diff) | |
download | bcm5719-llvm-625ed88f0732272136abbe0108543ca1048d533a.tar.gz bcm5719-llvm-625ed88f0732272136abbe0108543ca1048d533a.zip |
When rewriting a call to a K&R function to lead to a well-prototyped
function, be sure to drop parameter attributes when dropping their
associated arguments. Patch by Aaron Landwehr!
llvm-svn: 136753
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 12f09b1c657..6651282384e 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1407,6 +1407,17 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, if (CI->getType() != NewRetTy && !CI->use_empty()) continue; + // Get the attribute list. + llvm::SmallVector<llvm::AttributeWithIndex, 8> AttrVec; + llvm::AttrListPtr AttrList = CI->getAttributes(); + + // Get any return attributes. + llvm::Attributes RAttrs = AttrList.getRetAttributes(); + + // Add the return attributes. + if (RAttrs) + AttrVec.push_back(llvm::AttributeWithIndex::get(0, RAttrs)); + // If the function was passed too few arguments, don't transform. If extra // arguments were passed, we silently drop them. If any of the types // mismatch, we don't transform. @@ -1419,10 +1430,17 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, DontTransform = true; break; } + + // Add any parameter attributes. + if (llvm::Attributes PAttrs = AttrList.getParamAttributes(ArgNo + 1)) + AttrVec.push_back(llvm::AttributeWithIndex::get(ArgNo + 1, PAttrs)); } if (DontTransform) continue; + if (llvm::Attributes FnAttrs = AttrList.getFnAttributes()) + AttrVec.push_back(llvm::AttributeWithIndex::get(~0, FnAttrs)); + // Okay, we can transform this. Create the new call instruction and copy // over the required information. ArgList.append(CS.arg_begin(), CS.arg_begin() + ArgNo); @@ -1430,7 +1448,8 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, ArgList.clear(); if (!NewCall->getType()->isVoidTy()) NewCall->takeName(CI); - NewCall->setAttributes(CI->getAttributes()); + NewCall->setAttributes(llvm::AttrListPtr::get(AttrVec.begin(), + AttrVec.end())); NewCall->setCallingConv(CI->getCallingConv()); // Finally, remove the old call, replacing any uses with the new one. |