[cfe-commits] r46234 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/array-init.c

Steve Naroff snaroff at apple.com
Mon Jan 21 15:54:11 PST 2008


Author: snaroff
Date: Mon Jan 21 17:53:58 2008
New Revision: 46234

URL: http://llvm.org/viewvc/llvm-project?rev=46234&view=rev
Log:
Sema::CheckInitializerTypes(). Start simpliying and cleaning up...


Modified:
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/array-init.c

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=46234&r1=46233&r2=46234&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Jan 21 17:53:58 2008
@@ -513,6 +513,13 @@
 bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType) {
   bool hadError = false;
   
+  // C99 6.7.8p3: The type of the entity to be initialized shall be an array
+  // of unknown size ("[]") or an object type that is not a variable array type.
+  if (const VariableArrayType *VAT = DeclType->getAsVariablyModifiedType())
+    return Diag(VAT->getSizeExpr()->getLocStart(), 
+                diag::err_variable_object_no_init, 
+                VAT->getSizeExpr()->getSourceRange());
+  
   InitListExpr *InitList = dyn_cast<InitListExpr>(Init);
   if (!InitList) {
     if (StringLiteral *strLiteral = dyn_cast<StringLiteral>(Init)) {
@@ -550,10 +557,7 @@
 
   // C99 6.7.8p3: The type of the entity to be initialized shall be an array
   // of unknown size ("[]") or an object type that is not a variable array type.
-  if (const VariableArrayType *VAT = DeclType->getAsVariableArrayType()) { 
-    if (const Expr *expr = VAT->getSizeExpr())
-      return Diag(expr->getLocStart(), diag::err_variable_object_no_init, 
-                  expr->getSourceRange());
+  if (const VariableArrayType *VAT = DeclType->getAsIncompleteArrayType()) { 
 
     // We have a VariableArrayType with unknown size. Note that only the first
     // array can have unknown size. For example, "int [][]" is illegal.

Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=46234&r1=46233&r2=46234&view=diff

==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Mon Jan 21 17:53:58 2008
@@ -162,3 +162,8 @@
   int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-warning{{use of GNU empty initializer extension}}
 }
 
+void variableArrayInit() {
+  int a = 4;
+  char strlit[a] = "foo"; //expected-error{{variable-sized object may not be initialized}}
+  int b[a] = { 1, 2, 4 }; //expected-error{{variable-sized object may not be initialized}}
+}





More information about the cfe-commits mailing list