Handle demotion of coerced arguments (as in void a(x) short x; { ... }).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63726 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 8967ffb..2ad8f917 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -1220,8 +1220,14 @@
       llvm::Value *V = CreateTempAlloca(ConvertType(Ty), "coerce");
       CreateCoercedStore(AI, V, *this);
       // Match to what EmitParmDecl is expecting for this type.
-      if (!CodeGenFunction::hasAggregateLLVMType(Ty))
+      if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
         V = Builder.CreateLoad(V);
+        if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
+          // This must be a promotion, for something like
+          // "void a(x) short x; {..."
+          V = EmitScalarConversion(V, Ty, Arg->getType());
+        }
+      }
       EmitParmDecl(*Arg, V);
       break;
     }
diff --git a/test/Coverage/c-language-features.inc b/test/Coverage/c-language-features.inc
index 9a52e56..8b56e6a 100644
--- a/test/Coverage/c-language-features.inc
+++ b/test/Coverage/c-language-features.inc
@@ -144,3 +144,14 @@
   const char *s1 = __FUNCTION__;
   const char *s2 = __PRETTY_FUNCTION__;
 }
+
+// Arg mismatch with passed type.
+void f7(x) 
+     float x;
+{
+}
+
+void f8(x) 
+     short x;
+{
+}
diff --git a/test/Coverage/codegen.c b/test/Coverage/codegen.c
index 8c9ce02..5d6724e 100644
--- a/test/Coverage/codegen.c
+++ b/test/Coverage/codegen.c
@@ -1,5 +1,7 @@
-// RUN: clang -emit-llvm -o %t %s &&
-// RUN: clang -emit-llvm-bc -o %t %s &&
-// RUN: clang -g -emit-llvm-bc -o %t %s
+// RUN: clang -triple i386-unknown-unknown -emit-llvm -o %t %s &&
+// RUN: clang -triple i386-unknown-unknown -emit-llvm-bc -o %t %s &&
+// RUN: clang -triple i386-unknown-unknown -g -emit-llvm-bc -o %t %s &&
+// RUN: clang -triple x86_64-unknown-unknown -emit-llvm-bc -o %t %s &&
+// RUN: clang -triple x86_64-unknown-unknown -g -emit-llvm-bc -o %t %s
 
 #include "c-language-features.inc"