Skip to content

Commit c84d5c0

Browse files
committed
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<AttributeSetNode*>) 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299899 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0d684b1 commit c84d5c0

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/CodeGen/CodeGenModule.cpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -2935,13 +2935,11 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
29352935
continue;
29362936

29372937
// Get the call site's attribute list.
2938-
SmallVector<llvm::AttributeList, 8> newAttrs;
2938+
SmallVector<llvm::AttributeSetNode *, 8> newAttrs;
29392939
llvm::AttributeList oldAttrs = callSite.getAttributes();
29402940

29412941
// Collect any return attributes from the call.
2942-
if (oldAttrs.hasAttributes(llvm::AttributeList::ReturnIndex))
2943-
newAttrs.push_back(llvm::AttributeList::get(newFn->getContext(),
2944-
oldAttrs.getRetAttributes()));
2942+
newAttrs.push_back(oldAttrs.getRetAttributes());
29452943

29462944
// If the function was passed too few arguments, don't transform.
29472945
unsigned newNumArgs = newFn->arg_size();
@@ -2959,16 +2957,12 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
29592957
}
29602958

29612959
// Add any parameter attributes.
2962-
if (oldAttrs.hasAttributes(argNo + 1))
2963-
newAttrs.push_back(llvm::AttributeList::get(
2964-
newFn->getContext(), oldAttrs.getParamAttributes(argNo + 1)));
2960+
newAttrs.push_back(oldAttrs.getParamAttributes(argNo + 1));
29652961
}
29662962
if (dontTransform)
29672963
continue;
29682964

2969-
if (oldAttrs.hasAttributes(llvm::AttributeList::FunctionIndex))
2970-
newAttrs.push_back(llvm::AttributeList::get(newFn->getContext(),
2971-
oldAttrs.getFnAttributes()));
2965+
newAttrs.push_back(oldAttrs.getFnAttributes());
29722966

29732967
// Okay, we can transform this. Create the new call instruction and copy
29742968
// over the required information.

test/CodeGen/2006-05-19-SingleEltReturn.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Test returning a single element aggregate value containing a double.
2+
// RUN: %clang_cc1 -triple i686-linux %s -emit-llvm -o - | FileCheck %s --check-prefix=X86_32
23
// RUN: %clang_cc1 %s -emit-llvm -o -
34

45
struct X {
56
double D;
67
};
78

8-
struct Y {
9-
struct X x;
9+
struct Y {
10+
struct X x;
1011
};
1112

1213
struct Y bar();
@@ -21,3 +22,9 @@ struct Y bar() {
2122
return a;
2223
}
2324

25+
26+
// X86_32: define void @foo(%struct.Y* %P)
27+
// X86_32: call void @bar(%struct.Y* sret %{{[^),]*}})
28+
29+
// X86_32: define void @bar(%struct.Y* noalias sret %{{[^,)]*}})
30+
// X86_32: ret void

0 commit comments

Comments
 (0)