1; RUN: opt %s -passes='cgscc(function(sroa,instcombine),inline),function(instcombine,sroa),verify' -S -o - | FileCheck %s 2; RUN: opt --try-experimental-debuginfo-iterators %s -passes='cgscc(function(sroa,instcombine),inline),function(instcombine,sroa),verify' -S -o - | FileCheck %s 3; 4; This test checks that SROA pass processes debug info correctly if applied twice. 5; Specifically, after SROA works first time, instcombine converts dbg.declare 6; intrinsics into dbg.value. Inlining creates new opportunities for SROA, 7; so it is called again. This time it does not handle correctly previously 8; inserted dbg.value intrinsics: current SROA implementation while doing 9; "Migrate debug information from the old alloca to the new alloca(s)" handles 10; only dbg.declare intrinsic. In this case, original dbg.declare was lowered by 11; instcombine pass into dbg.value. When it comes into SROA second time, all dbg.value 12; intrinsics, inserted by instcombine pass before second SROA, just not updated 13; (though SROA was done). The fix is to not lower dbg.declare for structures. 14 15; 16; Hand-reduced from this example (-g -O -mllvm -disable-llvm-optzns -gno-column-info): 17; 18; struct S1 { 19; int p1; 20; 21; bool IsNull ( ) { return p1 == 0; } 22; }; 23; 24; S1 foo ( void ); 25; 26; int bar ( ) { 27; S1 result = foo(); 28; 29; if (result.IsNull()) 30; return 0; 31; 32; return result.p1 + 1; 33; } 34 35; CHECK: _Z3barv 36; CHECK: %[[RESULT:.*]] = call i32 @_Z3foov 37; CHECK: #dbg_value(i32 %[[RESULT]], [[METADATA_IDX1:![0-9]+]] 38; CHECK: ret 39; CHECK: DICompileUnit 40; CHECK: [[METADATA_IDX1]] = !DILocalVariable(name: "result" 41 42target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 43target triple = "x86_64-unknown-linux-gnu" 44 45%struct.S1 = type { i32 } 46 47$_ZN2S16IsNullEv = comdat any 48 49define dso_local i32 @_Z3barv() !dbg !7 { 50entry: 51 %retval = alloca i32, align 4 52 %result = alloca %struct.S1, align 4 53 %cleanup.dest.slot = alloca i32, align 4 54 call void @llvm.lifetime.start.p0(i64 4, ptr %result) #5, !dbg !21 55 call void @llvm.dbg.declare(metadata ptr %result, metadata !12, metadata !DIExpression()), !dbg !21 56 %call = call i32 @_Z3foov(), !dbg !21 57 store i32 %call, ptr %result, align 4, !dbg !21 58 %call1 = call zeroext i1 @_ZN2S16IsNullEv(ptr %result), !dbg !22 59 br i1 %call1, label %if.then, label %if.end, !dbg !24 60 61if.then: ; preds = %entry 62 store i32 0, ptr %retval, align 4, !dbg !25 63 store i32 1, ptr %cleanup.dest.slot, align 4 64 br label %cleanup, !dbg !25 65 66if.end: ; preds = %entry 67 %0 = load i32, ptr %result, align 4, !dbg !26 68 %add = add nsw i32 %0, 1, !dbg !26 69 store i32 %add, ptr %retval, align 4, !dbg !26 70 store i32 1, ptr %cleanup.dest.slot, align 4 71 br label %cleanup, !dbg !26 72 73cleanup: ; preds = %if.end, %if.then 74 call void @llvm.lifetime.end.p0(i64 4, ptr %result) #5, !dbg !32 75 %1 = load i32, ptr %retval, align 4, !dbg !32 76 ret i32 %1, !dbg !32 77} 78 79declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) 80 81declare void @llvm.dbg.declare(metadata, metadata, metadata) 82 83declare dso_local i32 @_Z3foov() 84 85define linkonce_odr dso_local zeroext i1 @_ZN2S16IsNullEv(ptr %this) #4 comdat align 2 !dbg !33 { 86entry: 87 %this.addr = alloca ptr, align 8 88 store ptr %this, ptr %this.addr, align 8 89 call void @llvm.dbg.declare(metadata ptr %this.addr, metadata !35, metadata !DIExpression()), !dbg !39 90 %this1 = load ptr, ptr %this.addr, align 8 91 %0 = load i32, ptr %this1, align 4, !dbg !40 92 %cmp = icmp eq i32 %0, 0, !dbg !40 93 ret i1 %cmp, !dbg !40 94} 95 96declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) 97 98!llvm.dbg.cu = !{!0} 99!llvm.module.flags = !{!3, !4, !5} 100!llvm.ident = !{!6} 101 102!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) 103!1 = !DIFile(filename: "sroa-after-inlining.cpp", directory: "") 104!2 = !{} 105!3 = !{i32 2, !"Dwarf Version", i32 4} 106!4 = !{i32 2, !"Debug Info Version", i32 3} 107!5 = !{i32 1, !"wchar_size", i32 4} 108!6 = !{!"clang"} 109!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) 110!8 = !DISubroutineType(types: !9) 111!9 = !{!10} 112!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 113!11 = !{!12} 114!12 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 10, type: !13) 115!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S1", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTS2S1") 116!14 = !{!15, !16} 117!15 = !DIDerivedType(tag: DW_TAG_member, name: "p1", scope: !13, file: !1, line: 2, baseType: !10, size: 32) 118!16 = !DISubprogram(name: "IsNull", linkageName: "_ZN2S16IsNullEv", scope: !13, file: !1, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) 119!17 = !DISubroutineType(types: !18) 120!18 = !{!19, !20} 121!19 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) 122!20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 123!21 = !DILocation(line: 10, scope: !7) 124!22 = !DILocation(line: 12, scope: !23) 125!23 = distinct !DILexicalBlock(scope: !7, file: !1, line: 12) 126!24 = !DILocation(line: 12, scope: !7) 127!25 = !DILocation(line: 13, scope: !23) 128!26 = !DILocation(line: 15, scope: !7) 129!32 = !DILocation(line: 16, scope: !7) 130!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) 131!34 = !{!35} 132!35 = !DILocalVariable(name: "this", arg: 1, scope: !33, type: !36, flags: DIFlagArtificial | DIFlagObjectPointer) 133!36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) 134!39 = !DILocation(line: 0, scope: !33) 135!40 = !DILocation(line: 4, scope: !33) 136