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.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@136648 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index b5e5c56..af919a1 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -1408,6 +1408,8 @@
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 @@
return false;
}
+
+ is_bitcast = true;
}
else if (const_expr && const_expr->getOpcode() == Instruction::IntToPtr)
{
@@ -1544,7 +1548,30 @@
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());