summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-07-26 20:56:53 +0000
committerVedant Kumar <vsk@apple.com>2018-07-26 20:56:53 +0000
commitb572f6421296e7688973014d253e46c54fd64ba3 (patch)
treee465c68573ed92b065e9be5d926a8df3edc16df4
parent024e1762aa6a89c623df8b1fcbd6b19744bebbde (diff)
downloadbcm5719-llvm-b572f6421296e7688973014d253e46c54fd64ba3.tar.gz
bcm5719-llvm-b572f6421296e7688973014d253e46c54fd64ba3.zip
[DebugInfo] LowerDbgDeclare: Add derefs when handling CallInst users
LowerDbgDeclare inserts a dbg.value before each use of an address described by a dbg.declare. When inserting a dbg.value before a CallInst use, however, it fails to append DW_OP_deref to the DIExpression. The DW_OP_deref is needed to reflect the fact that a dbg.value describes a source variable directly (as opposed to a dbg.declare, which relies on pointer indirection). This patch adds in the DW_OP_deref where needed. This results in the correct values being shown during a debug session for a program compiled with ASan and optimizations (see https://reviews.llvm.org/D49520). Note that ConvertDebugDeclareToDebugValue is already correct -- no changes there were needed. One complication is that SelectionDAG is unable to distinguish between direct and indirect frame-index (FRAMEIX) SDDbgValues. This patch also fixes this long-standing issue in order to not regress integration tests relying on the incorrect assumption that all frame-index SDDbgValues are indirect. This is a necessary fix: the newly-added DW_OP_derefs cannot be lowered properly otherwise. Basically the fix prevents a direct SDDbgValue with DIExpression(DW_OP_deref) from being dereferenced twice by a debugger. There were a handful of tests relying on this incorrect "FRAMEIX => indirect" assumption which actually had incorrect DW_AT_locations: these are all fixed up in this patch. Testing: - check-llvm, and an end-to-end test using lldb to debug an optimized program. - Existing unit tests for DIExpression::appendToStack fully cover the new DIExpression::append utility. - check-debuginfo (the debug info integration tests) Differential Revision: https://reviews.llvm.org/D49454 llvm-svn: 338069
-rw-r--r--debuginfo-tests/asan-deque.cpp46
-rw-r--r--llvm/include/llvm/CodeGen/SelectionDAG.h4
-rw-r--r--llvm/include/llvm/IR/DebugInfoMetadata.h6
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp14
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h26
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp8
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp30
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp59
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp13
-rw-r--r--llvm/test/DebugInfo/AArch64/coalescing.ll5
-rw-r--r--llvm/test/DebugInfo/Mips/dsr-fixed-objects.ll5
-rw-r--r--llvm/test/DebugInfo/X86/bbjoin.ll2
-rw-r--r--llvm/test/DebugInfo/X86/dbg-value-const-byref.ll2
-rw-r--r--llvm/test/DebugInfo/X86/dbg-value-frame-index.ll8
-rw-r--r--llvm/test/DebugInfo/X86/debug-loc-frame.ll9
-rw-r--r--llvm/test/Transforms/InstCombine/lower-dbg-declare.ll183
-rw-r--r--llvm/unittests/IR/MetadataTest.cpp10
17 files changed, 359 insertions, 71 deletions
diff --git a/debuginfo-tests/asan-deque.cpp b/debuginfo-tests/asan-deque.cpp
new file mode 100644
index 00000000000..19183d6cc15
--- /dev/null
+++ b/debuginfo-tests/asan-deque.cpp
@@ -0,0 +1,46 @@
+// RUN: %clangxx -arch x86_64 %target_itanium_abi_host_triple -O1 -g %s -o %t.out -fsanitize=address
+// RUN: %test_debuginfo %s %t.out
+// REQUIRES: not_asan
+// Zorg configures the ASAN stage2 bots to not build the asan
+// compiler-rt. Only run this test on non-asanified configurations.
+
+#include <deque>
+
+struct A {
+ int a;
+ A(int a) : a(a) {}
+};
+
+using log_t = std::deque<A>;
+
+static void __attribute__((noinline, optnone)) escape(log_t &log) {
+ static volatile log_t *sink;
+ sink = &log;
+}
+
+int main() {
+ log_t log;
+ log.emplace_back(1234);
+ log.emplace_back(56789);
+ escape(log);
+ // DEBUGGER: break 25
+ while (!log.empty()) {
+ auto record = log.front();
+ log.pop_front();
+ escape(log);
+ // DEBUGGER: break 30
+ }
+}
+
+// DEBUGGER: r
+
+// (at line 25)
+// DEBUGGER: p log
+// CHECK: 1234
+// CHECK: 56789
+
+// DEBUGGER: c
+
+// (at line 30)
+// DEBUGGER: p log
+// CHECK: 56789
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index a7b6db64a0a..888f9425ff9 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -1250,8 +1250,8 @@ public:
/// Creates a FrameIndex SDDbgValue node.
SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr,
- unsigned FI, const DebugLoc &DL,
- unsigned O);
+ unsigned FI, bool IsIndirect,
+ const DebugLoc &DL, unsigned O);
/// Creates a VReg SDDbgValue node.
SDDbgValue *getVRegDbgValue(DIVariable *Var, DIExpression *Expr,
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 1743abc5398..82074685110 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2444,6 +2444,12 @@ public:
SmallVectorImpl<uint64_t> &Ops,
bool StackValue = false);
+ /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
+ /// returned expression is a stack value only if \p DIExpr is a stack value.
+ /// If \p DIExpr describes a fragment, the returned expression will describe
+ /// the same fragment.
+ static DIExpression *append(const DIExpression *Expr, ArrayRef<uint64_t> Ops);
+
/// Convert \p DIExpr into a stack value if it isn't one already by appending
/// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
/// If \p DIExpr describes a fragment, the returned expression will describe
diff --git a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
index 65ee3816f84..d6171f3177d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
@@ -697,11 +697,15 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,
if (SD->getKind() == SDDbgValue::FRAMEIX) {
// Stack address; this needs to be lowered in target-dependent fashion.
// EmitTargetCodeForFrameDebugValue is responsible for allocation.
- return BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE))
- .addFrameIndex(SD->getFrameIx())
- .addImm(0)
- .addMetadata(Var)
- .addMetadata(Expr);
+ auto FrameMI = BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE))
+ .addFrameIndex(SD->getFrameIx());
+ if (SD->isIndirect())
+ // Push [fi + 0] onto the DIExpression stack.
+ FrameMI.addImm(0);
+ else
+ // Push fi onto the DIExpression stack.
+ FrameMI.addReg(0);
+ return FrameMI.addMetadata(Var).addMetadata(Expr);
}
// Otherwise, we're going to create an instruction here.
const MCInstrDesc &II = TII->get(TargetOpcode::DBG_VALUE);
diff --git a/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h b/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h
index 703eaa453ab..7e6b5742633 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h
+++ b/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h
@@ -71,20 +71,18 @@ public:
u.Const = C;
}
- /// Constructor for frame indices.
- SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned FI, DebugLoc dl,
- unsigned O)
- : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
- kind = FRAMEIX;
- u.FrameIx = FI;
- }
-
- /// Constructor for virtual registers.
- SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VReg, bool indir,
- DebugLoc dl, unsigned O)
- : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
- kind = VREG;
- u.VReg = VReg;
+ /// Constructor for virtual registers and frame indices.
+ SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
+ bool IsIndirect, DebugLoc DL, unsigned Order,
+ enum DbgValueKind Kind)
+ : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
+ assert((Kind == VREG || Kind == FRAMEIX) &&
+ "Invalid SDDbgValue constructor");
+ kind = Kind;
+ if (kind == VREG)
+ u.VReg = VRegOrFrameIdx;
+ else
+ u.FrameIx = VRegOrFrameIdx;
}
/// Returns the kind.
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 9870f21666f..1f2c50a69d9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -7391,11 +7391,13 @@ SDDbgValue *SelectionDAG::getConstantDbgValue(DIVariable *Var,
/// FrameIndex
SDDbgValue *SelectionDAG::getFrameIndexDbgValue(DIVariable *Var,
DIExpression *Expr, unsigned FI,
+ bool IsIndirect,
const DebugLoc &DL,
unsigned O) {
assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
- return new (DbgInfo->getAlloc()) SDDbgValue(Var, Expr, FI, DL, O);
+ return new (DbgInfo->getAlloc())
+ SDDbgValue(Var, Expr, FI, IsIndirect, DL, O, SDDbgValue::FRAMEIX);
}
/// VReg
@@ -7405,8 +7407,8 @@ SDDbgValue *SelectionDAG::getVRegDbgValue(DIVariable *Var,
const DebugLoc &DL, unsigned O) {
assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
- return new (DbgInfo->getAlloc()) SDDbgValue(Var, Expr, VReg, IsIndirect, DL,
- O);
+ return new (DbgInfo->getAlloc())
+ SDDbgValue(Var, Expr, VReg, IsIndirect, DL, O, SDDbgValue::VREG);
}
void SelectionDAG::transferDbgValues(SDValue From, SDValue To,
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 12ce222075b..737bb1f9c9f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4973,13 +4973,20 @@ SDDbgValue *SelectionDAGBuilder::getDbgValue(SDValue N,
unsigned DbgSDNodeOrder) {
if (auto *FISDN = dyn_cast<FrameIndexSDNode>(N.getNode())) {
// Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can describe
- // stack slot locations as such instead of as indirectly addressed
- // locations.
- return DAG.getFrameIndexDbgValue(Variable, Expr, FISDN->getIndex(), dl,
- DbgSDNodeOrder);
+ // stack slot locations.
+ //
+ // Consider "int x = 0; int *px = &x;". There are two kinds of interesting
+ // debug values here after optimization:
+ //
+ // dbg.value(i32* %px, !"int *px", !DIExpression()), and
+ // dbg.value(i32* %px, !"int x", !DIExpression(DW_OP_deref))
+ //
+ // Both describe the direct values of their associated variables.
+ return DAG.getFrameIndexDbgValue(Variable, Expr, FISDN->getIndex(),
+ /*IsIndirect*/ false, dl, DbgSDNodeOrder);
}
- return DAG.getDbgValue(Variable, Expr, N.getNode(), N.getResNo(), false, dl,
- DbgSDNodeOrder);
+ return DAG.getDbgValue(Variable, Expr, N.getNode(), N.getResNo(),
+ /*IsIndirect*/ false, dl, DbgSDNodeOrder);
}
// VisualStudio defines setjmp as _setjmp
@@ -5191,9 +5198,9 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
// the MachineFunction variable table.
if (FI != std::numeric_limits<int>::max()) {
if (Intrinsic == Intrinsic::dbg_addr) {
- SDDbgValue *SDV = DAG.getFrameIndexDbgValue(Variable, Expression,
- FI, dl, SDNodeOrder);
- DAG.AddDbgValue(SDV, getRoot().getNode(), isParameter);
+ SDDbgValue *SDV = DAG.getFrameIndexDbgValue(
+ Variable, Expression, FI, /*IsIndirect*/ true, dl, SDNodeOrder);
+ DAG.AddDbgValue(SDV, getRoot().getNode(), isParameter);
}
return nullptr;
}
@@ -5210,8 +5217,9 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
auto FINode = dyn_cast<FrameIndexSDNode>(N.getNode());
if (isParameter && FINode) {
// Byval parameter. We have a frame index at this point.
- SDV = DAG.getFrameIndexDbgValue(Variable, Expression,
- FINode->getIndex(), dl, SDNodeOrder);
+ SDV =
+ DAG.getFrameIndexDbgValue(Variable, Expression, FINode->getIndex(),
+ /*IsIndirect*/ true, dl, SDNodeOrder);
} else if (isa<Argument>(Address)) {
// Address is an argument, so try to emit its dbg value using
// virtual register info from the FuncInfo.ValueMap.
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index db28d9a242b..910e8c2fb74 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -841,9 +841,37 @@ DIExpression *DIExpression::prependOpcodes(const DIExpression *Expr,
return DIExpression::get(Expr->getContext(), Ops);
}
+DIExpression *DIExpression::append(const DIExpression *Expr,
+ ArrayRef<uint64_t> Ops) {
+ assert(Expr && !Ops.empty() && "Can't append ops to this expression");
+
+ // Copy Expr's current op list.
+ SmallVector<uint64_t, 16> NewOps;
+ for (auto Op : Expr->expr_ops()) {
+ // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
+ if (Op.getOp() == dwarf::DW_OP_stack_value ||
+ Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
+ NewOps.append(Ops.begin(), Ops.end());
+
+ // Ensure that the new opcodes are only appended once.
+ Ops = None;
+ }
+ Op.appendToVector(NewOps);
+ }
+
+ NewOps.append(Ops.begin(), Ops.end());
+ return DIExpression::get(Expr->getContext(), NewOps);
+}
+
DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
ArrayRef<uint64_t> Ops) {
assert(Expr && !Ops.empty() && "Can't append ops to this expression");
+ assert(none_of(Ops,
+ [](uint64_t Op) {
+ return Op == dwarf::DW_OP_stack_value ||
+ Op == dwarf::DW_OP_LLVM_fragment;
+ }) &&
+ "Can't append this op");
// Append a DW_OP_deref after Expr's current op list if it's non-empty and
// has no DW_OP_stack_value.
@@ -851,30 +879,21 @@ DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
// Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
Optional<FragmentInfo> FI = Expr->getFragmentInfo();
unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
- bool NeedsDeref =
- (Expr->getNumElements() > DropUntilStackValue) &&
- (Expr->getElements().drop_back(DropUntilStackValue).back() !=
- dwarf::DW_OP_stack_value);
-
- // Copy Expr's current op list, add a DW_OP_deref if needed, and ensure that
- // a DW_OP_stack_value is present.
+ ArrayRef<uint64_t> ExprOpsBeforeFragment =
+ Expr->getElements().drop_back(DropUntilStackValue);
+ bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
+ (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
+ bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
+
+ // Append a DW_OP_deref after Expr's current op list if needed, then append
+ // the new ops, and finally ensure that a single DW_OP_stack_value is present.
SmallVector<uint64_t, 16> NewOps;
- for (auto Op : Expr->expr_ops()) {
- if (Op.getOp() == dwarf::DW_OP_stack_value ||
- Op.getOp() == dwarf::DW_OP_LLVM_fragment)
- break;
- Op.appendToVector(NewOps);
- }
if (NeedsDeref)
NewOps.push_back(dwarf::DW_OP_deref);
NewOps.append(Ops.begin(), Ops.end());
- NewOps.push_back(dwarf::DW_OP_stack_value);
-
- // If Expr is a fragment, make the new expression a fragment as well.
- if (FI)
- NewOps.append(
- {dwarf::DW_OP_LLVM_fragment, FI->OffsetInBits, FI->SizeInBits});
- return DIExpression::get(Expr->getContext(), NewOps);
+ if (NeedsStackValue)
+ NewOps.push_back(dwarf::DW_OP_stack_value);
+ return DIExpression::append(Expr, NewOps);
}
Optional<DIExpression *> DIExpression::createFragmentExpression(
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index a0e79b68e72..ae3cb077a3a 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1419,12 +1419,13 @@ bool llvm::LowerDbgDeclare(Function &F) {
} else if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
ConvertDebugDeclareToDebugValue(DDI, LI, DIB);
} else if (CallInst *CI = dyn_cast<CallInst>(U)) {
- // This is a call by-value or some other instruction that
- // takes a pointer to the variable. Insert a *value*
- // intrinsic that describes the alloca.
- DIB.insertDbgValueIntrinsic(AI, DDI->getVariable(),
- DDI->getExpression(), DDI->getDebugLoc(),
- CI);
+ // This is a call by-value or some other instruction that takes a
+ // pointer to the variable. Insert a *value* intrinsic that describes
+ // the variable by dereferencing the alloca.
+ auto *DerefExpr =
+ DIExpression::append(DDI->getExpression(), dwarf::DW_OP_deref);
+ DIB.insertDbgValueIntrinsic(AI, DDI->getVariable(), DerefExpr,
+ DDI->getDebugLoc(), CI);
}
}
DDI->eraseFromParent();
diff --git a/llvm/test/DebugInfo/AArch64/coalescing.ll b/llvm/test/DebugInfo/AArch64/coalescing.ll
index 0f65856fcb3..c39f8841948 100644
--- a/llvm/test/DebugInfo/AArch64/coalescing.ll
+++ b/llvm/test/DebugInfo/AArch64/coalescing.ll
@@ -20,10 +20,13 @@ entry:
%0 = bitcast i32* %size to i8*, !dbg !15
%call = call i8* @_Z3fooPv(i8* %0) #3, !dbg !15
call void @llvm.dbg.value(metadata i32* %size, metadata !10, metadata !16), !dbg !17
+
+ ; The *location* of the variable should be $sp+12. This tells the debugger to
+ ; look up its value in [$sp+12].
; CHECK: .debug_info contents:
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location
- ; CHECK-NEXT: DW_OP_breg31 WSP+12, DW_OP_deref
+ ; CHECK-NEXT: DW_OP_breg31 WSP+12
; CHECK-NEXT: DW_AT_name {{.*}}"size"
ret void, !dbg !18
}
diff --git a/llvm/test/DebugInfo/Mips/dsr-fixed-objects.ll b/llvm/test/DebugInfo/Mips/dsr-fixed-objects.ll
index 010186852ee..ebbe64a0c42 100644
--- a/llvm/test/DebugInfo/Mips/dsr-fixed-objects.ll
+++ b/llvm/test/DebugInfo/Mips/dsr-fixed-objects.ll
@@ -20,11 +20,12 @@ declare void @llvm.lifetime.end(i64, i8* nocapture)
declare void @foo(i32*)
+; CHECK: DW_AT_name {{.*}}"f0"
; CHECK: DW_AT_name {{.*}}"e"
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (
; CHECK-NEXT: [0x00000028, 0x0000002c): DW_OP_reg1 AT_64
-; CHECK-NEXT: [0x0000002c, 0x00000048): DW_OP_breg29 SP_64+16, DW_OP_deref)
+; CHECK-NEXT: [0x0000002c, 0x00000048): DW_OP_breg29 SP_64+16)
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000006b] = "x")
define i32 @f0(i32 signext %a, i32 signext %b, i32 signext %c, i32 signext %d, i32 signext %e) !dbg !4 {
@@ -55,7 +56,7 @@ entry:
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (
; CHECK-NEXT: [0x00000080, 0x00000084): DW_OP_reg1 AT_64
-; CHECK-NEXT: [0x00000084, 0x00000098): DW_OP_breg29 SP_64+16, DW_OP_deref)
+; CHECK-NEXT: [0x00000084, 0x00000098): DW_OP_breg29 SP_64+16)
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000006b] = "x")
define i32 @f1(i32 signext %a, i32 signext %b, i32 signext %c, i32 signext %d, i32 signext %e) !dbg !15 {
diff --git a/llvm/test/DebugInfo/X86/bbjoin.ll b/llvm/test/DebugInfo/X86/bbjoin.ll
index 02b6d416793..b3f20a9b8e3 100644
--- a/llvm/test/DebugInfo/X86/bbjoin.ll
+++ b/llvm/test/DebugInfo/X86/bbjoin.ll
@@ -12,7 +12,7 @@
; CHECK: ![[X:.*]] = !DILocalVariable(name: "x",
; CHECK: bb.0.entry:
; CHECK: DBG_VALUE 23, debug-use $noreg, ![[X]],
-; CHECK: DBG_VALUE debug-use $rsp, 0, ![[X]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_deref),
+; CHECK: DBG_VALUE debug-use $rsp, debug-use $noreg, ![[X]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_deref),
; CHECK: bb.1.if.then:
; CHECK: DBG_VALUE 43, debug-use $noreg, ![[X]],
; CHECK: bb.2.if.end:
diff --git a/llvm/test/DebugInfo/X86/dbg-value-const-byref.ll b/llvm/test/DebugInfo/X86/dbg-value-const-byref.ll
index 49d0ea2e82b..945c95f9913 100644
--- a/llvm/test/DebugInfo/X86/dbg-value-const-byref.ll
+++ b/llvm/test/DebugInfo/X86/dbg-value-const-byref.ll
@@ -25,7 +25,7 @@
; CHECK-NEXT: [0x{{0*.*}}, 0x[[C1:.*]]): DW_OP_consts +3
; CHECK-NEXT: [0x[[C1]], 0x[[C2:.*]]): DW_OP_consts +7
; CHECK-NEXT: [0x[[C2]], 0x[[R1:.*]]): DW_OP_reg0 RAX
-; CHECK-NEXT: [0x[[R1]], 0x[[R2:.*]]): DW_OP_breg7 RSP+4, DW_OP_deref)
+; CHECK-NEXT: [0x[[R1]], 0x[[R2:.*]]): DW_OP_breg7 RSP+4)
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name{{.*}}"i"
diff --git a/llvm/test/DebugInfo/X86/dbg-value-frame-index.ll b/llvm/test/DebugInfo/X86/dbg-value-frame-index.ll
index b411f20a550..a2cf2cc4e29 100644
--- a/llvm/test/DebugInfo/X86/dbg-value-frame-index.ll
+++ b/llvm/test/DebugInfo/X86/dbg-value-frame-index.ll
@@ -20,10 +20,14 @@ while.end:
}
; CHECK-LABEL: test
-; CHECK: #DEBUG_VALUE: test:w <- [DW_OP_plus_uconst 8] [$rsp+0]
+; To get the value of the variable, we need to do [$rsp+8], i.e:
+; CHECK: #DEBUG_VALUE: test:w <- [DW_OP_plus_uconst 8, DW_OP_deref] $rsp
; DWARF: DW_AT_location [DW_FORM_sec_offset] (
; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_breg7 RSP+8)
+; Note: A previous version of this test checked for `[DW_OP_plus_uconst 8] [$rsp+0]`,
+; which is incorrect, because it adds the stack offset after dereferencing the stack pointer.
+
declare i1 @fn(i64*, i64*, i64*, i8*, i64, i64*, i32*, i8*)
declare void @llvm.dbg.value(metadata, metadata, metadata)
@@ -36,7 +40,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = distinct !DISubprogram(name: "test", type: !10, unit: !0)
!5 = !DILocalVariable(name: "w", scope: !4, type: !9)
-!6 = !DIExpression()
+!6 = !DIExpression(DW_OP_deref)
!7 = !DILocation(line: 210, column: 12, scope: !4)
!8 = !{!9}
!9 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
diff --git a/llvm/test/DebugInfo/X86/debug-loc-frame.ll b/llvm/test/DebugInfo/X86/debug-loc-frame.ll
index 58b11857a45..f3bcfcb7377 100644
--- a/llvm/test/DebugInfo/X86/debug-loc-frame.ll
+++ b/llvm/test/DebugInfo/X86/debug-loc-frame.ll
@@ -28,7 +28,14 @@
; CHECK: DW_TAG_variable
; CHECK: DW_AT_location [DW_FORM_sec_offset] ({{.*}}
; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_reg0 RAX
-; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_breg7 RSP+4, DW_OP_deref)
+;
+; Note: This is a location, so we don't want an extra DW_OP_deref at the end.
+; LLDB gets the location right without it:
+; Variable: ... name = "val", type = "int", location = [rsp+4], decl = frame.c:10
+; Adding the deref actually creates an invalid location:
+; ... [rsp+4] DW_OP_deref
+;
+; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_breg7 RSP+4)
; CHECK-NEXT: DW_AT_name {{.*}}"val"
; ModuleID = 'frame.c'
diff --git a/llvm/test/Transforms/InstCombine/lower-dbg-declare.ll b/llvm/test/Transforms/InstCombine/lower-dbg-declare.ll
new file mode 100644
index 00000000000..44de3fc7531
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/lower-dbg-declare.ll
@@ -0,0 +1,183 @@
+; RUN: opt -instcombine < %s -S | FileCheck %s
+
+; This tests dbg.declare lowering for CallInst users of an alloca. The
+; resulting dbg.value expressions should add a deref to the declare's expression.
+
+; Hand-reduced from this example (-g -Og -fsanitize=address):
+
+; static volatile int sink;
+; struct OneElementVector {
+; int Element;
+; OneElementVector(int Element) : Element(Element) { sink = Element; }
+; bool empty() const { return false; }
+; };
+; using container = OneElementVector;
+; static void escape(container &c) { sink = c.Element; }
+; int main() {
+; container d1 = {42};
+; while (!d1.empty())
+; escape(d1);
+; return 0;
+; }
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.13.0"
+
+%struct.OneElementVector = type { i32 }
+
+define i1 @escape(%struct.OneElementVector* %d1) {
+ ret i1 false
+}
+
+; CHECK-LABEL: @main
+define i32 @main() !dbg !15 {
+entry:
+ %d1 = alloca %struct.OneElementVector, align 4
+ %0 = bitcast %struct.OneElementVector* %d1 to i8*, !dbg !34
+
+; CHECK: dbg.value(metadata %struct.OneElementVector* [[var:%.*]], metadata !DIExpression(DW_OP_deref))
+; CHECK-NEXT: call i1 @escape
+ call void @llvm.dbg.declare(metadata %struct.OneElementVector* %d1, metadata !19, metadata !DIExpression()), !dbg !35
+ call i1 @escape(%struct.OneElementVector* %d1)
+ br label %while.cond, !dbg !37
+
+while.cond: ; preds = %while.body, %entry
+; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_deref))
+; CHECK-NEXT: call i1 @escape
+ %call = call i1 @escape(%struct.OneElementVector* %d1), !dbg !38
+ %lnot = xor i1 %call, true, !dbg !39
+ br i1 %lnot, label %while.body, label %while.end, !dbg !37
+
+while.body: ; preds = %while.cond
+; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_deref))
+; CHECK-NEXT: call i1 @escape
+ call i1 @escape(%struct.OneElementVector* %d1)
+ br label %while.cond, !dbg !37, !llvm.loop !42
+
+while.end: ; preds = %while.cond
+ ret i32 0, !dbg !45
+}
+
+; CHECK-LABEL: @main2
+define i32 @main2() {
+entry:
+ %d1 = alloca %struct.OneElementVector, align 4
+ %0 = bitcast %struct.OneElementVector* %d1 to i8*, !dbg !34
+
+; CHECK: dbg.value(metadata %struct.OneElementVector* [[var:%.*]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref))
+; CHECK-NEXT: call i1 @escape
+ call void @llvm.dbg.declare(metadata %struct.OneElementVector* %d1, metadata !19, metadata !DIExpression(DW_OP_lit0, DW_OP_mul)), !dbg !35
+ call i1 @escape(%struct.OneElementVector* %d1)
+ br label %while.cond, !dbg !37
+
+while.cond: ; preds = %while.body, %entry
+; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref))
+; CHECK-NEXT: call i1 @escape
+ %call = call i1 @escape(%struct.OneElementVector* %d1), !dbg !38
+ %lnot = xor i1 %call, true, !dbg !39
+ br i1 %lnot, label %while.body, label %while.end, !dbg !37
+
+while.body: ; preds = %while.cond
+; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref))
+; CHECK-NEXT: call i1 @escape
+ call i1 @escape(%struct.OneElementVector* %d1)
+ br label %while.cond, !dbg !37, !llvm.loop !42
+
+while.end: ; preds = %while.cond
+ ret i32 0, !dbg !45
+}
+
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!2}
+!llvm.asan.globals = !{!8}
+!llvm.module.flags = !{!10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "sink", linkageName: "_ZL4sink", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (trunk 337207) (llvm/trunk 337204)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "test.cc", directory: "/Users/vsk/src/builds/llvm.org-master-RA")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7)
+!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!8 = !{}
+!9 = !{!"test.cc", i32 1, i32 21}
+!10 = !{i32 2, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{i32 7, !"PIC Level", i32 2}
+!14 = !{!"clang version 7.0.0 (trunk 337207) (llvm/trunk 337204)"}
+!15 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 18, type: !16, isLocal: false, isDefinition: true, scopeLine: 18, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !18)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!7}
+!18 = !{!19}
+!19 = !DILocalVariable(name: "d1", scope: !15, file: !3, line: 21, type: !20)
+!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "container", file: !3, line: 12, baseType: !21)
+!21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "OneElementVector", file: !3, line: 3, size: 32, flags: DIFlagTypePassByValue, elements: !22, identifier: "_ZTS16OneElementVector")
+!22 = !{!23, !24, !28}
+!23 = !DIDerivedType(tag: DW_TAG_member, name: "Element", scope: !21, file: !3, line: 4, baseType: !7, size: 32)
+!24 = !DISubprogram(name: "OneElementVector", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: false, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true)
+!25 = !DISubroutineType(types: !26)
+!26 = !{null, !27, !7}
+!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!28 = !DISubprogram(name: "empty", linkageName: "_ZNK16OneElementVector5emptyEv", scope: !21, file: !3, line: 8, type: !29, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true)
+!29 = !DISubroutineType(types: !30)
+!30 = !{!31, !32}
+!31 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
+!32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!33 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !21)
+!34 = !DILocation(line: 21, column: 3, scope: !15)
+!35 = !DILocation(line: 21, column: 13, scope: !15)
+!36 = !DILocation(line: 21, column: 18, scope: !15)
+!37 = !DILocation(line: 22, column: 3, scope: !15)
+!38 = !DILocation(line: 22, column: 14, scope: !15)
+!39 = !DILocation(line: 22, column: 10, scope: !15)
+!40 = !DILocation(line: 23, column: 5, scope: !41)
+!41 = distinct !DILexicalBlock(scope: !15, file: !3, line: 22, column: 23)
+!42 = distinct !{!42, !37, !43}
+!43 = !DILocation(line: 24, column: 3, scope: !15)
+!44 = !DILocation(line: 26, column: 1, scope: !15)
+!45 = !DILocation(line: 25, column: 3, scope: !15)
+!46 = distinct !DISubprogram(name: "OneElementVector", linkageName: "_ZN16OneElementVectorC1Ei", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !24, retainedNodes: !47)
+!47 = !{!48, !50}
+!48 = !DILocalVariable(name: "this", arg: 1, scope: !46, type: !49, flags: DIFlagArtificial | DIFlagObjectPointer)
+!49 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)
+!50 = !DILocalVariable(name: "Element", arg: 2, scope: !46, file: !3, line: 6, type: !7)
+!51 = !DILocation(line: 0, scope: !46)
+!52 = !DILocation(line: 6, column: 24, scope: !46)
+!53 = !DILocation(line: 6, column: 52, scope: !46)
+!54 = !DILocation(line: 6, column: 70, scope: !46)
+!55 = distinct !DISubprogram(name: "empty", linkageName: "_ZNK16OneElementVector5emptyEv", scope: !21, file: !3, line: 8, type: !29, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !28, retainedNodes: !56)
+!56 = !{!57}
+!57 = !DILocalVariable(name: "this", arg: 1, scope: !55, type: !58, flags: DIFlagArtificial | DIFlagObjectPointer)
+!58 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64)
+!59 = !DILocation(line: 0, scope: !55)
+!60 = !DILocation(line: 8, column: 24, scope: !55)
+!61 = distinct !DISubprogram(name: "escape", linkageName: "_ZL6escapeR16OneElementVector", scope: !3, file: !3, line: 14, type: !62, isLocal: true, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !65)
+!62 = !DISubroutineType(types: !63)
+!63 = !{null, !64}
+!64 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !20, size: 64)
+!65 = !{!66}
+!66 = !DILocalVariable(name: "c", arg: 1, scope: !61, file: !3, line: 14, type: !64)
+!67 = !DILocation(line: 14, column: 31, scope: !61)
+!68 = !DILocation(line: 15, column: 12, scope: !61)
+!69 = !{!70, !71, i64 0}
+!70 = !{!"_ZTS16OneElementVector", !71, i64 0}
+!71 = !{!"int", !72, i64 0}
+!72 = !{!"omnipotent char", !73, i64 0}
+!73 = !{!"Simple C++ TBAA"}
+!74 = !DILocation(line: 15, column: 8, scope: !61)
+!75 = !{!71, !71, i64 0}
+!76 = !DILocation(line: 16, column: 1, scope: !61)
+!77 = distinct !DISubprogram(name: "OneElementVector", linkageName: "_ZN16OneElementVectorC2Ei", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !24, retainedNodes: !78)
+!78 = !{!79, !80}
+!79 = !DILocalVariable(name: "this", arg: 1, scope: !77, type: !49, flags: DIFlagArtificial | DIFlagObjectPointer)
+!80 = !DILocalVariable(name: "Element", arg: 2, scope: !77, file: !3, line: 6, type: !7)
+!81 = !DILocation(line: 0, scope: !77)
+!82 = !DILocation(line: 6, column: 24, scope: !77)
+!83 = !DILocation(line: 6, column: 35, scope: !77)
+!84 = !DILocation(line: 6, column: 59, scope: !85)
+!85 = distinct !DILexicalBlock(scope: !77, file: !3, line: 6, column: 52)
+!86 = !DILocation(line: 6, column: 70, scope: !77)
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 12256bd2366..84a7b02fa98 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -2111,14 +2111,20 @@ TEST_F(DIExpressionTest, get) {
// Test DIExpression::prepend().
uint64_t Elts0[] = {dwarf::DW_OP_LLVM_fragment, 0, 32};
auto *N0 = DIExpression::get(Context, Elts0);
- N0 = DIExpression::prepend(N0, true, 64, true, true);
+ auto *N0WithPrependedOps = DIExpression::prepend(N0, true, 64, true, true);
uint64_t Elts1[] = {dwarf::DW_OP_deref,
dwarf::DW_OP_plus_uconst, 64,
dwarf::DW_OP_deref,
dwarf::DW_OP_stack_value,
dwarf::DW_OP_LLVM_fragment, 0, 32};
auto *N1 = DIExpression::get(Context, Elts1);
- EXPECT_EQ(N0, N1);
+ EXPECT_EQ(N0WithPrependedOps, N1);
+
+ // Test DIExpression::append().
+ uint64_t Elts2[] = {dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 64,
+ dwarf::DW_OP_deref, dwarf::DW_OP_stack_value};
+ auto *N2 = DIExpression::append(N0, Elts2);
+ EXPECT_EQ(N0WithPrependedOps, N2);
}
TEST_F(DIExpressionTest, isValid) {
OpenPOWER on IntegriCloud