summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse.llvm@gmail.com>2019-07-01 09:38:23 +0000
committerJeremy Morse <jeremy.morse.llvm@gmail.com>2019-07-01 09:38:23 +0000
commitd2b6665e33944eb04ea699124f15850ba22a144a (patch)
treec7323403d652a99a5056b0bb3694b9133b14d636 /llvm/lib/IR
parent9d34f4569b48821fdc27ab520fecde9ec09b344b (diff)
downloadbcm5719-llvm-d2b6665e33944eb04ea699124f15850ba22a144a.tar.gz
bcm5719-llvm-d2b6665e33944eb04ea699124f15850ba22a144a.zip
[DebugInfo] Avoid adding too much indirection to pointer-valued variables
This patch addresses PR41675, where a stack-pointer variable is dereferenced too many times by its location expression, presenting a value on the stack as the pointer to the stack. The difference between a stack *pointer* DBG_VALUE and one that refers to a value on the stack, is currently the indirect flag. However the DWARF backend will also try to guess whether something is a memory location or not, based on whether there is any computation in the location expression. By simply prepending the stack offset to existing expressions, we can accidentally convert a register location into a memory location, which introduces a suprise (and unintended) dereference. The solution is to add DW_OP_stack_value whenever we add a DIExpression computation to a stack *pointer*. It's an implicit location computed on the expression stack, thus needs to be flagged as a stack_value. For the edge case where the offset is zero and the location could be a register location, DIExpression::prepend will still generate opcodes, and thus DW_OP_stack_value must still be added. Differential Revision: https://reviews.llvm.org/D63429 llvm-svn: 364736
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 1607cf5104f..900df27d1d3 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -926,6 +926,27 @@ bool DIExpression::isImplicit() const {
return false;
}
+bool DIExpression::isComplex() const {
+ if (!isValid())
+ return false;
+
+ if (getNumElements() == 0)
+ return false;
+
+ // If there are any elements other than fragment or tag_offset, then some
+ // kind of complex computation occurs.
+ for (const auto &It : expr_ops()) {
+ switch (It.getOp()) {
+ case dwarf::DW_OP_LLVM_tag_offset:
+ case dwarf::DW_OP_LLVM_fragment:
+ continue;
+ default: return true;
+ }
+ }
+
+ return false;
+}
+
Optional<DIExpression::FragmentInfo>
DIExpression::getFragmentInfo(expr_op_iterator Start, expr_op_iterator End) {
for (auto I = Start; I != End; ++I)
OpenPOWER on IntegriCloud