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

Sean Callanan scallanan at apple.com
Tue Sep 7 15:43:20 PDT 2010


Author: spyffe
Date: Tue Sep  7 17:43:19 2010
New Revision: 113300

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

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=113300&r1=113299&r2=113300&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Tue Sep  7 17:43:19 2010
@@ -172,11 +172,42 @@
     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;





More information about the lldb-commits mailing list