aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-08-25 21:31:01 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-08-25 21:31:01 +0000
commiteb4b7051a596560ef4a1846e3714707f44e9dc30 (patch)
tree594c0010b8352c42c8003c98aab7ee759e0ce040 /lib/CodeGen
parentc9e56b2a63f023b298d92fc572c0d47538aae964 (diff)
Do typechecking and codegen for K&R-style function declarations
correctly. Not a regression, but made more obvious by my recent fix which made function type compatibility checking a bit more strict. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index af63be73fe..11fde87302 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -138,10 +138,23 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
AI->setName("agg.result");
++AI;
}
-
- for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i, ++AI) {
- assert(AI != CurFn->arg_end() && "Argument mismatch!");
- EmitParmDecl(*FD->getParamDecl(i), AI);
+
+ if (FD->getNumParams()) {
+ const FunctionTypeProto* FProto = FD->getType()->getAsFunctionTypeProto();
+ assert(FProto && "Function def must have prototype!");
+ for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i, ++AI) {
+ assert(AI != CurFn->arg_end() && "Argument mismatch!");
+ const ParmVarDecl* CurParam = FD->getParamDecl(i);
+ llvm::Value* V = AI;
+ if (!getContext().typesAreCompatible(FProto->getArgType(i),
+ CurParam->getType())) {
+ // This must be a promotion, for something like
+ // "void a(x) short x; {..."
+ V = EmitScalarConversion(V, FProto->getArgType(i),
+ CurParam->getType());
+ }
+ EmitParmDecl(*CurParam, V);
+ }
}
GenerateFunction(FD->getBody());
}