1; RUN: opt -passes=inline %s -S -o - \ 2; RUN: | FileCheck %s 3; RUN: opt --try-experimental-debuginfo-iterators -passes=inline %s -S -o - \ 4; RUN: | FileCheck %s 5 6;; Hand modified from: 7;; $ cat test.c 8;; int g = 5; 9;; static int callee() { 10;; int local = g; 11;; return local; 12;; } 13;; 14;; int fun() { 15;; return callee(); 16;; } 17;; 18;; IR grabbed before inlining in: 19;; $ clang++ -O2 -g 20;; Then modified (see comment in body). 21 22;; NOTE: Although this reproducer is contrived, this has been observed in real 23;; builds with assignment tracking (dbg.assign intrinsics) - in fact, it caused 24;; verifier failures in some cases using assignment tracking (good). This is 25;; the simplest test I could write. 26 27;; use-before-defs in debug intrinsics should be preserved through inlining, 28;; or at the very least should be converted to undefs. The previous behaviour 29;; was to replace the use-before-def operand with empty metadata, which signals 30;; cleanup passes that it's okay to remove the debug intrinsic (bad). Check 31;; that this no longer happens. 32 33; CHECK: define dso_local i32 @fun() 34; CHECK-NEXT: entry 35; CHECK-NEXT: #dbg_value(i32 %0 36 37@g = dso_local local_unnamed_addr global i32 5, align 4, !dbg !0 38 39define dso_local i32 @fun() local_unnamed_addr #0 !dbg !11 { 40entry: 41 %call = call fastcc i32 @callee(), !dbg !14 42 ret i32 %call, !dbg !15 43} 44 45define internal fastcc i32 @callee() unnamed_addr #1 !dbg !16 { 46entry: 47 ;; dbg.value moved here from after %0 def. 48 call void @llvm.dbg.value(metadata i32 %0, metadata !18, metadata !DIExpression()), !dbg !24 49 %0 = load i32, ptr @g, align 4, !dbg !19 50 ret i32 %0, !dbg !25 51} 52 53declare void @llvm.dbg.value(metadata, metadata, metadata) #2 54 55 56!llvm.dbg.cu = !{!2} 57!llvm.module.flags = !{!7, !8, !9, !1000} 58!llvm.ident = !{!10} 59 60!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 61!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) 62!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) 63!3 = !DIFile(filename: "test.c", directory: "/") 64!4 = !{} 65!5 = !{!0} 66!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 67!7 = !{i32 7, !"Dwarf Version", i32 4} 68!8 = !{i32 2, !"Debug Info Version", i32 3} 69!9 = !{i32 1, !"wchar_size", i32 4} 70!10 = !{!"clang version 12.0.0"} 71!11 = distinct !DISubprogram(name: "fun", scope: !3, file: !3, line: 7, type: !12, scopeLine: 7, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) 72!12 = !DISubroutineType(types: !13) 73!13 = !{!6} 74!14 = !DILocation(line: 8, column: 10, scope: !11) 75!15 = !DILocation(line: 8, column: 3, scope: !11) 76!16 = distinct !DISubprogram(name: "callee", scope: !3, file: !3, line: 2, type: !12, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !17) 77!17 = !{!18} 78!18 = !DILocalVariable(name: "local", scope: !16, file: !3, line: 3, type: !6) 79!19 = !DILocation(line: 3, column: 15, scope: !16) 80!24 = !DILocation(line: 0, scope: !16) 81!25 = !DILocation(line: 4, column: 3, scope: !16) 82!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 83