Author: rnk
Date: Mon Apr 10 18:31:05 2017
New Revision: 299899

URL: http://llvm.org/viewvc/llvm-project?rev=299899&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp   (contents, props changed)
    cfe/trunk/test/CodeGen/2006-05-19-SingleEltReturn.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=299899&r1=299898&r2=299899&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 10 18:31:05 2017
@@ -2935,13 +2935,11 @@ static void replaceUsesOfNonProtoConstan
       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 replaceUsesOfNonProtoConstan
       }
 
       // 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.

Propchange: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
------------------------------------------------------------------------------
--- svn:eol-style (original)
+++ svn:eol-style (removed)
@@ -1 +0,0 @@
-native

Modified: cfe/trunk/test/CodeGen/2006-05-19-SingleEltReturn.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2006-05-19-SingleEltReturn.c?rev=299899&r1=299898&r2=299899&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/2006-05-19-SingleEltReturn.c (original)
+++ cfe/trunk/test/CodeGen/2006-05-19-SingleEltReturn.c Mon Apr 10 18:31:05 2017
@@ -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


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to