From eb4b7051a596560ef4a1846e3714707f44e9dc30 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Mon, 25 Aug 2008 21:31:01 +0000 Subject: 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 --- lib/CodeGen/CodeGenFunction.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/CodeGenFunction.cpp') 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()); } -- cgit v1.2.3-70-g09d2