xref: /llvm-project/llvm/test/DebugInfo/X86/clone-module-2.ll (revision b25ad38307fdf162d7030a002b6ef1d2048fda55)
1; RUN: opt -run-twice -passes=verify -S -o - %s | FileCheck %s
2
3; If a module contains a DISubprogram referenced only indirectly from
4; instruction-level debug info metadata, but not attached to any Function
5; defined within the module, cloning such a module with CloneModule was
6; causing a DICompileUnit duplication: it would be moved in indirecty via a
7; DISubprogram by DebugInfoFinder (making sure DISubprogram's don't get
8; duplicated) first without being explicitly self-mapped within the ValueMap
9; shared among CloneFunctionInto calls, and then it would get copied during
10; named metadata cloning.
11;
12; This is to make sure we don't regress on that.
13
14; Derived from the following C-snippet
15;
16; static int eliminated(int j);
17; __attribute__((nodebug)) int nodebug(int k) { return eliminated(k); }
18; __attribute__((always_inline)) static int eliminated(int j) { return j * 2; }
19;
20; compiled with `clang -O1 -g1 -emit-llvm -S`
21
22; CHECK:     DICompileUnit
23; CHECK-NOT: DICompileUnit
24
25source_filename = "clone-module.c"
26target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
27target triple = "x86_64-apple-macosx"
28
29; Function Attrs: norecurse nounwind readnone ssp uwtable
30define i32 @nodebug(i32 %k) local_unnamed_addr #0 {
31entry:
32  %mul.i = shl nsw i32 %k, 1, !dbg !8
33  ret i32 %mul.i
34}
35
36attributes #0 = { norecurse nounwind readnone ssp uwtable }
37
38!llvm.dbg.cu = !{!0}
39!llvm.module.flags = !{!3, !4, !5, !6}
40!llvm.ident = !{!7}
41
42!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
43!1 = !DIFile(filename: "test.c", directory: "/Volumes/Data/llvm/build/obj")
44!2 = !{}
45!3 = !{i32 2, !"Dwarf Version", i32 4}
46!4 = !{i32 2, !"Debug Info Version", i32 3}
47!5 = !{i32 1, !"wchar_size", i32 4}
48!6 = !{i32 7, !"PIC Level", i32 2}
49!7 = !{!"clang version 7.0.0"}
50!8 = !DILocation(line: 3, column: 72, scope: !9)
51!9 = distinct !DISubprogram(name: "eliminated", scope: !1, file: !1, line: 3, type: !10, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
52!10 = !DISubroutineType(types: !2)
53