llvm.org GIT mirror llvm / 081d211
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338069 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 1 year, 2 months ago
16 changed file(s) with 314 addition(s) and 72 deletion(s). Raw diff Collapse all Expand all
12491249
12501250 /// Creates a FrameIndex SDDbgValue node.
12511251 SDDbgValue *getFrameIndexDbgValue(DIVariable *Var, DIExpression *Expr,
1252 unsigned FI, const DebugLoc &DL,
1253 unsigned O);
1252 unsigned FI, bool IsIndirect,
1253 const DebugLoc &DL, unsigned O);
12541254
12551255 /// Creates a VReg SDDbgValue node.
12561256 SDDbgValue *getVRegDbgValue(DIVariable *Var, DIExpression *Expr,
24432443 SmallVectorImpl &Ops,
24442444 bool StackValue = false);
24452445
2446 /// Append the opcodes \p Ops to \p DIExpr. Unlike \ref appendToStack, the
2447 /// returned expression is a stack value only if \p DIExpr is a stack value.
2448 /// If \p DIExpr describes a fragment, the returned expression will describe
2449 /// the same fragment.
2450 static DIExpression *append(const DIExpression *Expr, ArrayRef Ops);
2451
24462452 /// Convert \p DIExpr into a stack value if it isn't one already by appending
24472453 /// DW_OP_deref if needed, and appending \p Ops to the resulting expression.
24482454 /// If \p DIExpr describes a fragment, the returned expression will describe
696696 if (SD->getKind() == SDDbgValue::FRAMEIX) {
697697 // Stack address; this needs to be lowered in target-dependent fashion.
698698 // EmitTargetCodeForFrameDebugValue is responsible for allocation.
699 return BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE))
700 .addFrameIndex(SD->getFrameIx())
701 .addImm(0)
702 .addMetadata(Var)
703 .addMetadata(Expr);
699 auto FrameMI = BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE))
700 .addFrameIndex(SD->getFrameIx());
701 if (SD->isIndirect())
702 // Push [fi + 0] onto the DIExpression stack.
703 FrameMI.addImm(0);
704 else
705 // Push fi onto the DIExpression stack.
706 FrameMI.addReg(0);
707 return FrameMI.addMetadata(Var).addMetadata(Expr);
704708 }
705709 // Otherwise, we're going to create an instruction here.
706710 const MCInstrDesc &II = TII->get(TargetOpcode::DBG_VALUE);
7070 u.Const = C;
7171 }
7272
73 /// Constructor for frame indices.
74 SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned FI, DebugLoc dl,
75 unsigned O)
76 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) {
77 kind = FRAMEIX;
78 u.FrameIx = FI;
79 }
80
81 /// Constructor for virtual registers.
82 SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VReg, bool indir,
83 DebugLoc dl, unsigned O)
84 : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) {
85 kind = VREG;
86 u.VReg = VReg;
73 /// Constructor for virtual registers and frame indices.
74 SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx,
75 bool IsIndirect, DebugLoc DL, unsigned Order,
76 enum DbgValueKind Kind)
77 : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) {
78 assert((Kind == VREG || Kind == FRAMEIX) &&
79 "Invalid SDDbgValue constructor");
80 kind = Kind;
81 if (kind == VREG)
82 u.VReg = VRegOrFrameIdx;
83 else
84 u.FrameIx = VRegOrFrameIdx;
8785 }
8886
8987 /// Returns the kind.
73907390 /// FrameIndex
73917391 SDDbgValue *SelectionDAG::getFrameIndexDbgValue(DIVariable *Var,
73927392 DIExpression *Expr, unsigned FI,
7393 bool IsIndirect,
73937394 const DebugLoc &DL,
73947395 unsigned O) {
73957396 assert(cast(Var)->isValidLocationForIntrinsic(DL) &&
73967397 "Expected inlined-at fields to agree");
7397 return new (DbgInfo->getAlloc()) SDDbgValue(Var, Expr, FI, DL, O);
7398 return new (DbgInfo->getAlloc())
7399 SDDbgValue(Var, Expr, FI, IsIndirect, DL, O, SDDbgValue::FRAMEIX);
73987400 }
73997401
74007402 /// VReg
74047406 const DebugLoc &DL, unsigned O) {
74057407 assert(cast(Var)->isValidLocationForIntrinsic(DL) &&
74067408 "Expected inlined-at fields to agree");
7407 return new (DbgInfo->getAlloc()) SDDbgValue(Var, Expr, VReg, IsIndirect, DL,
7408 O);
7409 return new (DbgInfo->getAlloc())
7410 SDDbgValue(Var, Expr, VReg, IsIndirect, DL, O, SDDbgValue::VREG);
74097411 }
74107412
74117413 void SelectionDAG::transferDbgValues(SDValue From, SDValue To,
49724972 unsigned DbgSDNodeOrder) {
49734973 if (auto *FISDN = dyn_cast(N.getNode())) {
49744974 // Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can describe
4975 // stack slot locations as such instead of as indirectly addressed
4976 // locations.
4977 return DAG.getFrameIndexDbgValue(Variable, Expr, FISDN->getIndex(), dl,
4978 DbgSDNodeOrder);
4979 }
4980 return DAG.getDbgValue(Variable, Expr, N.getNode(), N.getResNo(), false, dl,
4981 DbgSDNodeOrder);
4975 // stack slot locations.
4976 //
4977 // Consider "int x = 0; int *px = &x;". There are two kinds of interesting
4978 // debug values here after optimization:
4979 //
4980 // dbg.value(i32* %px, !"int *px", !DIExpression()), and
4981 // dbg.value(i32* %px, !"int x", !DIExpression(DW_OP_deref))
4982 //
4983 // Both describe the direct values of their associated variables.
4984 return DAG.getFrameIndexDbgValue(Variable, Expr, FISDN->getIndex(),
4985 /*IsIndirect*/ false, dl, DbgSDNodeOrder);
4986 }
4987 return DAG.getDbgValue(Variable, Expr, N.getNode(), N.getResNo(),
4988 /*IsIndirect*/ false, dl, DbgSDNodeOrder);
49824989 }
49834990
49844991 // VisualStudio defines setjmp as _setjmp
51905197 // the MachineFunction variable table.
51915198 if (FI != std::numeric_limits::max()) {
51925199 if (Intrinsic == Intrinsic::dbg_addr) {
5193 SDDbgValue *SDV = DAG.getFrameIndexDbgValue(Variable, Expression,
5194 FI, dl, SDNodeOrder);
5195 DAG.AddDbgValue(SDV, getRoot().getNode(), isParameter);
5200 SDDbgValue *SDV = DAG.getFrameIndexDbgValue(
5201 Variable, Expression, FI, /*IsIndirect*/ true, dl, SDNodeOrder);
5202 DAG.AddDbgValue(SDV, getRoot().getNode(), isParameter);
51965203 }
51975204 return nullptr;
51985205 }
52095216 auto FINode = dyn_cast(N.getNode());
52105217 if (isParameter && FINode) {
52115218 // Byval parameter. We have a frame index at this point.
5212 SDV = DAG.getFrameIndexDbgValue(Variable, Expression,
5213 FINode->getIndex(), dl, SDNodeOrder);
5219 SDV =
5220 DAG.getFrameIndexDbgValue(Variable, Expression, FINode->getIndex(),
5221 /*IsIndirect*/ true, dl, SDNodeOrder);
52145222 } else if (isa(Address)) {
52155223 // Address is an argument, so try to emit its dbg value using
52165224 // virtual register info from the FuncInfo.ValueMap.
840840 return DIExpression::get(Expr->getContext(), Ops);
841841 }
842842
843 DIExpression *DIExpression::append(const DIExpression *Expr,
844 ArrayRef Ops) {
845 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
846
847 // Copy Expr's current op list.
848 SmallVector NewOps;
849 for (auto Op : Expr->expr_ops()) {
850 // Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
851 if (Op.getOp() == dwarf::DW_OP_stack_value ||
852 Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
853 NewOps.append(Ops.begin(), Ops.end());
854
855 // Ensure that the new opcodes are only appended once.
856 Ops = None;
857 }
858 Op.appendToVector(NewOps);
859 }
860
861 NewOps.append(Ops.begin(), Ops.end());
862 return DIExpression::get(Expr->getContext(), NewOps);
863 }
864
843865 DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
844866 ArrayRef Ops) {
845867 assert(Expr && !Ops.empty() && "Can't append ops to this expression");
868 assert(none_of(Ops,
869 [](uint64_t Op) {
870 return Op == dwarf::DW_OP_stack_value ||
871 Op == dwarf::DW_OP_LLVM_fragment;
872 }) &&
873 "Can't append this op");
846874
847875 // Append a DW_OP_deref after Expr's current op list if it's non-empty and
848876 // has no DW_OP_stack_value.
850878 // Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
851879 Optional FI = Expr->getFragmentInfo();
852880 unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
853 bool NeedsDeref =
854 (Expr->getNumElements() > DropUntilStackValue) &&
855 (Expr->getElements().drop_back(DropUntilStackValue).back() !=
856 dwarf::DW_OP_stack_value);
857
858 // Copy Expr's current op list, add a DW_OP_deref if needed, and ensure that
859 // a DW_OP_stack_value is present.
881 ArrayRef ExprOpsBeforeFragment =
882 Expr->getElements().drop_back(DropUntilStackValue);
883 bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
884 (ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
885 bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
886
887 // Append a DW_OP_deref after Expr's current op list if needed, then append
888 // the new ops, and finally ensure that a single DW_OP_stack_value is present.
860889 SmallVector NewOps;
861 for (auto Op : Expr->expr_ops()) {
862 if (Op.getOp() == dwarf::DW_OP_stack_value ||
863 Op.getOp() == dwarf::DW_OP_LLVM_fragment)
864 break;
865 Op.appendToVector(NewOps);
866 }
867890 if (NeedsDeref)
868891 NewOps.push_back(dwarf::DW_OP_deref);
869892 NewOps.append(Ops.begin(), Ops.end());
870 NewOps.push_back(dwarf::DW_OP_stack_value);
871
872 // If Expr is a fragment, make the new expression a fragment as well.
873 if (FI)
874 NewOps.append(
875 {dwarf::DW_OP_LLVM_fragment, FI->OffsetInBits, FI->SizeInBits});
876 return DIExpression::get(Expr->getContext(), NewOps);
893 if (NeedsStackValue)
894 NewOps.push_back(dwarf::DW_OP_stack_value);
895 return DIExpression::append(Expr, NewOps);
877896 }
878897
879898 Optional DIExpression::createFragmentExpression(
14181418 } else if (LoadInst *LI = dyn_cast(U)) {
14191419 ConvertDebugDeclareToDebugValue(DDI, LI, DIB);
14201420 } else if (CallInst *CI = dyn_cast(U)) {
1421 // This is a call by-value or some other instruction that
1422 // takes a pointer to the variable. Insert a *value*
1423 // intrinsic that describes the alloca.
1424 DIB.insertDbgValueIntrinsic(AI, DDI->getVariable(),
1425 DDI->getExpression(), DDI->getDebugLoc(),
1426 CI);
1421 // This is a call by-value or some other instruction that takes a
1422 // pointer to the variable. Insert a *value* intrinsic that describes
1423 // the variable by dereferencing the alloca.
1424 auto *DerefExpr =
1425 DIExpression::append(DDI->getExpression(), dwarf::DW_OP_deref);
1426 DIB.insertDbgValueIntrinsic(AI, DDI->getVariable(), DerefExpr,
1427 DDI->getDebugLoc(), CI);
14271428 }
14281429 }
14291430 DDI->eraseFromParent();
1919 %0 = bitcast i32* %size to i8*, !dbg !15
2020 %call = call i8* @_Z3fooPv(i8* %0) #3, !dbg !15
2121 call void @llvm.dbg.value(metadata i32* %size, metadata !10, metadata !16), !dbg !17
22
23 ; The *location* of the variable should be $sp+12. This tells the debugger to
24 ; look up its value in [$sp+12].
2225 ; CHECK: .debug_info contents:
2326 ; CHECK: DW_TAG_variable
2427 ; CHECK-NEXT: DW_AT_location
25 ; CHECK-NEXT: DW_OP_breg31 WSP+12, DW_OP_deref
28 ; CHECK-NEXT: DW_OP_breg31 WSP+12
2629 ; CHECK-NEXT: DW_AT_name {{.*}}"size"
2730 ret void, !dbg !18
2831 }
1919
2020 declare void @foo(i32*)
2121
22 ; CHECK: DW_AT_name {{.*}}"f0"
2223 ; CHECK: DW_AT_name {{.*}}"e"
2324 ; CHECK: DW_TAG_variable
2425 ; CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (
2526 ; CHECK-NEXT: [0x00000028, 0x0000002c): DW_OP_reg1 AT_64
26 ; CHECK-NEXT: [0x0000002c, 0x00000048): DW_OP_breg29 SP_64+16, DW_OP_deref)
27 ; CHECK-NEXT: [0x0000002c, 0x00000048): DW_OP_breg29 SP_64+16)
2728 ; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000006b] = "x")
2829
2930 define i32 @f0(i32 signext %a, i32 signext %b, i32 signext %c, i32 signext %d, i32 signext %e) !dbg !4 {
5455 ; CHECK: DW_TAG_variable
5556 ; CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (
5657 ; CHECK-NEXT: [0x00000080, 0x00000084): DW_OP_reg1 AT_64
57 ; CHECK-NEXT: [0x00000084, 0x00000098): DW_OP_breg29 SP_64+16, DW_OP_deref)
58 ; CHECK-NEXT: [0x00000084, 0x00000098): DW_OP_breg29 SP_64+16)
5859 ; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000006b] = "x")
5960
6061 define i32 @f1(i32 signext %a, i32 signext %b, i32 signext %c, i32 signext %d, i32 signext %e) !dbg !15 {
1111 ; CHECK: ![[X:.*]] = !DILocalVariable(name: "x",
1212 ; CHECK: bb.0.entry:
1313 ; CHECK: DBG_VALUE 23, debug-use $noreg, ![[X]],
14 ; CHECK: DBG_VALUE debug-use $rsp, 0, ![[X]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_deref),
14 ; CHECK: DBG_VALUE debug-use $rsp, debug-use $noreg, ![[X]], !DIExpression(DW_OP_plus_uconst, 4, DW_OP_deref),
1515 ; CHECK: bb.1.if.then:
1616 ; CHECK: DBG_VALUE 43, debug-use $noreg, ![[X]],
1717 ; CHECK: bb.2.if.end:
2424 ; CHECK-NEXT: [0x{{0*.*}}, 0x[[C1:.*]]): DW_OP_consts +3
2525 ; CHECK-NEXT: [0x[[C1]], 0x[[C2:.*]]): DW_OP_consts +7
2626 ; CHECK-NEXT: [0x[[C2]], 0x[[R1:.*]]): DW_OP_reg0 RAX
27 ; CHECK-NEXT: [0x[[R1]], 0x[[R2:.*]]): DW_OP_breg7 RSP+4, DW_OP_deref)
27 ; CHECK-NEXT: [0x[[R1]], 0x[[R2:.*]]): DW_OP_breg7 RSP+4)
2828 ; CHECK-NOT: DW_TAG
2929 ; CHECK: DW_AT_name{{.*}}"i"
3030
1919 }
2020
2121 ; CHECK-LABEL: test
22 ; CHECK: #DEBUG_VALUE: test:w <- [DW_OP_plus_uconst 8] [$rsp+0]
22 ; To get the value of the variable, we need to do [$rsp+8], i.e:
23 ; CHECK: #DEBUG_VALUE: test:w <- [DW_OP_plus_uconst 8, DW_OP_deref] $rsp
2324 ; DWARF: DW_AT_location [DW_FORM_sec_offset] (
2425 ; DWARF-NEXT: [{{.*}}, {{.*}}): DW_OP_breg7 RSP+8)
26
27 ; Note: A previous version of this test checked for `[DW_OP_plus_uconst 8] [$rsp+0]`,
28 ; which is incorrect, because it adds the stack offset after dereferencing the stack pointer.
2529
2630 declare i1 @fn(i64*, i64*, i64*, i8*, i64, i64*, i32*, i8*)
2731 declare void @llvm.dbg.value(metadata, metadata, metadata)
3539 !3 = !{i32 2, !"Debug Info Version", i32 3}
3640 !4 = distinct !DISubprogram(name: "test", type: !10, unit: !0)
3741 !5 = !DILocalVariable(name: "w", scope: !4, type: !9)
38 !6 = !DIExpression()
42 !6 = !DIExpression(DW_OP_deref)
3943 !7 = !DILocation(line: 210, column: 12, scope: !4)
4044 !8 = !{!9}
4145 !9 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
2727 ; CHECK: DW_TAG_variable
2828 ; CHECK: DW_AT_location [DW_FORM_sec_offset] ({{.*}}
2929 ; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_reg0 RAX
30 ; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_breg7 RSP+4, DW_OP_deref)
30 ;
31 ; Note: This is a location, so we don't want an extra DW_OP_deref at the end.
32 ; LLDB gets the location right without it:
33 ; Variable: ... name = "val", type = "int", location = [rsp+4], decl = frame.c:10
34 ; Adding the deref actually creates an invalid location:
35 ; ... [rsp+4] DW_OP_deref
36 ;
37 ; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_breg7 RSP+4)
3138 ; CHECK-NEXT: DW_AT_name {{.*}}"val"
3239
3340 ; ModuleID = 'frame.c'
0 ; RUN: opt -instcombine < %s -S | FileCheck %s
1
2 ; This tests dbg.declare lowering for CallInst users of an alloca. The
3 ; resulting dbg.value expressions should add a deref to the declare's expression.
4
5 ; Hand-reduced from this example (-g -Og -fsanitize=address):
6
7 ; static volatile int sink;
8 ; struct OneElementVector {
9 ; int Element;
10 ; OneElementVector(int Element) : Element(Element) { sink = Element; }
11 ; bool empty() const { return false; }
12 ; };
13 ; using container = OneElementVector;
14 ; static void escape(container &c) { sink = c.Element; }
15 ; int main() {
16 ; container d1 = {42};
17 ; while (!d1.empty())
18 ; escape(d1);
19 ; return 0;
20 ; }
21
22 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-apple-macosx10.13.0"
24
25 %struct.OneElementVector = type { i32 }
26
27 define i1 @escape(%struct.OneElementVector* %d1) {
28 ret i1 false
29 }
30
31 ; CHECK-LABEL: @main
32 define i32 @main() !dbg !15 {
33 entry:
34 %d1 = alloca %struct.OneElementVector, align 4
35 %0 = bitcast %struct.OneElementVector* %d1 to i8*, !dbg !34
36
37 ; CHECK: dbg.value(metadata %struct.OneElementVector* [[var:%.*]], metadata !DIExpression(DW_OP_deref))
38 ; CHECK-NEXT: call i1 @escape
39 call void @llvm.dbg.declare(metadata %struct.OneElementVector* %d1, metadata !19, metadata !DIExpression()), !dbg !35
40 call i1 @escape(%struct.OneElementVector* %d1)
41 br label %while.cond, !dbg !37
42
43 while.cond: ; preds = %while.body, %entry
44 ; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_deref))
45 ; CHECK-NEXT: call i1 @escape
46 %call = call i1 @escape(%struct.OneElementVector* %d1), !dbg !38
47 %lnot = xor i1 %call, true, !dbg !39
48 br i1 %lnot, label %while.body, label %while.end, !dbg !37
49
50 while.body: ; preds = %while.cond
51 ; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_deref))
52 ; CHECK-NEXT: call i1 @escape
53 call i1 @escape(%struct.OneElementVector* %d1)
54 br label %while.cond, !dbg !37, !llvm.loop !42
55
56 while.end: ; preds = %while.cond
57 ret i32 0, !dbg !45
58 }
59
60 ; CHECK-LABEL: @main2
61 define i32 @main2() {
62 entry:
63 %d1 = alloca %struct.OneElementVector, align 4
64 %0 = bitcast %struct.OneElementVector* %d1 to i8*, !dbg !34
65
66 ; CHECK: dbg.value(metadata %struct.OneElementVector* [[var:%.*]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref))
67 ; CHECK-NEXT: call i1 @escape
68 call void @llvm.dbg.declare(metadata %struct.OneElementVector* %d1, metadata !19, metadata !DIExpression(DW_OP_lit0, DW_OP_mul)), !dbg !35
69 call i1 @escape(%struct.OneElementVector* %d1)
70 br label %while.cond, !dbg !37
71
72 while.cond: ; preds = %while.body, %entry
73 ; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref))
74 ; CHECK-NEXT: call i1 @escape
75 %call = call i1 @escape(%struct.OneElementVector* %d1), !dbg !38
76 %lnot = xor i1 %call, true, !dbg !39
77 br i1 %lnot, label %while.body, label %while.end, !dbg !37
78
79 while.body: ; preds = %while.cond
80 ; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref))
81 ; CHECK-NEXT: call i1 @escape
82 call i1 @escape(%struct.OneElementVector* %d1)
83 br label %while.cond, !dbg !37, !llvm.loop !42
84
85 while.end: ; preds = %while.cond
86 ret i32 0, !dbg !45
87 }
88
89 declare void @llvm.dbg.declare(metadata, metadata, metadata)
90
91 !llvm.dbg.cu = !{!2}
92 !llvm.asan.globals = !{!8}
93 !llvm.module.flags = !{!10, !11, !12, !13}
94 !llvm.ident = !{!14}
95
96 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
97 !1 = distinct !DIGlobalVariable(name: "sink", linkageName: "_ZL4sink", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true)
98 !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)
99 !3 = !DIFile(filename: "test.cc", directory: "/Users/vsk/src/builds/llvm.org-master-RA")
100 !4 = !{}
101 !5 = !{!0}
102 !6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7)
103 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
104 !8 = !{}
105 !9 = !{!"test.cc", i32 1, i32 21}
106 !10 = !{i32 2, !"Dwarf Version", i32 4}
107 !11 = !{i32 2, !"Debug Info Version", i32 3}
108 !12 = !{i32 1, !"wchar_size", i32 4}
109 !13 = !{i32 7, !"PIC Level", i32 2}
110 !14 = !{!"clang version 7.0.0 (trunk 337207) (llvm/trunk 337204)"}
111 !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)
112 !16 = !DISubroutineType(types: !17)
113 !17 = !{!7}
114 !18 = !{!19}
115 !19 = !DILocalVariable(name: "d1", scope: !15, file: !3, line: 21, type: !20)
116 !20 = !DIDerivedType(tag: DW_TAG_typedef, name: "container", file: !3, line: 12, baseType: !21)
117 !21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "OneElementVector", file: !3, line: 3, size: 32, flags: DIFlagTypePassByValue, elements: !22, identifier: "_ZTS16OneElementVector")
118 !22 = !{!23, !24, !28}
119 !23 = !DIDerivedType(tag: DW_TAG_member, name: "Element", scope: !21, file: !3, line: 4, baseType: !7, size: 32)
120 !24 = !DISubprogram(name: "OneElementVector", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: false, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true)
121 !25 = !DISubroutineType(types: !26)
122 !26 = !{null, !27, !7}
123 !27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
124 !28 = !DISubprogram(name: "empty", linkageName: "_ZNK16OneElementVector5emptyEv", scope: !21, file: !3, line: 8, type: !29, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true)
125 !29 = !DISubroutineType(types: !30)
126 !30 = !{!31, !32}
127 !31 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
128 !32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
129 !33 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !21)
130 !34 = !DILocation(line: 21, column: 3, scope: !15)
131 !35 = !DILocation(line: 21, column: 13, scope: !15)
132 !36 = !DILocation(line: 21, column: 18, scope: !15)
133 !37 = !DILocation(line: 22, column: 3, scope: !15)
134 !38 = !DILocation(line: 22, column: 14, scope: !15)
135 !39 = !DILocation(line: 22, column: 10, scope: !15)
136 !40 = !DILocation(line: 23, column: 5, scope: !41)
137 !41 = distinct !DILexicalBlock(scope: !15, file: !3, line: 22, column: 23)
138 !42 = distinct !{!42, !37, !43}
139 !43 = !DILocation(line: 24, column: 3, scope: !15)
140 !44 = !DILocation(line: 26, column: 1, scope: !15)
141 !45 = !DILocation(line: 25, column: 3, scope: !15)
142 !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)
143 !47 = !{!48, !50}
144 !48 = !DILocalVariable(name: "this", arg: 1, scope: !46, type: !49, flags: DIFlagArtificial | DIFlagObjectPointer)
145 !49 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)
146 !50 = !DILocalVariable(name: "Element", arg: 2, scope: !46, file: !3, line: 6, type: !7)
147 !51 = !DILocation(line: 0, scope: !46)
148 !52 = !DILocation(line: 6, column: 24, scope: !46)
149 !53 = !DILocation(line: 6, column: 52, scope: !46)
150 !54 = !DILocation(line: 6, column: 70, scope: !46)
151 !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)
152 !56 = !{!57}
153 !57 = !DILocalVariable(name: "this", arg: 1, scope: !55, type: !58, flags: DIFlagArtificial | DIFlagObjectPointer)
154 !58 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64)
155 !59 = !DILocation(line: 0, scope: !55)
156 !60 = !DILocation(line: 8, column: 24, scope: !55)
157 !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)
158 !62 = !DISubroutineType(types: !63)
159 !63 = !{null, !64}
160 !64 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !20, size: 64)
161 !65 = !{!66}
162 !66 = !DILocalVariable(name: "c", arg: 1, scope: !61, file: !3, line: 14, type: !64)
163 !67 = !DILocation(line: 14, column: 31, scope: !61)
164 !68 = !DILocation(line: 15, column: 12, scope: !61)
165 !69 = !{!70, !71, i64 0}
166 !70 = !{!"_ZTS16OneElementVector", !71, i64 0}
167 !71 = !{!"int", !72, i64 0}
168 !72 = !{!"omnipotent char", !73, i64 0}
169 !73 = !{!"Simple C++ TBAA"}
170 !74 = !DILocation(line: 15, column: 8, scope: !61)
171 !75 = !{!71, !71, i64 0}
172 !76 = !DILocation(line: 16, column: 1, scope: !61)
173 !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)
174 !78 = !{!79, !80}
175 !79 = !DILocalVariable(name: "this", arg: 1, scope: !77, type: !49, flags: DIFlagArtificial | DIFlagObjectPointer)
176 !80 = !DILocalVariable(name: "Element", arg: 2, scope: !77, file: !3, line: 6, type: !7)
177 !81 = !DILocation(line: 0, scope: !77)
178 !82 = !DILocation(line: 6, column: 24, scope: !77)
179 !83 = !DILocation(line: 6, column: 35, scope: !77)
180 !84 = !DILocation(line: 6, column: 59, scope: !85)
181 !85 = distinct !DILexicalBlock(scope: !77, file: !3, line: 6, column: 52)
182 !86 = !DILocation(line: 6, column: 70, scope: !77)
21102110 // Test DIExpression::prepend().
21112111 uint64_t Elts0[] = {dwarf::DW_OP_LLVM_fragment, 0, 32};
21122112 auto *N0 = DIExpression::get(Context, Elts0);
2113 N0 = DIExpression::prepend(N0, true, 64, true, true);
2113 auto *N0WithPrependedOps = DIExpression::prepend(N0, true, 64, true, true);
21142114 uint64_t Elts1[] = {dwarf::DW_OP_deref,
21152115 dwarf::DW_OP_plus_uconst, 64,
21162116 dwarf::DW_OP_deref,
21172117 dwarf::DW_OP_stack_value,
21182118 dwarf::DW_OP_LLVM_fragment, 0, 32};
21192119 auto *N1 = DIExpression::get(Context, Elts1);
2120 EXPECT_EQ(N0, N1);
2120 EXPECT_EQ(N0WithPrependedOps, N1);
2121
2122 // Test DIExpression::append().
2123 uint64_t Elts2[] = {dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 64,
2124 dwarf::DW_OP_deref, dwarf::DW_OP_stack_value};
2125 auto *N2 = DIExpression::append(N0, Elts2);
2126 EXPECT_EQ(N0WithPrependedOps, N2);
21212127 }
21222128
21232129 TEST_F(DIExpressionTest, isValid) {