[cfe-commits] r54612 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/tentative-decls.c

Steve Naroff snaroff at apple.com
Sun Aug 10 08:20:15 PDT 2008


Author: snaroff
Date: Sun Aug 10 10:20:13 2008
New Revision: 54612

URL: http://llvm.org/viewvc/llvm-project?rev=54612&view=rev
Log:
Sema::CheckForFileScopedRedefinitions(): Make sure tentative decls of incomplete array types are completed (and diagnosed properly).


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/tentative-decls.c

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Aug 10 10:20:13 2008
@@ -391,6 +391,7 @@
 /// when dealing with C "tentative" external object definitions (C99 6.9.2).
 void Sema::CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD) {
   bool VDIsTentative = isTentativeDefinition(VD);
+  bool VDIsIncompleteArray = VD->getType()->isIncompleteArrayType();
   
   for (IdentifierResolver::iterator
        I = IdResolver.begin(VD->getIdentifier(), 
@@ -399,6 +400,14 @@
     if (*I != VD && IdResolver.isDeclInScope(*I, VD->getDeclContext(), S)) {
       VarDecl *OldDecl = dyn_cast<VarDecl>(*I);
       
+      // Handle the following case:
+      //   int a[10];
+      //   int a[];   - the code below makes sure we set the correct type. 
+      //   int a[11]; - this is an error, size isn't 10.
+      if (OldDecl && VDIsTentative && VDIsIncompleteArray && 
+          OldDecl->getType()->isConstantArrayType())
+        VD->setType(OldDecl->getType());
+      
       // Check for "tentative" definitions. We can't accomplish this in 
       // MergeVarDecl since the initializer hasn't been attached.
       if (!OldDecl || isTentativeDefinition(OldDecl) || VDIsTentative)

Modified: cfe/trunk/test/Sema/tentative-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tentative-decls.c?rev=54612&r1=54611&r2=54612&view=diff

==============================================================================
--- cfe/trunk/test/Sema/tentative-decls.c (original)
+++ cfe/trunk/test/Sema/tentative-decls.c Sun Aug 10 10:20:13 2008
@@ -27,6 +27,10 @@
 int (*pToArray)[];
 int (*pToArray)[8];
 
+int redef[10];
+int redef[];  // expected-error{{previous definition is here}}
+int redef[11]; // expected-error{{redefinition of 'redef'}}
+
 void func() {
   extern int i1; // expected-error{{previous definition is here}}
   static int i1; // expected-error{{static declaration of 'i1' follows non-static declaration}}





More information about the cfe-commits mailing list