[Lldb-commits] [PATCH] D102624: [lldb] Optimize expressions

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon May 17 09:45:29 PDT 2021

teemperor added inline comments.

Comment at: lldb/source/Plugins/ExpressionParser/Clang/ASTResultSynthesizer.cpp:409
+  //       static MyClass *__lldb_expr_result_ptr = &c; // Points to stack.
+  //       __lldb_expr_result_ptr(__lldb_expr_result_ptr);
+  //     } // End of expression function.
vsk wrote:
> vsk wrote:
> > Why is it safe for lldb to take the address of "c"? After evaluation completes, is the state of the stack preserved?
> Would marking `__lldb_expr_result_ptr` volatile make the call to `__lldb_use_expr_result` redundant?
That's actually a good point and I am actually writing up an RFC about the current behaviour to lldb-dev. The current behaviour of LLDB is that we end the function call, we call all the destructors and so on and then we read the results from memory. So the memory we read is just the leftovers after the function call has returned. That's why a unique_ptr local variable in LLDB always looks like it owns no memory because we read it after it got already destroyed. I'm actually thinking whether/how we should fix that behaviour as seems rather fragile (but that's for the RFC).

So unless I'm missing something, we currently already rely on the stack being preserved to even get the correct results. The function call is just there to make sure the optimizer doesn't realize what we're up to.

Not sure about the `volatile` and if it would help. The `__lldb_expr_result` variable gets transformed by IRForTarget until it ends up being just a part of our argument struct IIRC, so I need to look into that before I know where we could sneak in a volatile.



More information about the lldb-commits mailing list