Add type checking for tentative definitions at the end of the
translation unit.

Thread the various declarations of variables via
VarDecl::getPreviousDeclaration.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66601 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Sema/enum.c b/test/Sema/enum.c
index 37c9a1e..dbc250a 100644
--- a/test/Sema/enum.c
+++ b/test/Sema/enum.c
@@ -21,7 +21,9 @@
   return sizeof(enum e) ;
 }
 
-enum gccForwardEnumExtension ve; // expected-warning{{ISO C forbids forward references to 'enum' types}}
+enum gccForwardEnumExtension ve; // expected-warning{{ISO C forbids forward references to 'enum' types}} \
+// expected-error{{tentative definition has type 'enum gccForwardEnumExtension' that is never completed}} \
+// expected-note{{forward declaration of 'enum gccForwardEnumExtension'}}
 
 int test2(int i)
 {
diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c
index 7ec436a..de95740 100644
--- a/test/Sema/incomplete-decl.c
+++ b/test/Sema/incomplete-decl.c
@@ -1,9 +1,9 @@
 // RUN: clang -fsyntax-only -verify %s
 
-struct foo; // expected-note 3 {{forward declaration of 'struct foo'}}
+struct foo; // expected-note 4 {{forward declaration of 'struct foo'}}
 
 void b;  // expected-error {{variable has incomplete type 'void'}}
-struct foo f; // // FIXME: error because 'struct foo' is never defined
+struct foo f; // expected-error{{tentative definition has type 'struct foo' that is never completed}}
 
 static void c; // expected-error {{variable has incomplete type 'void'}}
 static struct foo g;  // expected-error {{variable has incomplete type 'struct foo'}}
diff --git a/test/Sema/init.c b/test/Sema/init.c
index 1f84e41..6f592b8 100644
--- a/test/Sema/init.c
+++ b/test/Sema/init.c
@@ -74,7 +74,8 @@
 };
 
 // PR3001
-struct s1 s2 = {
+struct s1 s2 = { // expected-error{{tentative definition has type 'struct s1' that is never completed}} \
+  // expected-note{{forward declaration of 'struct s1'}}
     .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
                             // expected-note{{forward declaration of 'struct s3'}}
     .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
diff --git a/test/Sema/tentative-decls.c b/test/Sema/tentative-decls.c
index 3c1ab0e..23297f3 100644
--- a/test/Sema/tentative-decls.c
+++ b/test/Sema/tentative-decls.c
@@ -5,7 +5,10 @@
 static struct a x2; // expected-error{{variable has incomplete type 'struct a'}}
 struct a x3[10]; // expected-error{{array has incomplete element type 'struct a'}}
 struct a {int x;};
-struct b x4; // FIXME: error because 'struct b' is never defined
+static struct a x2_okay;
+struct a x3_okay[10];
+struct b x4; // expected-error{{tentative definition has type 'struct b' that is never completed}} \
+            // expected-note{{forward declaration of 'struct b'}}
 
 const int a [1] = {1};
 extern const int a[];
@@ -23,8 +26,8 @@
 extern int i1; // expected-note {{previous definition is here}}
 static int i1; // expected-error{{static declaration of 'i1' follows non-static declaration}}
 
-static int i2 = 5; // expected-note 2 {{previous definition is here}}
-int i2 = 3; // expected-error{{redefinition of 'i2'}} expected-error{{non-static declaration of 'i2' follows static declaration}}
+static int i2 = 5; // expected-note 1 {{previous definition is here}}
+int i2 = 3; // expected-error{{non-static declaration of 'i2' follows static declaration}}
 
 __private_extern__ int pExtern;
 int pExtern = 0;