[cfe-commits] r49068 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp test/Sema/array-init.c test/Sema/decl-invalid.c

Chris Lattner sabre at nondot.org
Tue Apr 1 18:05:11 PDT 2008


Author: lattner
Date: Tue Apr  1 20:05:10 2008
New Revision: 49068

URL: http://llvm.org/viewvc/llvm-project?rev=49068&view=rev
Log:
Fix PR2017 and silence some bogus errors.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/array-init.c
    cfe/trunk/test/Sema/decl-invalid.c

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr  1 20:05:10 2008
@@ -951,7 +951,7 @@
     // Block scope. C99 6.7p7: If an identifier for an object is declared with
     // no linkage (C99 6.2.2p6), the type for the object shall be complete...
     if (BVD && IDecl->getStorageClass() != VarDecl::Extern) {
-      if (T->isIncompleteType()) {
+      if (T->isIncompleteType() && !IDecl->isInvalidDecl()) {
         Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
              T.getAsString());
         IDecl->setInvalidDecl();
@@ -967,7 +967,7 @@
       if (T->isIncompleteArrayType()) {
         // C99 6.9.2 (p2, p5): Implicit initialization causes an incomplete
         // array to be completed. Don't issue a diagnostic.
-      } else if (T->isIncompleteType()) {
+      } else if (T->isIncompleteType() && !IDecl->isInvalidDecl()) {
         // C99 6.9.2p3: If the declaration of an identifier for an object is
         // a tentative definition and has internal linkage (C99 6.2.2p3), the  
         // declared type shall not be an incomplete type.
@@ -1100,7 +1100,8 @@
       // C99 6.7.5.3p4: the parameters in a parameter type list in a function
       // declarator that is part of a function definition of that function
       // shall not have incomplete type.
-      if (parmDecl->getType()->isIncompleteType()) {
+      if (parmDecl->getType()->isIncompleteType() &&
+          !parmDecl->isInvalidDecl()) {
         Diag(parmDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
              parmDecl->getType().getAsString());
         parmDecl->setInvalidDecl();

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=49068&r1=49067&r2=49068&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Apr  1 20:05:10 2008
@@ -203,7 +203,7 @@
         DeclType.Ref.AttrList = ProcessTypeAttributes(T, AL);
       break;
     case DeclaratorChunk::Array: {
-      const DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
+      DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
       Expr *ArraySize = static_cast<Expr*>(ATI.NumElts);
       ArrayType::ArraySizeModifier ASM;
       if (ATI.isStar)
@@ -246,9 +246,11 @@
         Diag(ArraySize->getLocStart(), diag::err_array_size_non_int, 
              ArraySize->getType().getAsString(), ArraySize->getSourceRange());
         D.setInvalidType(true);
+        delete ArraySize;
+        ATI.NumElts = ArraySize = 0;
       }
       llvm::APSInt ConstVal(32);
-      // If no expression was provided, we consider it a VLA.
+      // If no expression was provided, we consider it an incomplete array.
       if (!ArraySize) {
         T = Context.getIncompleteArrayType(T, ASM, ATI.TypeQuals);
       } else if (!ArraySize->isIntegerConstantExpr(ConstVal, Context)) {

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

==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Tue Apr  1 20:05:10 2008
@@ -126,8 +126,7 @@
       { 6 },
     },
   };
-  // FIXME: the following two errors are redundant
-  int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}} expected-error{{variable has incomplete type 'int []'}}
+  int a[][] = { 1, 2 }; // expected-error{{array has incomplete element type 'int []'}}
 }
 
 typedef int AryT[];
@@ -159,7 +158,7 @@
   char c3[5] = { "Hello" };
   char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}}
 
-  int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-error{{variable has incomplete type 'int []'}} expected-warning{{use of GNU empty initializer extension}}
+  int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-warning{{use of GNU empty initializer extension}}
 }
 
 void variableArrayInit() {

Modified: cfe/trunk/test/Sema/decl-invalid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/decl-invalid.c?rev=49068&r1=49067&r2=49068&view=diff

==============================================================================
--- cfe/trunk/test/Sema/decl-invalid.c (original)
+++ cfe/trunk/test/Sema/decl-invalid.c Tue Apr  1 20:05:10 2008
@@ -1,3 +1,11 @@
 // RUN: clang %s -fsyntax-only -verify
 
 typedef union <anonymous> __mbstate_t;  // expected-error: {{expected identifier or}}
+
+
+// PR2017
+void x(); 
+int a() {
+  int r[x()];  // expected-error: {{size of array has non-integer type 'void'}}
+}
+





More information about the cfe-commits mailing list