When a function with a prototype is redeclared without a prototype,
merge the prototype into the redeclaration (and make a note in the
declaration). Fixes PR3588.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 3960a7d..444f85e 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -593,7 +593,24 @@
   // duplicate function decls like "void f(int); void f(enum X);" properly.
   if (!getLangOptions().CPlusPlus &&
       Context.typesAreCompatible(OldQType, NewQType)) {
+    const FunctionType *NewFuncType = NewQType->getAsFunctionType();
+    const FunctionTypeProto *OldProto = 0;
+    if (isa<FunctionTypeNoProto>(NewFuncType) &&
+        (OldProto = OldQType->getAsFunctionTypeProto())) {
+      // The old declaration provided a function prototype, but the
+      // new declaration does not. Merge in the prototype.
+      llvm::SmallVector<QualType, 16> ParamTypes(OldProto->arg_type_begin(),
+                                                 OldProto->arg_type_end());
+      NewQType = Context.getFunctionType(NewFuncType->getResultType(),
+                                         &ParamTypes[0], ParamTypes.size(),
+                                         OldProto->isVariadic(),
+                                         OldProto->getTypeQuals());
+      New->setType(NewQType);
+      New->setInheritedPrototype();
+    }
+
     MergeAttributes(New, Old);
+    
     return false;
   }