[cfe-commits] r134483 - in /cfe/trunk: lib/Sema/TreeTransform.h test/CodeGenCXX/variadic-templates.cpp

John McCall rjmccall at apple.com
Wed Jul 6 00:30:07 PDT 2011


Author: rjmccall
Date: Wed Jul  6 02:30:07 2011
New Revision: 134483

URL: http://llvm.org/viewvc/llvm-project?rev=134483&view=rev
Log:
When tree-transforming an expression sequence, always flag expanded
variadic argument pack expansions as having changed, rather than doing
it for each changed expansion, which leaves out zero-argument packs
with catastrophic consequences.

Fixes PR10260.


Modified:
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CodeGenCXX/variadic-templates.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=134483&r1=134482&r2=134483&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Jul  6 02:30:07 2011
@@ -1547,9 +1547,9 @@
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
   ExprResult RebuildInitList(SourceLocation LBraceLoc,
-                                   MultiExprArg Inits,
-                                   SourceLocation RBraceLoc,
-                                   QualType ResultTy) {
+                             MultiExprArg Inits,
+                             SourceLocation RBraceLoc,
+                             QualType ResultTy) {
     ExprResult Result
       = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
     if (Result.isInvalid() || ResultTy->isDependentType())
@@ -2476,6 +2476,10 @@
         Outputs.push_back(Out.get());
         continue;
       }
+
+      // Record right away that the argument was changed.  This needs
+      // to happen even if the array expands to nothing.
+      if (ArgChanged) *ArgChanged = true;
       
       // The transform has determined that we should perform an elementwise
       // expansion of the pattern. Do so.
@@ -2492,8 +2496,6 @@
             return true;
         }
         
-        if (ArgChanged)
-          *ArgChanged = true;  
         Outputs.push_back(Out.get());
       }
         

Modified: cfe/trunk/test/CodeGenCXX/variadic-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/variadic-templates.cpp?rev=134483&r1=134482&r2=134483&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/variadic-templates.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/variadic-templates.cpp Wed Jul  6 02:30:07 2011
@@ -9,4 +9,15 @@
 // CHECK: ret i32 3
 template int get_num_types(int, float, double);
 
+// PR10260 - argument packs that expand to nothing
+namespace test1 {
+  template <class... T> void foo() {
+    int values[sizeof...(T)+1] = { T::value... };
+    // CHECK: define linkonce_odr void @_ZN5test13fooIJEEEvv()
+    // CHECK: alloca [1 x i32], align 4
+  }
 
+  void test() {
+    foo<>();
+  }
+}





More information about the cfe-commits mailing list