1; RUN: llc %s -stop-before finalize-isel -o - \ 2; RUN: -experimental-debug-variable-locations=false \ 3; RUN: -debug-ata-coalesce-frags=true \ 4; RUN: | FileCheck %s --implicit-check-not=DBG_ 5 6; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before finalize-isel -o - \ 7; RUN: -experimental-debug-variable-locations=false \ 8; RUN: -debug-ata-coalesce-frags=true \ 9; RUN: | FileCheck %s --implicit-check-not=DBG_ 10; RUN: llc %s -stop-before finalize-isel -o - \ 11; RUN: -experimental-debug-variable-locations=true \ 12; RUN: | FileCheck %s --implicit-check-not=DBG_ 13 14 15; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before finalize-isel -o - \ 16; RUN: -experimental-debug-variable-locations=true \ 17; RUN: | FileCheck %s --implicit-check-not=DBG_ 18 19;; Check that the mem-loc-frag-fill pseudo-pass works on a simple CFG. When 20;; LLVM sees a dbg.value with an overlapping fragment it essentially considers 21;; the previous location as valid for all bits in that fragment. The pass 22;; tracks which bits are in memory and inserts dbg.values preserve memory 23;; locations for bits in memory when overlapping fragments are encountered. 24 25;; nums lives in mem, except prior to the second call to step() where there has 26;; been some DSE. At this point, the memory loc for nums.c is invalid. But the 27;; rest of num's bits, [0, 64), are in memory, so check there's a dbg.value for 28;; them. 29 30;; $ cat test.cpp 31;; struct Nums { int a, b, c; }; 32;; 33;; void esc1(struct Nums*); 34;; void esc2(struct Nums*); 35;; bool step(); 36;; 37;; int main() { 38;; struct Nums nums = { 1, 2, 1 }; 39;; if (step()) 40;; esc1(&nums); 41;; else 42;; esc2(&nums); 43;; 44;; nums.c = 2; //< Include some DSE to force a non-mem location. 45;; step(); 46;; 47;; nums.c = nums.a; 48;; 49;; esc1(&nums); 50;; return 0; 51;; } 52;; 53;; $ clang++ test.cpp -O2 -g -Xclang -fexperimental-assignment-tracking -emit-llvm -S -o - 54 55;; Most check lines are inline in main. 56; CHECK: ![[nums:[0-9]+]] = !DILocalVariable(name: "nums", 57 58target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 59target triple = "x86_64-unknown-linux-gnu" 60 61%struct.Nums = type { i32, i32, i32 } 62 63@__const.main.nums = private unnamed_addr constant %struct.Nums { i32 1, i32 2, i32 1 }, align 4 64 65declare void @_Z4esc1P4Nums(ptr nocapture noundef readonly %p) 66declare void @_Z4esc2P4Nums(ptr nocapture noundef readonly %p) 67 68; Function Attrs: mustprogress norecurse uwtable 69define dso_local noundef i32 @main() local_unnamed_addr #3 !dbg !40 { 70; CHECK: name: main 71entry: 72 %nums = alloca %struct.Nums, align 4, !DIAssignID !45 73 call void @llvm.dbg.assign(metadata i1 undef, metadata !44, metadata !DIExpression(), metadata !45, metadata ptr %nums, metadata !DIExpression()), !dbg !46 74; CHECK: DBG_VALUE %stack.0.nums, $noreg, ![[nums]], !DIExpression(DW_OP_deref) 75 call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %nums, ptr noundef nonnull align 4 dereferenceable(12) %nums, i64 12, i1 false), !dbg !48, !DIAssignID !49 76 call void @llvm.dbg.assign(metadata i1 undef, metadata !44, metadata !DIExpression(), metadata !49, metadata ptr %nums, metadata !DIExpression()), !dbg !46 77 %call = tail call noundef zeroext i1 @_Z4stepv(), !dbg !50 78 br i1 %call, label %if.then, label %if.else, !dbg !52 79 80if.then: ; preds = %entry 81 call void @_Z4esc1P4Nums(ptr noundef nonnull %nums), !dbg !53 82 br label %if.end, !dbg !53 83 84if.else: ; preds = %entry 85 call void @_Z4esc2P4Nums(ptr noundef nonnull %nums), !dbg !54 86 br label %if.end 87 88if.end: ; preds = %if.else, %if.then 89; CHECK: bb.3.if.end: 90; CHECK-NEXT: DBG_VALUE 2, $noreg, ![[nums]], !DIExpression(DW_OP_LLVM_fragment, 64, 32), debug-location 91; CHECK-NEXT: DBG_VALUE %stack.0.nums, $noreg, ![[nums]], !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 0, 64) 92 %c = getelementptr inbounds %struct.Nums, ptr %nums, i64 0, i32 2, !dbg !55 93 call void @llvm.dbg.assign(metadata i32 2, metadata !44, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 32), metadata !56, metadata ptr %c, metadata !DIExpression()), !dbg !46 94 %call1 = tail call noundef zeroext i1 @_Z4stepv(), !dbg !57 95 store i32 1, ptr %c, align 4, !dbg !58, !DIAssignID !61 96;; Store to bits 64 to 96 - the whole variable is in memory again. 97; CHECK: MOV32mi %stack.0.nums, 1, $noreg, 8, $noreg, 1 98; CHECK-NEXT: DBG_VALUE %stack.0.nums, $noreg, ![[nums]], !DIExpression(DW_OP_deref) 99 call void @llvm.dbg.assign(metadata i32 1, metadata !44, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 32), metadata !61, metadata ptr %c, metadata !DIExpression()), !dbg !46 100 call void @_Z4esc1P4Nums(ptr noundef nonnull %nums), !dbg !62 101 ret i32 0, !dbg !64 102} 103 104declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #4 105declare !dbg !65 dso_local noundef zeroext i1 @_Z4stepv() local_unnamed_addr #5 106declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #4 107declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1 108declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2 109 110!llvm.dbg.cu = !{!2} 111!llvm.module.flags = !{!11, !12, !13, !14, !1000} 112!llvm.ident = !{!15} 113 114!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 115!1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !3, line: 2, type: !5, isLocal: false, isDefinition: true) 116!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) 117!3 = !DIFile(filename: "test.cpp", directory: "/") 118!4 = !{!0} 119!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nums", file: !3, line: 1, size: 96, flags: DIFlagTypePassByValue, elements: !6, identifier: "_ZTS4Nums") 120!6 = !{!7, !9, !10} 121!7 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !3, line: 1, baseType: !8, size: 32) 122!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 123!9 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !5, file: !3, line: 1, baseType: !8, size: 32, offset: 32) 124!10 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !5, file: !3, line: 1, baseType: !8, size: 32, offset: 64) 125!11 = !{i32 7, !"Dwarf Version", i32 5} 126!12 = !{i32 2, !"Debug Info Version", i32 3} 127!13 = !{i32 1, !"wchar_size", i32 4} 128!14 = !{i32 7, !"uwtable", i32 1} 129!15 = !{!"clang version 14.0.0"} 130!40 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 7, type: !41, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !43) 131!41 = !DISubroutineType(types: !42) 132!42 = !{!8} 133!43 = !{!44} 134!44 = !DILocalVariable(name: "nums", scope: !40, file: !3, line: 8, type: !5) 135!45 = distinct !DIAssignID() 136!46 = !DILocation(line: 0, scope: !40) 137!47 = !DILocation(line: 8, column: 3, scope: !40) 138!48 = !DILocation(line: 8, column: 15, scope: !40) 139!49 = distinct !DIAssignID() 140!50 = !DILocation(line: 9, column: 7, scope: !51) 141!51 = distinct !DILexicalBlock(scope: !40, file: !3, line: 9, column: 7) 142!52 = !DILocation(line: 9, column: 7, scope: !40) 143!53 = !DILocation(line: 10, column: 5, scope: !51) 144!54 = !DILocation(line: 12, column: 5, scope: !51) 145!55 = !DILocation(line: 14, column: 8, scope: !40) 146!56 = distinct !DIAssignID() 147!57 = !DILocation(line: 15, column: 3, scope: !40) 148!58 = !DILocation(line: 17, column: 10, scope: !40) 149!61 = distinct !DIAssignID() 150!62 = !DILocation(line: 19, column: 3, scope: !40) 151!63 = !DILocation(line: 21, column: 1, scope: !40) 152!64 = !DILocation(line: 20, column: 3, scope: !40) 153!65 = !DISubprogram(name: "step", linkageName: "_Z4stepv", scope: !3, file: !3, line: 5, type: !66, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !69) 154!66 = !DISubroutineType(types: !67) 155!67 = !{!68} 156!68 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) 157!69 = !{} 158!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 159