From eb9dd5b87f43cbd9641fba0555b775589e49af33 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 10 Apr 2017 23:31:05 +0000 Subject: Reland "[IR] Make AttributeSetNode public, avoid temporary AttributeList copies" This re-lands r299875. I introduced a bug in Clang code responsible for replacing K&R, no prototype declarations with a real function definition with a prototype. The bug was here: // Collect any return attributes from the call. - if (oldAttrs.hasAttributes(llvm::AttributeList::ReturnIndex)) - newAttrs.push_back(llvm::AttributeList::get(newFn->getContext(), - oldAttrs.getRetAttributes())); + newAttrs.push_back(oldAttrs.getRetAttributes()); Previously getRetAttributes() carried AttributeList::ReturnIndex in its AttributeList. Now that we return the AttributeSetNode* directly, it no longer carries that index, and we call this overload with a single node: AttributeList::get(LLVMContext&, ArrayRef) That aborted with an assertion on x86_32 targets. I added an explicit triple to the test and added CHECKs to help find issues like this in the future sooner. llvm-svn: 299899 --- clang/lib/CodeGen/CodeGenModule.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6bc7d4f10e2..96358bf6119 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2935,13 +2935,11 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, continue; // Get the call site's attribute list. - SmallVector newAttrs; + SmallVector newAttrs; llvm::AttributeList oldAttrs = callSite.getAttributes(); // Collect any return attributes from the call. - if (oldAttrs.hasAttributes(llvm::AttributeList::ReturnIndex)) - newAttrs.push_back(llvm::AttributeList::get(newFn->getContext(), - oldAttrs.getRetAttributes())); + newAttrs.push_back(oldAttrs.getRetAttributes()); // If the function was passed too few arguments, don't transform. unsigned newNumArgs = newFn->arg_size(); @@ -2959,16 +2957,12 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, } // Add any parameter attributes. - if (oldAttrs.hasAttributes(argNo + 1)) - newAttrs.push_back(llvm::AttributeList::get( - newFn->getContext(), oldAttrs.getParamAttributes(argNo + 1))); + newAttrs.push_back(oldAttrs.getParamAttributes(argNo + 1)); } if (dontTransform) continue; - if (oldAttrs.hasAttributes(llvm::AttributeList::FunctionIndex)) - newAttrs.push_back(llvm::AttributeList::get(newFn->getContext(), - oldAttrs.getFnAttributes())); + newAttrs.push_back(oldAttrs.getFnAttributes()); // Okay, we can transform this. Create the new call instruction and copy // over the required information. -- cgit v1.2.3