http://llvm.org/bugs/show_bug.cgi?id=11618
lldb::SBValue::AddressOf does not work on dereferenced registers in synthetic children provider

Patch submitted by Enrico Granata.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@147637 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index e115054..128db9c 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -406,13 +406,6 @@
                                                             address,
                                                             address_type,
                                                             pvar_sp->GetByteSize());
-        
-        // if the frozen object does not yet have a valid live address we replicate the live_sp address
-        // to it. this solves the issue where synthetic children providers are unable to access
-        // the address-of result for objects obtained by casting the result of pointer arithmetic
-        // performed by the expression parser, as in: print *((ClassType*)(value-1))
-        if (pvar_sp->m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS)
-            pvar_sp->m_frozen_sp->SetLiveAddress(address);
     }
     
     if (pvar_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry)
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index 9128223..7c3e658 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -500,6 +500,8 @@
         
         if (execution_policy != eExecutionPolicyAlways && ir_for_target.interpretSuccess())
         {
+            if (const_result)
+                const_result->TransferAddress();
             evaluated_statically = true;
             err.Clear();
             return err;
diff --git a/source/Expression/ClangExpressionVariable.cpp b/source/Expression/ClangExpressionVariable.cpp
index 9a264eb..ec08a0c 100644
--- a/source/Expression/ClangExpressionVariable.cpp
+++ b/source/Expression/ClangExpressionVariable.cpp
@@ -133,3 +133,15 @@
     m_frozen_sp->ValueUpdated ();
 }
 
+void
+ClangExpressionVariable::TransferAddress (bool force)
+{
+    if (m_live_sp.get() == NULL)
+        return;
+
+    if (m_frozen_sp.get() == NULL)
+        return;
+    
+    if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS))
+        m_frozen_sp->SetLiveAddress(m_live_sp->GetLiveAddress());
+}
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index c2164c8..7719f08 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -525,6 +525,9 @@
         return false;
     }
     
+    if (result)
+        result->TransferAddress();
+    
     return true;
 }