[Lldb-commits] [lldb] r160596 - in /lldb/trunk: include/lldb/Expression/IRForTarget.h source/Expression/IRForTarget.cpp

Sean Callanan scallanan at apple.com
Fri Jul 20 19:02:15 PDT 2012


Author: spyffe
Date: Fri Jul 20 21:02:15 2012
New Revision: 160596

URL: http://llvm.org/viewvc/llvm-project?rev=160596&view=rev
Log:
Added a fix that allows newly-constructed objects
to returned by expressions, by removing the
__cxa_atexit call that would normally cause these
objects to be destroyed.  This also prevents many
errors of the form

Couldn't rewrite one of the arguments of a function call
error: Couldn't materialize struct: Structure hasn't been laid out yet

<rdar://problem/11309402>

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

Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=160596&r1=160595&r2=160596&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Fri Jul 20 21:02:15 2012
@@ -532,6 +532,20 @@
     ResolveCalls (llvm::BasicBlock &basic_block);
     
     //------------------------------------------------------------------
+    /// Remove calls to __cxa_atexit, which should never be generated by
+    /// expressions.
+    ///
+    /// @param[in] call_inst
+    ///     The call instruction.
+    ///
+    /// @return
+    ///     True if the scan was successful; false if some operation
+    ///     failed
+    //------------------------------------------------------------------
+    bool
+    RemoveCXAAtExit (llvm::BasicBlock &basic_block);
+    
+    //------------------------------------------------------------------
     /// The top-level pass implementation
     ///
     /// @param[in] basic_block

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=160596&r1=160595&r2=160596&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Fri Jul 20 21:02:15 2012
@@ -1818,6 +1818,51 @@
 }
 
 bool
+IRForTarget::RemoveCXAAtExit (BasicBlock &basic_block)
+{
+    BasicBlock::iterator ii;
+    
+    std::vector<CallInst *> calls_to_remove;
+    
+    for (ii = basic_block.begin();
+         ii != basic_block.end();
+         ++ii)
+    {
+        Instruction &inst = *ii;
+        
+        CallInst *call = dyn_cast<CallInst>(&inst);
+        
+        // MaybeHandleCallArguments handles error reporting; we are silent here
+        if (!call)
+            continue;
+        
+        bool remove = false;
+    
+        llvm::Function *func = call->getCalledFunction();
+        
+        if (func && func->getName() == "__cxa_atexit")
+            remove = true;
+        
+        llvm::Value *val = call->getCalledValue();
+        
+        if (val && val->getName() == "__cxa_atexit")
+            remove = true;
+        
+        if (remove)
+            calls_to_remove.push_back(call);
+    }
+    
+    for (std::vector<CallInst *>::iterator ci = calls_to_remove.begin(), ce = calls_to_remove.end();
+         ci != ce;
+         ++ci)
+    {
+        (*ci)->eraseFromParent();
+    }
+    
+    return true;
+}
+
+bool
 IRForTarget::ResolveCalls(BasicBlock &basic_block)
 {        
     /////////////////////////////////////////////////////////////////////////
@@ -2684,6 +2729,16 @@
             
             return false;
         }
+        
+        if (!RemoveCXAAtExit(*bbi))
+        {
+            if (log)
+                log->Printf("RemoveCXAAtExit() failed");
+            
+            // RemoveCXAAtExit() reports its own errors, so we don't do so here
+
+            return false;
+        }
     }
     
     if (m_decl_map && m_execution_policy != lldb_private::eExecutionPolicyAlways)





More information about the lldb-commits mailing list