]> granicus.if.org Git - clang/commitdiff
Reland "[IR] Make AttributeSetNode public, avoid temporary AttributeList copies"
authorReid Kleckner <rnk@google.com>
Mon, 10 Apr 2017 23:31:05 +0000 (23:31 +0000)
committerReid Kleckner <rnk@google.com>
Mon, 10 Apr 2017 23:31:05 +0000 (23:31 +0000)
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

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/2006-05-19-SingleEltReturn.c

index 6bc7d4f10e27dc077c790ab2e05ce0387164bd0b..96358bf6119e1c2c98a4d97a4461e2df6d4a1582 100644 (file)
@@ -2935,13 +2935,11 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
       continue;
 
     // Get the call site's attribute list.
-    SmallVector<llvm::AttributeList, 8> newAttrs;
+    SmallVector<llvm::AttributeSetNode *, 8> 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.
index 819237ce53bef4f0387c4de8b1aa7b1b27a6cd6d..dfc23f84ab424be4b8633f181bb4de320e0ccd91 100644 (file)
@@ -1,12 +1,13 @@
 // Test returning a single element aggregate value containing a double.
+// RUN: %clang_cc1 -triple i686-linux %s -emit-llvm -o - | FileCheck %s --check-prefix=X86_32
 // RUN: %clang_cc1 %s -emit-llvm -o -
 
 struct X {
   double D;
 };
 
-struct Y { 
-  struct X x; 
+struct Y {
+  struct X x;
 };
 
 struct Y bar();
@@ -21,3 +22,9 @@ struct Y bar() {
   return a;
 }
 
+
+// X86_32: define void @foo(%struct.Y* %P)
+// X86_32:   call void @bar(%struct.Y* sret %{{[^),]*}})
+
+// X86_32: define void @bar(%struct.Y* noalias sret %{{[^,)]*}})
+// X86_32:   ret void