[llvm-commits] [124303] Lower calls to "implicit ..." functions more carefully.
clattner at apple.com
clattner at apple.com
Sun Feb 25 14:01:14 PST 2007
Revision: 124303
Author: clattner
Date: 2007-02-25 14:01:13 -0800 (Sun, 25 Feb 2007)
Log Message:
-----------
Lower calls to "implicit ..." functions more carefully. This implements
test/CFrontend/2007-02-25-C-DotDotDot.c
Modified Paths:
--------------
apple-local/branches/llvm/gcc/llvm-convert.cpp
Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp
===================================================================
--- apple-local/branches/llvm/gcc/llvm-convert.cpp 2007-02-25 18:44:39 UTC (rev 124302)
+++ apple-local/branches/llvm/gcc/llvm-convert.cpp 2007-02-25 22:01:13 UTC (rev 124303)
@@ -2190,7 +2190,7 @@
// Pass the static chain, if any, as the first parameter.
if (TREE_OPERAND(exp, 2))
- CallOperands.push_back (Emit(TREE_OPERAND(exp, 2), 0));
+ CallOperands.push_back(Emit(TREE_OPERAND(exp, 2), 0));
// Loop over the arguments, expanding them and adding them to the op list.
const PointerType *PFTy = cast<PointerType>(Callee->getType());
@@ -2226,8 +2226,28 @@
}
}
- // TODO: Check to see if the arguments and callee types disagree. If so,
- // insert a cast of the callee to a type that will work.
+ // Compile stuff like:
+ // %tmp = call float (...)* bitcast (float ()* @foo to float (...)*)( )
+ // to:
+ // %tmp = call float @foo( )
+ // This commonly occurs due to C "implicit ..." semantics.
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Callee)) {
+ if (CallOperands.empty() && CE->getOpcode() == Instruction::BitCast) {
+ Constant *RealCallee = CE->getOperand(0);
+ assert(isa<PointerType>(RealCallee->getType()) &&
+ "Bitcast to ptr not from ptr?");
+ const PointerType *RealPT = cast<PointerType>(RealCallee->getType());
+ if (const FunctionType *RealFT =
+ dyn_cast<FunctionType>(RealPT->getElementType())) {
+ const PointerType *ActualPT = cast<PointerType>(Callee->getType());
+ const FunctionType *ActualFT =
+ cast<FunctionType>(ActualPT->getElementType());
+ if (RealFT->getReturnType() == ActualFT->getReturnType() &&
+ ActualFT->getNumParams() == 0)
+ Callee = RealCallee;
+ }
+ }
+ }
Value *Call;
if (!UnwindBlock) {
More information about the llvm-commits
mailing list