Fix the following bug submitted by Ted Kremenek:

void func() {
int xx = xx; // incorrectly diagnosed 'xx' as an undeclared identifier.
}

This smallish bug resulted in a largish fix. Here are some highlights:

- Needed to make sure ParseDeclarator is called *before* parsing any
initializer. Removed the "Init" argument to ParseDeclarator.
- Added AddInitializerToDecl() to the Action & Sema classes.
In Sema, this hook is responsible for validating the initializer and
installing it into the respective decl.
- Moved several semantic checks from ParseDeclarator() to 
FinalizeDeclaratorGroup(). Previously, this hook was only responsible for 
reversing a list. Now it plays a much larger semantic role. 

All of the above changes ended up simplifying ParseDeclarator(), which
is goodness...



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41877 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Parse/MinimalAction.cpp b/Parse/MinimalAction.cpp
index 8ca7258..377a2e7 100644
--- a/Parse/MinimalAction.cpp
+++ b/Parse/MinimalAction.cpp
@@ -43,8 +43,7 @@
 /// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
 /// popped.
 Action::DeclTy *
-MinimalAction::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
-                               DeclTy *LastInGroup) {
+MinimalAction::ParseDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) {
   IdentifierInfo *II = D.getIdentifier();
   
   // If there is no identifier associated with this declarator, bail out.
diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp
index dc9edc3..be37111 100644
--- a/Parse/ParseDecl.cpp
+++ b/Parse/ParseDecl.cpp
@@ -262,7 +262,11 @@
     // If attributes are present, parse them.
     if (Tok.getKind() == tok::kw___attribute)
       D.AddAttributes(ParseAttributes());
-    
+
+    // Inform the current actions module that we just parsed this declarator.
+    // FIXME: pass asm & attributes.
+    LastDeclInGroup = Actions.ParseDeclarator(CurScope, D, LastDeclInGroup);
+        
     // Parse declarator '=' initializer.
     ExprResult Init;
     if (Tok.getKind() == tok::equal) {
@@ -272,13 +276,9 @@
         SkipUntil(tok::semi);
         return 0;
       }
+      Actions.AddInitializerToDecl(LastDeclInGroup, Init.Val);
     }
     
-    // Inform the current actions module that we just parsed this declarator.
-    // FIXME: pass asm & attributes.
-    LastDeclInGroup = Actions.ParseDeclarator(CurScope, D, Init.Val,
-                                              LastDeclInGroup);
-    
     // If we don't have a comma, it is either the end of the list (a ';') or an
     // error, bail out.
     if (Tok.getKind() != tok::comma)
diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp
index da1bb52..21ef54d 100644
--- a/Parse/Parser.cpp
+++ b/Parse/Parser.cpp
@@ -242,7 +242,7 @@
     
     Declarator D(DS, Declarator::FileContext);
     D.SetIdentifier(PP.getIdentifierInfo("__builtin_va_list"),SourceLocation());
-    Actions.ParseDeclarator(CurScope, D, 0, 0);
+    Actions.ParseDeclarator(CurScope, D, 0);
   }
   
   if (Tok.getKind() == tok::eof &&