Fixed bug in FunctionDecl serialization where we crashed when the
FunctionDecl had decls for its parameters but still had greater than 0
arguments.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44076 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/DeclSerialization.cpp b/AST/DeclSerialization.cpp
index 71706e3..b881cbe 100644
--- a/AST/DeclSerialization.cpp
+++ b/AST/DeclSerialization.cpp
@@ -226,9 +226,15 @@
   // NOTE: We do not need to serialize out the number of parameters, because
   //  that is encoded in the type (accessed via getNumParams()).
   
-  S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], // From FunctionDecl.
-                       Body, // From FunctionDecl.
-                       getNextDeclarator());  // From ScopedDecl.
+  if (ParamInfo != NULL) {
+    S.EmitBool(true);
+    S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body,
+                         getNextDeclarator());
+  }
+  else {
+    S.EmitBool(false);
+    S.BatchEmitOwnedPtrs(Body,getNextDeclarator());  
+  }
 }
 
 FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D) {
@@ -247,10 +253,14 @@
   
   Decl* next_declarator;
   
-  D.BatchReadOwnedPtrs(decl->getNumParams(),
-                reinterpret_cast<Decl**>(&decl->ParamInfo[0]), // FunctionDecl.
-                decl->Body,  // From FunctionDecl.
-                next_declarator); // From ScopedDecl.
+  bool hasParamDecls = D.ReadBool();
+  
+  if (hasParamDecls)
+    D.BatchReadOwnedPtrs(decl->getNumParams(),
+                         reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
+                         decl->Body, next_declarator);
+  else
+    D.BatchReadOwnedPtrs(decl->Body, next_declarator);
   
   decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));