diff options
| author | Sean Callanan <scallanan@apple.com> | 2010-11-08 00:31:32 +0000 |
|---|---|---|
| committer | Sean Callanan <scallanan@apple.com> | 2010-11-08 00:31:32 +0000 |
| commit | a4e55178bcfcc82572c4fe476f854b8f5a864c5a (patch) | |
| tree | 717fe32d7728664dc5fd2000baeb6d80f525fa4f | |
| parent | 7481c20f090d669e434a84ada73a6ddf3d9cd417 (diff) | |
| download | bcm5719-llvm-a4e55178bcfcc82572c4fe476f854b8f5a864c5a.tar.gz bcm5719-llvm-a4e55178bcfcc82572c4fe476f854b8f5a864c5a.zip | |
Made variable resolution more robust by handling
every external variable reference in the module,
and returning a clean error (instead of letting
LLVM issue a fatal error) if the variable could
not be resolved.
llvm-svn: 118388
| -rw-r--r-- | lldb/include/lldb/Expression/IRForTarget.h | 32 | ||||
| -rw-r--r-- | lldb/source/Expression/IRForTarget.cpp | 52 |
2 files changed, 50 insertions, 34 deletions
diff --git a/lldb/include/lldb/Expression/IRForTarget.h b/lldb/include/lldb/Expression/IRForTarget.h index 555a910f80c..826277c5574 100644 --- a/lldb/include/lldb/Expression/IRForTarget.h +++ b/lldb/include/lldb/Expression/IRForTarget.h @@ -193,11 +193,11 @@ private: llvm::BasicBlock &BB); //------------------------------------------------------------------ - /// A basic block-level pass to find all external variables and - /// functions used in the IR. Each found external variable is added - /// to the struct, and each external function is resolved in place, - /// its call replaced with a call to a function pointer whose value - /// is the address of the function in the target process. + /// A function-level pass to find all external variables and functions + /// used in the IR. Each found external variable is added to the + /// struct, and each external function is resolved in place, its call + /// replaced with a call to a function pointer whose value is the + /// address of the function in the target process. //------------------------------------------------------------------ //------------------------------------------------------------------ @@ -216,8 +216,7 @@ private: /// True on success; false otherwise //------------------------------------------------------------------ bool MaybeHandleVariable(llvm::Module &M, - llvm::Value *V, - bool Store); + llvm::Value *V); //------------------------------------------------------------------ /// Handle all the arguments to a function call @@ -250,7 +249,7 @@ private: llvm::CallInst *C); //------------------------------------------------------------------ - /// The top-level pass implementation + /// Resolve calls to external functions /// /// @param[in] M /// The module currently being processed. @@ -261,8 +260,23 @@ private: /// @return /// True on success; false otherwise //------------------------------------------------------------------ + bool resolveCalls(llvm::Module &M, + llvm::BasicBlock &BB); + + //------------------------------------------------------------------ + /// The top-level pass implementation + /// + /// @param[in] M + /// The module currently being processed. + /// + /// @param[in] BB + /// The function currently being processed. + /// + /// @return + /// True on success; false otherwise + //------------------------------------------------------------------ bool resolveExternals(llvm::Module &M, - llvm::BasicBlock &BB); + llvm::Function &F); //------------------------------------------------------------------ /// A basic block-level pass to excise guard variables from the code. diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp index 3ddb9efd40f..4fc461f939f 100644 --- a/lldb/source/Expression/IRForTarget.cpp +++ b/lldb/source/Expression/IRForTarget.cpp @@ -563,8 +563,7 @@ bool IRForTarget::MaybeHandleVariable ( Module &llvm_module, - Value *llvm_value_ptr, - bool Store + Value *llvm_value_ptr ) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); @@ -578,7 +577,7 @@ IRForTarget::MaybeHandleVariable case Instruction::GetElementPtr: case Instruction::BitCast: Value *s = constant_expr->getOperand(0); - MaybeHandleVariable(llvm_module, s, Store); + MaybeHandleVariable(llvm_module, s); } } if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(llvm_value_ptr)) @@ -646,7 +645,7 @@ IRForTarget::MaybeHandleCallArguments(Module &M, for (unsigned op_index = 0, num_ops = C->getNumArgOperands(); op_index < num_ops; ++op_index) - if (!MaybeHandleVariable(M, C->getArgOperand(op_index), true)) // conservatively believe that this is a store + if (!MaybeHandleVariable(M, C->getArgOperand(op_index))) // conservatively believe that this is a store return false; return true; @@ -773,7 +772,7 @@ IRForTarget::MaybeHandleCall(Module &llvm_module, } bool -IRForTarget::resolveExternals(Module &M, BasicBlock &BB) +IRForTarget::resolveCalls(Module &M, BasicBlock &BB) { ///////////////////////////////////////////////////////////////////////// // Prepare the current basic block for execution in the remote process @@ -787,31 +786,31 @@ IRForTarget::resolveExternals(Module &M, BasicBlock &BB) { Instruction &inst = *ii; - if (m_resolve_vars) - { - if (LoadInst *load = dyn_cast<LoadInst>(&inst)) - if (!MaybeHandleVariable(M, load->getPointerOperand(), false)) - return false; - - if (StoreInst *store = dyn_cast<StoreInst>(&inst)) - if (!MaybeHandleVariable(M, store->getValueOperand(), true) || - !MaybeHandleVariable(M, store->getPointerOperand(), true)) - return false; - } + CallInst *call = dyn_cast<CallInst>(&inst); - if (CallInst *call = dyn_cast<CallInst>(&inst)) - { - if (!MaybeHandleCallArguments(M, call)) - return false; - - if (!MaybeHandleCall(M, call)) - return false; - } + if (call && !MaybeHandleCall(M, call)) + return false; } return true; } +bool +IRForTarget::resolveExternals(Module &M, + Function &F) +{ + for (Module::global_iterator global = M.global_begin(), end = M.global_end(); + global != end; + ++global) + { + if ((*global).hasExternalLinkage() && + !MaybeHandleVariable (M, global)) + return false; + } + + return true; +} + static bool isGuardVariableRef(Value *V) { Constant *C; @@ -1156,7 +1155,7 @@ IRForTarget::runOnModule(Module &M) if (!rewriteObjCSelectors(M, *bbi)) return false; - if (!resolveExternals(M, *bbi)) + if (!resolveCalls(M, *bbi)) return false; } @@ -1164,6 +1163,9 @@ IRForTarget::runOnModule(Module &M) // Run function-level passes // + if (!resolveExternals(M, *function)) + return false; + if (!replaceVariables(M, *function)) return false; |

