135 lines · plain
1; RUN: opt %s -passes='cgscc(function(sroa,instcombine),inline),function(instcombine,sroa),verify' -S -o - | FileCheck %s2;3; This test checks that SROA pass processes debug info correctly if applied twice.4; Specifically, after SROA works first time, instcombine converts dbg.declare5; intrinsics into dbg.value. Inlining creates new opportunities for SROA,6; so it is called again. This time it does not handle correctly previously7; inserted dbg.value intrinsics: current SROA implementation while doing8; "Migrate debug information from the old alloca to the new alloca(s)" handles9; only dbg.declare intrinsic. In this case, original dbg.declare was lowered by10; instcombine pass into dbg.value. When it comes into SROA second time, all dbg.value11; intrinsics, inserted by instcombine pass before second SROA, just not updated12; (though SROA was done). The fix is to not lower dbg.declare for structures.13 14;15; Hand-reduced from this example (-g -O -mllvm -disable-llvm-optzns -gno-column-info):16;17; struct S1 {18; int p1;19;20; bool IsNull ( ) { return p1 == 0; }21; };22;23; S1 foo ( void );24;25; int bar ( ) {26; S1 result = foo();27;28; if (result.IsNull())29; return 0;30;31; return result.p1 + 1;32; }33 34; CHECK: _Z3barv35; CHECK: %[[RESULT:.*]] = call i32 @_Z3foov36; CHECK: #dbg_value(i32 %[[RESULT]], [[METADATA_IDX1:![0-9]+]]37; CHECK: ret38; CHECK: DICompileUnit39; CHECK: [[METADATA_IDX1]] = !DILocalVariable(name: "result"40 41target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"42target triple = "x86_64-unknown-linux-gnu"43 44%struct.S1 = type { i32 }45 46$_ZN2S16IsNullEv = comdat any47 48define dso_local i32 @_Z3barv() !dbg !7 {49entry:50 %retval = alloca i32, align 451 %result = alloca %struct.S1, align 452 %cleanup.dest.slot = alloca i32, align 453 call void @llvm.lifetime.start.p0(i64 4, ptr %result) #5, !dbg !2154 call void @llvm.dbg.declare(metadata ptr %result, metadata !12, metadata !DIExpression()), !dbg !2155 %call = call i32 @_Z3foov(), !dbg !2156 store i32 %call, ptr %result, align 4, !dbg !2157 %call1 = call zeroext i1 @_ZN2S16IsNullEv(ptr %result), !dbg !2258 br i1 %call1, label %if.then, label %if.end, !dbg !2459 60if.then: ; preds = %entry61 store i32 0, ptr %retval, align 4, !dbg !2562 store i32 1, ptr %cleanup.dest.slot, align 463 br label %cleanup, !dbg !2564 65if.end: ; preds = %entry66 %0 = load i32, ptr %result, align 4, !dbg !2667 %add = add nsw i32 %0, 1, !dbg !2668 store i32 %add, ptr %retval, align 4, !dbg !2669 store i32 1, ptr %cleanup.dest.slot, align 470 br label %cleanup, !dbg !2671 72cleanup: ; preds = %if.end, %if.then73 call void @llvm.lifetime.end.p0(i64 4, ptr %result) #5, !dbg !3274 %1 = load i32, ptr %retval, align 4, !dbg !3275 ret i32 %1, !dbg !3276}77 78declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)79 80declare void @llvm.dbg.declare(metadata, metadata, metadata)81 82declare dso_local i32 @_Z3foov()83 84define linkonce_odr dso_local zeroext i1 @_ZN2S16IsNullEv(ptr %this) #4 comdat align 2 !dbg !33 {85entry:86 %this.addr = alloca ptr, align 887 store ptr %this, ptr %this.addr, align 888 call void @llvm.dbg.declare(metadata ptr %this.addr, metadata !35, metadata !DIExpression()), !dbg !3989 %this1 = load ptr, ptr %this.addr, align 890 %0 = load i32, ptr %this1, align 4, !dbg !4091 %cmp = icmp eq i32 %0, 0, !dbg !4092 ret i1 %cmp, !dbg !4093}94 95declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)96 97!llvm.dbg.cu = !{!0}98!llvm.module.flags = !{!3, !4, !5}99!llvm.ident = !{!6}100 101!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)102!1 = !DIFile(filename: "sroa-after-inlining.cpp", directory: "")103!2 = !{}104!3 = !{i32 2, !"Dwarf Version", i32 4}105!4 = !{i32 2, !"Debug Info Version", i32 3}106!5 = !{i32 1, !"wchar_size", i32 4}107!6 = !{!"clang"}108!7 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)109!8 = !DISubroutineType(types: !9)110!9 = !{!10}111!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)112!11 = !{!12}113!12 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 10, type: !13)114!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S1", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTS2S1")115!14 = !{!15, !16}116!15 = !DIDerivedType(tag: DW_TAG_member, name: "p1", scope: !13, file: !1, line: 2, baseType: !10, size: 32)117!16 = !DISubprogram(name: "IsNull", linkageName: "_ZN2S16IsNullEv", scope: !13, file: !1, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)118!17 = !DISubroutineType(types: !18)119!18 = !{!19, !20}120!19 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)121!20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)122!21 = !DILocation(line: 10, scope: !7)123!22 = !DILocation(line: 12, scope: !23)124!23 = distinct !DILexicalBlock(scope: !7, file: !1, line: 12)125!24 = !DILocation(line: 12, scope: !7)126!25 = !DILocation(line: 13, scope: !23)127!26 = !DILocation(line: 15, scope: !7)128!32 = !DILocation(line: 16, scope: !7)129!33 = distinct !DISubprogram(name: "IsNull", linkageName: "_ZN2S16IsNullEv", scope: !13, file: !1, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !16, retainedNodes: !34)130!34 = !{!35}131!35 = !DILocalVariable(name: "this", arg: 1, scope: !33, type: !36, flags: DIFlagArtificial | DIFlagObjectPointer)132!36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)133!39 = !DILocation(line: 0, scope: !33)134!40 = !DILocation(line: 4, scope: !33)135