133 lines · plain
1; RUN: opt -passes=redundant-dbg-inst-elim -S %s -o - \2; RUN: | FileCheck %s --implicit-check-not="#dbg_"3 4;; $ cat -n reduce.c5;; 1 void ext();6;; 2 typedef struct {7;; 3 short *a;8;; 4 char *b;9;; 5 } c;10;; 6 char d;11;; 7 void f();12;; 8 typedef struct {13;; 9 c decoder;14;; 10 } e;15;; 11 void g() {16;; 12 e a;17;; 13 (&(&a)->decoder)->b = 0;18;; 14 (&(&a)->decoder)->a = 0;19;; 15 ext();20;; 16 a.decoder.b = &d;21;; 17 f(&a);22;; 18 }23 24;; clang -O2 -g -Xclang -fexperiemental-assignment-tracking:25;;26;; MemCpyOptPass: Aggregate scalar stores from line 13 and 14 into memset.27;; DSE: Shorten aggregated store because field 'b' is re-assigned later.28;; Insert an unlinked dbg.assign after the dbg.assign describing29;; the fragment for field 'b', which is still linked to the memset.30;;31;; Check we don't delete that inserted unlinked dbg.assign.32 33; CHECK: %a = alloca %struct.e, align 8, !DIAssignID ![[ID_0:[0-9]+]]34; CHECK-NEXT: #dbg_assign({{.*}}, ![[ID_0]],{{.*}})35 36;; This dbg.assign is linked to the memset.37; CHECK: #dbg_assign(ptr null,{{.*}}, !DIExpression(DW_OP_LLVM_fragment, 64, 64), ![[ID_1:[0-9]+]], ptr %b, !DIExpression(),38 39;; Importantly, check this unlinked dbg.assign which is shadowed by the40;; dbg.assign above isn't deleted.41; CHECK-NEXT: #dbg_assign(ptr null,{{.*}}, !DIExpression(DW_OP_LLVM_fragment, 64, 64), ![[ID_2:[0-9]+]], ptr undef, !DIExpression(),42 43; CHECK: #dbg_assign(ptr null,{{.*}}, !DIExpression(DW_OP_LLVM_fragment, 0, 64), ![[ID_1]], ptr %a2, !DIExpression(),44 45; CHECK: call void @llvm.memset{{.*}}, !DIAssignID ![[ID_1]]46 47; CHECK: store ptr @d, ptr %b, align 8,{{.*}}!DIAssignID ![[ID_3:[0-9]+]]48; CHECK-NEXT: #dbg_assign(ptr @d,{{.*}}, !DIExpression(DW_OP_LLVM_fragment, 64, 64), ![[ID_3]], ptr %b, !DIExpression(),49 50; CHECK-DAG: ![[ID_0]] = distinct !DIAssignID()51; CHECK-DAG: ![[ID_1]] = distinct !DIAssignID()52; CHECK-DAG: ![[ID_2]] = distinct !DIAssignID()53; CHECK-DAG: ![[ID_3]] = distinct !DIAssignID()54 55%struct.e = type { %struct.c }56%struct.c = type { ptr, ptr }57 58@d = dso_local global i8 0, align 1, !dbg !059 60define dso_local void @g() local_unnamed_addr #0 !dbg !12 {61entry:62 %a = alloca %struct.e, align 8, !DIAssignID !2963 call void @llvm.dbg.assign(metadata i1 undef, metadata !16, metadata !DIExpression(), metadata !29, metadata ptr %a, metadata !DIExpression()), !dbg !3064 call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %a) #5, !dbg !3165 %b = getelementptr inbounds %struct.e, ptr %a, i64 0, i32 0, i32 1, !dbg !3266 call void @llvm.dbg.assign(metadata ptr null, metadata !16, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64), metadata !33, metadata ptr %b, metadata !DIExpression()), !dbg !3067 call void @llvm.dbg.assign(metadata ptr null, metadata !16, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64), metadata !34, metadata ptr undef, metadata !DIExpression()), !dbg !3068 %a2 = getelementptr inbounds %struct.e, ptr %a, i64 0, i32 0, i32 0, !dbg !3569 call void @llvm.dbg.assign(metadata ptr null, metadata !16, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64), metadata !33, metadata ptr %a2, metadata !DIExpression()), !dbg !3070 call void @llvm.memset.p0.i64(ptr align 8 %a2, i8 0, i64 8, i1 false), !dbg !35, !DIAssignID !3371 tail call void (...) @ext() #5, !dbg !3672 store ptr @d, ptr %b, align 8, !dbg !37, !DIAssignID !4473 call void @llvm.dbg.assign(metadata ptr @d, metadata !16, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64), metadata !44, metadata ptr %b, metadata !DIExpression()), !dbg !3074 call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %a) #5, !dbg !4675 ret void, !dbg !4676}77 78declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #179declare !dbg !47 dso_local void @ext(...) local_unnamed_addr #280declare dso_local void @f(...) local_unnamed_addr #281declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #182declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #383declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #484 85!llvm.dbg.cu = !{!2}86!llvm.module.flags = !{!6, !7, !8, !9, !10, !1000}87!llvm.ident = !{!11}88 89!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())90!1 = distinct !DIGlobalVariable(name: "d", scope: !2, file: !3, line: 6, type: !5, isLocal: false, isDefinition: true)91!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)92!3 = !DIFile(filename: "reduce.c", directory: "/")93!4 = !{!0}94!5 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)95!6 = !{i32 7, !"Dwarf Version", i32 5}96!7 = !{i32 2, !"Debug Info Version", i32 3}97!8 = !{i32 1, !"wchar_size", i32 4}98!9 = !{i32 7, !"uwtable", i32 1}99!10 = !{i32 7, !"frame-pointer", i32 2}100!11 = !{!"clang version 14.0.0"}101!12 = distinct !DISubprogram(name: "g", scope: !3, file: !3, line: 11, type: !13, scopeLine: 11, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)102!13 = !DISubroutineType(types: !14)103!14 = !{null}104!15 = !{!16}105!16 = !DILocalVariable(name: "a", scope: !12, file: !3, line: 12, type: !17)106!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "e", file: !3, line: 10, baseType: !18)107!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 8, size: 128, elements: !19)108!19 = !{!20}109!20 = !DIDerivedType(tag: DW_TAG_member, name: "decoder", scope: !18, file: !3, line: 9, baseType: !21, size: 128)110!21 = !DIDerivedType(tag: DW_TAG_typedef, name: "c", file: !3, line: 5, baseType: !22)111!22 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 2, size: 128, elements: !23)112!23 = !{!24, !27}113!24 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !22, file: !3, line: 3, baseType: !25, size: 64)114!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !26, size: 64)115!26 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)116!27 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !22, file: !3, line: 4, baseType: !28, size: 64, offset: 64)117!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)118!29 = distinct !DIAssignID()119!30 = !DILocation(line: 0, scope: !12)120!31 = !DILocation(line: 12, scope: !12)121!32 = !DILocation(line: 13, scope: !12)122!33 = distinct !DIAssignID()123!34 = distinct !DIAssignID()124!35 = !DILocation(line: 14, scope: !12)125!36 = !DILocation(line: 15, scope: !12)126!37 = !DILocation(line: 16, scope: !12)127!44 = distinct !DIAssignID()128!45 = !DILocation(line: 17, scope: !12)129!46 = !DILocation(line: 18, scope: !12)130!47 = !DISubprogram(name: "ext", scope: !3, file: !3, line: 1, type: !13, spFlags: DISPFlagOptimized, retainedNodes: !48)131!48 = !{}132!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}133