summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/IRForTarget.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2011-08-01 20:53:53 +0000
committerSean Callanan <scallanan@apple.com>2011-08-01 20:53:53 +0000
commit7f3755b5ff95d68d985c61f9c5918dcc169b0952 (patch)
treeaf46d790dc9fda18487019675834c76198de7bdc /lldb/source/Expression/IRForTarget.cpp
parentfb1d9f325c25cbce5e8ad73119209810cb9816ae (diff)
downloadbcm5719-llvm-7f3755b5ff95d68d985c61f9c5918dcc169b0952.tar.gz
bcm5719-llvm-7f3755b5ff95d68d985c61f9c5918dcc169b0952.zip
Fixed a problem in the expression parser that
caused functions that were cast as part of the call to have that cast ignored once their addresses were resolved. Notably, in the case of objc_msgSend(), if the function was cast from something returning i8* to something returning i8, the expression parser was discarding the cast as part of its resolution. This caused crashes later on. llvm-svn: 136648
Diffstat (limited to 'lldb/source/Expression/IRForTarget.cpp')
-rw-r--r--lldb/source/Expression/IRForTarget.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp
index b5e5c561f75..af919a15f21 100644
--- a/lldb/source/Expression/IRForTarget.cpp
+++ b/lldb/source/Expression/IRForTarget.cpp
@@ -1408,6 +1408,8 @@ IRForTarget::MaybeHandleCall (CallInst *llvm_call_inst)
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Function *fun = llvm_call_inst->getCalledFunction();
+
+ bool is_bitcast = false;
// If the call is to something other than a plain llvm::Function, resolve which
// Function is meant or give up.
@@ -1430,6 +1432,8 @@ IRForTarget::MaybeHandleCall (CallInst *llvm_call_inst)
return false;
}
+
+ is_bitcast = true;
}
else if (const_expr && const_expr->getOpcode() == Instruction::IntToPtr)
{
@@ -1544,7 +1548,30 @@ IRForTarget::MaybeHandleCall (CallInst *llvm_call_inst)
if (fun_value_ptr)
fun_addr_ptr = *fun_value_ptr;
- llvm_call_inst->setCalledFunction(fun_addr_ptr);
+ if (is_bitcast)
+ {
+ Value *val = llvm_call_inst->getCalledValue();
+
+ ConstantExpr *const_expr = dyn_cast<ConstantExpr>(val);
+
+ Constant *fun_addr_ptr_cst = dyn_cast<Constant>(fun_addr_ptr);
+
+ if (!fun_addr_ptr_cst)
+ {
+ if (m_error_stream)
+ m_error_stream->Printf("Error [IRForTarget]: Non-constant source function '%s' has a constant BitCast\n", str.GetCString());
+
+ return false;
+ }
+
+ Constant *new_bit_cast = ConstantExpr::getBitCast(fun_addr_ptr_cst, const_expr->getType());
+
+ llvm_call_inst->setCalledFunction(new_bit_cast);
+ }
+ else
+ {
+ llvm_call_inst->setCalledFunction(fun_addr_ptr);
+ }
ConstantArray *func_name = (ConstantArray*)ConstantArray::get(m_module->getContext(), str.GetCString());
OpenPOWER on IntegriCloud