Index: lib/CodeGen/CodeGenFunction.cpp =================================================================== --- lib/CodeGen/CodeGenFunction.cpp (revision 55278) +++ lib/CodeGen/CodeGenFunction.cpp (working copy) @@ -138,10 +138,19 @@ 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 (FProto->getArgType(i) != CurParam->getType()) + V = EmitScalarConversion(V, FProto->getArgType(i), + CurParam->getType()); + EmitParmDecl(*CurParam, V); + } } GenerateFunction(FD->getBody()); } Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp (revision 55278) +++ lib/Sema/SemaDecl.cpp (working copy) @@ -690,8 +694,7 @@ // Copy the parameter declarations from the declarator D to // the function declaration NewFD, if they are available. - if (D.getNumTypeObjects() > 0 && - D.getTypeObject(0).Fun.hasPrototype) { + if (D.getNumTypeObjects() > 0) { DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; // Create Decl objects for each parameter, adding them to the @@ -716,7 +719,7 @@ Diag(Param->getLocation(), diag::ext_param_typedef_of_void); } - } else { + } else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) { for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) Params.push_back((ParmVarDecl *)FTI.ArgInfo[i].Param); } @@ -1538,11 +1541,6 @@ FTI.ArgInfo[i].Param = ActOnParamDeclarator(FnBodyScope, ParamD); } } - - // Since this is a function definition, act as though we have information - // about the arguments. - if (FTI.NumArgs) - FTI.hasPrototype = true; } else { // FIXME: Diagnose arguments without names in C. } Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp (revision 55278) +++ lib/Sema/SemaType.cpp (working copy) @@ -397,14 +399,12 @@ D.setInvalidType(true); } - if (!FTI.hasPrototype) { + if (FTI.NumArgs == 0) { // Simple void foo(), where the incoming T is the result type. T = Context.getFunctionTypeNoProto(T); - + } else if (FTI.ArgInfo[0].Param == 0) { // C99 6.7.5.3p3: Reject int(x,y,z) when it's not a function definition. - if (FTI.NumArgs != 0) - Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration); - + Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration); } else { // Otherwise, we have a function with an argument list that is // potentially variadic. @@ -458,6 +458,13 @@ // Do not add 'void' to the ArgTys list. break; } + } else if (!FTI.hasPrototype) { + if (ArgTy->isPromotableIntegerType()) { + ArgTy = Context.IntTy; + } else if (const BuiltinType* BTy = ArgTy->getAsBuiltinType()) { + if (BTy->getKind() == BuiltinType::Float) + ArgTy = Context.DoubleTy; + } } ArgTys.push_back(ArgTy);