diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 6a9065e..2b46a45 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2402,6 +2402,27 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
   if (getLangOpts().CPlusPlus)
     return MergeCXXFunctionDecl(New, Old, S);
 
+  // Merge the return types so the we get the composite.
+  // FIXME: We should probably merge the full function type, but that can
+  // produce a function definition where the ParmVarDecl type doesn't match
+  // the argument type in the FunctionProtoType, which CodeGen expects.
+  // FIXME: Should we patch the ParmVarDecl? Should we make CodeGen produce
+  // a cast?
+  QualType NewType = New->getType();
+  QualType MergedReturn = Context.mergeTypes(Old->getResultType(),
+                                             New->getResultType());
+  QualType MergedType;
+  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(NewType)) {
+    FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+    MergedType = Context.getFunctionType(MergedReturn, FPT->arg_type_begin(),
+                                        FPT->getNumArgs(), EPI);
+    New->setType(MergedType);
+  } else if (const FunctionType *FT = dyn_cast<FunctionType>(NewType)) {
+    FunctionType::ExtInfo EI = FT->getExtInfo();
+    MergedType = Context.getFunctionNoProtoType(MergedReturn, EI);
+    New->setType(MergedType);
+  }
+
   return false;
 }
 
diff --git a/test/Sema/merge-decls.c b/test/Sema/merge-decls.c
index da3e245..51c6378 100644
--- a/test/Sema/merge-decls.c
+++ b/test/Sema/merge-decls.c
@@ -48,3 +48,18 @@ void test1_g(void)
   }
   (void)sizeof(*test1_f());
 }
+
+typedef int test2_IA[];
+typedef int test2_A10[10];
+
+static test2_A10 *test2_f(void);
+static test2_IA  *test2_f(void);
+
+void test2_g(void)
+{
+  (void)sizeof(*test2_f());
+}
+
+int (*test3_f())[10];
+int (*test3_f())[];
+int test3_k = sizeof(*test3_f());
