]> granicus.if.org Git - clang/commitdiff
Fix a crash involving a multi-dimensional dependent VLA. PR11744.
authorEli Friedman <eli.friedman@gmail.com>
Wed, 25 Jan 2012 22:19:07 +0000 (22:19 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 25 Jan 2012 22:19:07 +0000 (22:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148989 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/TreeTransform.h
test/SemaCXX/c99-variable-length-array.cpp

index f5fc3b7cb8426ce5dbce7ff168e23a27ee8cb572..5d761d382a77f8e7b711f19fec19053aec615455 100644 (file)
@@ -3593,8 +3593,12 @@ TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
     if (Result.isNull())
       return QualType();
   }
-  
-  ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
+
+  // We might have either a ConstantArrayType or a VariableArrayType now:
+  // a ConstantArrayType is allowed to have an element type which is a
+  // VariableArrayType if the type is dependent.  Fortunately, all array
+  // types have the same location layout.
+  ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
   NewTL.setLBracketLoc(TL.getLBracketLoc());
   NewTL.setRBracketLoc(TL.getRBracketLoc());
 
index 37115abc68e211c648e474d48d05d40c96f72ef7..2f9bb957ec0570ebb03d88fa8a67615427c3af4b 100644 (file)
@@ -130,3 +130,11 @@ static const int k_cVal3 = (int)(1000*0.2f);
     char rgch[k_cVal3] = {0};
   }
 }
+
+namespace PR11744 {
+  template<typename T> int f(int n) {
+    T arr[3][n]; // expected-warning 3 {{variable length arrays are a C99 feature}}
+    return 3;
+  }
+  int test = f<int>(0); // expected-note {{instantiation of}}
+}