summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/IRForTarget.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2010-09-07 22:43:19 +0000
committerSean Callanan <scallanan@apple.com>2010-09-07 22:43:19 +0000
commit1e87fffb4171f12d7061d887ced3757a0ed09bc9 (patch)
treef4fb8c64c408223bb3f58b60e166d60f43d3c5a6 /lldb/source/Expression/IRForTarget.cpp
parent4d19d2651db1ae869c5719fca5a6804f2abada34 (diff)
downloadbcm5719-llvm-1e87fffb4171f12d7061d887ced3757a0ed09bc9.tar.gz
bcm5719-llvm-1e87fffb4171f12d7061d887ced3757a0ed09bc9.zip
Fixed a bug where we did not handle constant
expressions correctly. These produced a result variable with an initializer but no store instruction, and the store instruction was as a result never rewritten to become a store to a persistent variable. Now if the result variable has an initializer but is never used, we generate a (redundant) store instruction for it, which is then later rewritten into a (useful) store to the persistent result variable. llvm-svn: 113300
Diffstat (limited to 'lldb/source/Expression/IRForTarget.cpp')
-rw-r--r--lldb/source/Expression/IRForTarget.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/lldb/source/Expression/IRForTarget.cpp b/lldb/source/Expression/IRForTarget.cpp
index 6ffc7b977d8..345ae349633 100644
--- a/lldb/source/Expression/IRForTarget.cpp
+++ b/lldb/source/Expression/IRForTarget.cpp
@@ -172,11 +172,42 @@ IRForTarget::createResultVariable(llvm::Module &M,
named_metadata->addOperand(persistent_global_md);
if (log)
- log->Printf("Replacing %s with %s",
- PrintValue(result_global).c_str(),
+ log->Printf("Replacing %s with %s",
+ PrintValue(result_global).c_str(),
PrintValue(new_result_global).c_str());
+
+ if (result_global->hasNUses(0))
+ {
+ // We need to synthesize a store for this variable, because otherwise
+ // there's nothing to put into its equivalent persistent variable.
+
+ BasicBlock &entry_block(F.getEntryBlock());
+ Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
+
+ if (!first_entry_instruction)
+ return false;
+
+ if (!result_global->hasInitializer())
+ {
+ if (log)
+ log->Printf("Couldn't find initializer for unused variable");
+ return false;
+ }
+
+ Constant *initializer = result_global->getInitializer();
+
+ StoreInst *synthesized_store = new StoreInst::StoreInst(initializer,
+ new_result_global,
+ first_entry_instruction);
+
+ if (log)
+ log->Printf("Synthesized result store %s\n", PrintValue(synthesized_store).c_str());
+ }
+ else
+ {
+ result_global->replaceAllUsesWith(new_result_global);
+ }
- result_global->replaceAllUsesWith(new_result_global);
result_global->eraseFromParent();
return true;
OpenPOWER on IntegriCloud