]> granicus.if.org Git - clang/commitdiff
Add a bit more handling for declarations like "int a[*]".
authorEli Friedman <eli.friedman@gmail.com>
Sun, 26 Apr 2009 21:57:51 +0000 (21:57 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 26 Apr 2009 21:57:51 +0000 (21:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70162 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/AST/Type.cpp
lib/Sema/SemaType.cpp
test/Sema/vla.c

index bc46bdf994a4b7cff60b0de22cd8aab9baece8d7..7225aadbbc1ec04952f90084c3954302db31694e 100644 (file)
@@ -891,6 +891,8 @@ def err_illegal_decl_array_incomplete_type : Error<
   "array has incomplete element type %0">;
 def err_illegal_decl_array_of_references : Error<
   "'%0' declared as array of references">;
+def err_array_star_outside_prototype : Error<
+  "star modifier used outside of function prototype">;
 def err_illegal_decl_pointer_to_reference : Error<
   "'%0' declared as a pointer to a reference">;
 def err_illegal_decl_mempointer_to_void : Error<
index a94310bbdf390e14db9432b7e92d8124cae0bfdc..0331bbf40ddc2851b4975d8e7d177462d356b234 100644 (file)
@@ -37,7 +37,8 @@ void Type::Destroy(ASTContext& C) {
 }
 
 void VariableArrayType::Destroy(ASTContext& C) {
-  SizeExpr->Destroy(C);
+  if (SizeExpr)
+    SizeExpr->Destroy(C);
   this->~VariableArrayType();
   C.Deallocate(this);
 }
index 883cf221fba88ebc26925ed13689dbbd6be0da45..5df0aecd8fae7713f6994f43daab7f5956262a29 100644 (file)
@@ -500,7 +500,10 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
   }
   llvm::APSInt ConstVal(32);
   if (!ArraySize) {
-    T = Context.getIncompleteArrayType(T, ASM, Quals);
+    if (ASM == ArrayType::Star)
+      T = Context.getVariableArrayType(T, 0, ASM, Quals);
+    else
+      T = Context.getIncompleteArrayType(T, ASM, Quals);
   } else if (ArraySize->isValueDependent()) {
     T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals);
   } else if (!ArraySize->isIntegerConstantExpr(ConstVal, Context) ||
@@ -687,6 +690,15 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip) {
         ASM = ArrayType::Static;
       else
         ASM = ArrayType::Normal;
+      if (ASM == ArrayType::Star &&
+          D.getContext() != Declarator::PrototypeContext) {
+        // FIXME: This check isn't quite right: it allows star in prototypes
+        // for function definitions, and disallows some edge cases detailed
+        // in http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00133.html
+        Diag(DeclType.Loc, diag::err_array_star_outside_prototype);
+        ASM = ArrayType::Normal;
+        D.setInvalidType(true);
+      }
       T = BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals, DeclType.Loc, Name);
       break;
     }
index 252e9ff62e5331b360e643beb37fc34ec34fae6a..b4839143bf757366f621e1aff8b4924a86d40e50 100644 (file)
@@ -43,3 +43,6 @@ void f3()
 
 // PR3663
 static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{size of static array must be an integer constant expression}}
+
+int a[*]; // expected-error {{star modifier used outside of function prototype}}
+int f4(int a[*][*]);