[cfe-commits] r39727 - /cfe/cfe/trunk/CodeGen/CGExpr.cpp
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:47:36 PDT 2007
Author: clattner
Date: Wed Jul 11 11:47:35 2007
New Revision: 39727
URL: http://llvm.org/viewvc/llvm-project?rev=39727&view=rev
Log:
implement codegen support for the "default argument promotions" (C99 6.5.2.2p6).
Not having this prevented promoting float arguments to double when passed
into printf, for example.
Modified:
cfe/cfe/trunk/CodeGen/CGExpr.cpp
Modified: cfe/cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGExpr.cpp?rev=39727&r1=39726&r2=39727&view=diff
==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:47:35 2007
@@ -523,15 +523,46 @@
}
RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
- QualType Ty;
+ QualType CalleeTy;
llvm::Value *Callee =
- EmitExprWithUsualUnaryConversions(E->getCallee(), Ty).getVal();
+ EmitExprWithUsualUnaryConversions(E->getCallee(), CalleeTy).getVal();
+
+ // The callee type will always be a pointer to function type, get the function
+ // type.
+ CalleeTy = cast<PointerType>(CalleeTy.getCanonicalType())->getPointeeType();
+
+ // Get information about the argument types.
+ FunctionTypeProto::arg_type_iterator ArgTyIt = 0, ArgTyEnd = 0;
+
+ // Calling unprototyped functions provides no argument info.
+ if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(CalleeTy)) {
+ ArgTyIt = FTP->arg_type_begin();
+ ArgTyEnd = FTP->arg_type_end();
+ }
llvm::SmallVector<llvm::Value*, 16> Args;
// FIXME: Handle struct return.
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
- RValue ArgVal = EmitExprWithUsualUnaryConversions(E->getArg(i), Ty);
+ QualType ArgTy;
+ RValue ArgVal = EmitExprWithUsualUnaryConversions(E->getArg(i), ArgTy);
+
+ // If this argument has prototype information, convert it.
+ if (ArgTyIt != ArgTyEnd) {
+ ArgVal = EmitConversion(ArgVal, ArgTy, *ArgTyIt++);
+ } else {
+ // Otherwise, if passing through "..." or to a function with no prototype,
+ // perform the "default argument promotions" (C99 6.5.2.2p6), which
+ // includes the usual unary conversions, but also promotes float to
+ // double.
+ if (const BuiltinType *BT =
+ dyn_cast<BuiltinType>(ArgTy.getCanonicalType())) {
+ if (BT->getKind() == BuiltinType::Float)
+ ArgVal = RValue::get(Builder.CreateFPExt(ArgVal.getVal(),
+ llvm::Type::DoubleTy,"tmp"));
+ }
+ }
+
if (ArgVal.isScalar())
Args.push_back(ArgVal.getVal());
More information about the cfe-commits
mailing list