[Lldb-commits] [lldb] r136648 - /lldb/trunk/source/Expression/IRForTarget.cpp

Sean Callanan scallanan at apple.com
Mon Aug 1 13:53:53 PDT 2011


Author: spyffe
Date: Mon Aug  1 15:53:53 2011
New Revision: 136648

URL: http://llvm.org/viewvc/llvm-project?rev=136648&view=rev
Log:
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.

Modified:
    lldb/trunk/source/Expression/IRForTarget.cpp

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=136648&r1=136647&r2=136648&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Mon Aug  1 15:53:53 2011
@@ -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());
     





More information about the lldb-commits mailing list