1; RUN: opt -passes=mem2reg -S %s -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg" 2; RUN: opt --try-experimental-debuginfo-iterators -passes=mem2reg -S %s -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg" 3 4; CHECK: #dbg_value(i64 0, ![[#]], !DIExpression(DW_OP_LLVM_fragment, 0, 32), 5 6;; The store has a debug intrinsic attached to it with a fragment size 7;; different to the base alloca debug intrinsic fragment size. Check that 8;; mem2reg doesn't think this store is "untagged" for that base variable. If 9;; that were the case mem2reg would insert a dbg.value covering the entire 10;; variable, which isn't the right thing to do here. This example looks weird 11;; and not particularly compelling, but this was encountered in the wild on 12;; "real code". 13 14;; Reduced from this C++ (which itself has been reduced). 15;; class a { 16;; public: 17;; a(float, float); 18;; }; 19;; class d { 20;; protected: 21;; float b[4]; 22;; 23;; public: 24;; float e() { return b[0]; } 25;; float f() { return b[1]; } 26;; }; 27;; class g : public d { 28;; public: 29;; void operator*=(g) { 30;; { 31;; float __attribute__((nodebug)) c = b[2], __attribute__((nodebug)) h = b[0]; 32;; b[0] = c; 33;; b[1] = h; 34;; } 35;; } 36;; }; 37;; g get(); 38;; void i() { 39;; g __attribute__((nodebug)) j = get(); 40;; g k = j; 41;; k *= j; 42;; a(k.e(), k.f()); 43;; } 44 45define dso_local i64 @_Z3funv() #0 !dbg !10 { 46entry: 47 %retval.sroa.0 = alloca i64, align 8, !DIAssignID !20 48 call void @llvm.dbg.assign(metadata i1 undef, metadata !19, metadata !DIExpression(), metadata !20, metadata ptr %retval.sroa.0, metadata !DIExpression()), !dbg !21 49 store i64 0, ptr %retval.sroa.0, align 8, !dbg !22, !DIAssignID !23 50 call void @llvm.dbg.assign(metadata i64 0, metadata !19, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32), metadata !23, metadata ptr %retval.sroa.0, metadata !DIExpression()), !dbg !21 51 ret i64 0 52} 53 54declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 55declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #1 56 57!llvm.dbg.cu = !{!0} 58!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} 59!llvm.ident = !{!9} 60 61!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) 62!1 = !DIFile(filename: "test.cpp", directory: "/") 63!2 = !{i32 7, !"Dwarf Version", i32 5} 64!3 = !{i32 2, !"Debug Info Version", i32 3} 65!4 = !{i32 1, !"wchar_size", i32 4} 66!5 = !{i32 8, !"PIC Level", i32 2} 67!6 = !{i32 7, !"PIE Level", i32 2} 68!7 = !{i32 7, !"uwtable", i32 2} 69!8 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 70!9 = !{!"clang version 17.0.0"} 71!10 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !18) 72!11 = !DISubroutineType(types: !12) 73!12 = !{!13} 74!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Pair", file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTS4Pair") 75!14 = !{!15, !17} 76!15 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !13, file: !1, line: 1, baseType: !16, size: 32) 77!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 78!17 = !DIDerivedType(tag: DW_TAG_member, name: "B", scope: !13, file: !1, line: 1, baseType: !16, size: 32, offset: 32) 79!18 = !{!19} 80!19 = !DILocalVariable(name: "X", scope: !10, file: !1, line: 3, type: !13) 81!20 = distinct !DIAssignID() 82!21 = !DILocation(line: 0, scope: !10) 83!22 = !DILocation(line: 3, column: 8, scope: !10) 84!23 = distinct !DIAssignID() 85!24 = !DILocation(line: 4, column: 3, scope: !10) 86