1; RUN: opt -run-twice -verify -S -o - %s | FileCheck %s 2 3; The ValueMap shared between CloneFunctionInto calls within CloneModule needs 4; to contain identity mappings for all of the DISubprogram's to prevent them 5; from being duplicated by MapMetadata / RemapInstruction calls, this is 6; achieved via DebugInfoFinder collecting all the DISubprogram's. However, 7; CloneFunctionInto was missing calls into DebugInfoFinder for functions w/o 8; DISubprogram's attached, but still referring DISubprogram's from within. 9; 10; This is to make sure we don't regress on that. 11 12; Derived from the following C-snippet 13; 14; int inlined(int j); 15; __attribute__((nodebug)) int nodebug(int k) { return inlined(k); } 16; __attribute__((always_inline)) int inlined(int j) { return j * 2; } 17; 18; compiled with `clang -O1 -g3 -emit-llvm -S` by removing 19; 20; call void @llvm.dbg.value(metadata i32 %k, metadata !8, metadata !DIExpression()), !dbg !14 21; 22; line from @nodebug function. 23 24; The @llvm.dbg.value call is manually removed from @nodebug as not having 25; it there also may cause an incorrect remapping of the call in a case of a 26; regression, not just a duplication of a DISubprogram. Namely, the call's 27; metadata !8 2nd argument and the !dbg !14 debug location may get remapped 28; to reference different copies of the DISubprogram, which is verified by IR 29; Verifier, while having DISubprogram duplicates is not. 30 31; CHECK: DISubprogram 32; CHECK-NOT: DISubprogram 33 34source_filename = "clone-module.c" 35target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 36target triple = "x86_64-apple-macosx" 37 38; Function Attrs: nounwind readnone ssp uwtable 39define i32 @nodebug(i32 %k) local_unnamed_addr #0 { 40entry: 41 %mul.i = shl nsw i32 %k, 1, !dbg !15 42 ret i32 %mul.i 43} 44 45; Function Attrs: alwaysinline nounwind readnone ssp uwtable 46define i32 @inlined(i32 %j) local_unnamed_addr #1 !dbg !9 { 47entry: 48 call void @llvm.dbg.value(metadata i32 %j, metadata !8, metadata !DIExpression()), !dbg !14 49 %mul = shl nsw i32 %j, 1, !dbg !15 50 ret i32 %mul, !dbg !16 51} 52 53; Function Attrs: nounwind readnone speculatable 54declare void @llvm.dbg.value(metadata, metadata, metadata) #2 55 56attributes #0 = { nounwind readnone ssp uwtable } 57attributes #1 = { alwaysinline nounwind readnone ssp uwtable } 58attributes #2 = { nounwind readnone speculatable } 59 60!llvm.dbg.cu = !{!0} 61!llvm.module.flags = !{!3, !4, !5, !6} 62!llvm.ident = !{!7} 63 64!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (https://git.llvm.org/git/clang.git/ 195459d046e795f5952f7d2121e505eeb59c5574) (https://git.llvm.org/git/llvm.git/ 69ec7d5667e9928db8435bfbee0da151c85a91c9)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 65!1 = !DIFile(filename: "clone-module.c", directory: "/somewhere") 66!2 = !{} 67!3 = !{i32 2, !"Dwarf Version", i32 4} 68!4 = !{i32 2, !"Debug Info Version", i32 3} 69!5 = !{i32 1, !"wchar_size", i32 4} 70!6 = !{i32 7, !"PIC Level", i32 2} 71!7 = !{!"clang version 7.0.0 (https://git.llvm.org/git/clang.git/ 195459d046e795f5952f7d2121e505eeb59c5574) (https://git.llvm.org/git/llvm.git/ 69ec7d5667e9928db8435bfbee0da151c85a91c9)"} 72!8 = !DILocalVariable(name: "j", arg: 1, scope: !9, file: !1, line: 3, type: !12) 73!9 = distinct !DISubprogram(name: "inlined", scope: !1, file: !1, line: 3, type: !10, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !13) 74!10 = !DISubroutineType(types: !11) 75!11 = !{!12, !12} 76!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 77!13 = !{!8} 78!14 = !DILocation(line: 3, column: 48, scope: !9) 79!15 = !DILocation(line: 3, column: 62, scope: !9) 80!16 = !DILocation(line: 3, column: 53, scope: !9) 81