llvm.org GIT mirror llvm / ae03f03
Linker: Remove unnecessary call to copyMetadata in IRLinker::linkGlobalVariable. This was causing us to create duplicate metadata on global variables. Debug info test case by Adrian Prantl, additional test cases by me. Fixes PR31012. Differential Revision: https://reviews.llvm.org/D26622 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286905 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
4 changed file(s) with 76 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
949949 /// Update the initializers in the Dest module now that all globals that may be
950950 /// referenced are in Dest.
951951 void IRLinker::linkGlobalVariable(GlobalVariable &Dst, GlobalVariable &Src) {
952 Dst.copyMetadata(&Src, 0);
953
954952 // Figure out what the initializer looks like in the dest module.
955953 Mapper.scheduleMapGlobalInitializer(Dst, *Src.getInitializer());
956954 }
0 @g1 = external global i32, !attach !0
1
2 @g2 = global i32 1, !attach !0
3
4 @g3 = global i32 2, !attach !0
5
6 declare !attach !0 void @f1()
7
8 define void @f2() !attach !0 {
9 call void @f1()
10 store i32 0, i32* @g1
11 ret void
12 }
13
14 define void @f3() !attach !0 {
15 ret void
16 }
17
18 !0 = !{i32 1}
0 ; RUN: llvm-link -S %s %S/debug-info-version-a.ll | FileCheck %s
1 source_filename = "debug-info-global-var.c"
2 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-apple-macosx10.12.0"
4
5 ; CHECK: @g = global i32 0, align 4, !dbg ![[G:[0-9]+]]{{$}}
6 @g = global i32 0, align 4, !dbg !0
7
8 !llvm.dbg.cu = !{!1}
9 !llvm.module.flags = !{!6, !7, !8}
10 !llvm.ident = !{!9}
11
12 ; CHECK: ![[G]] = distinct !DIGlobalVariable(name: "g"
13 !0 = distinct !DIGlobalVariable(name: "g", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true)
14 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
15 !2 = !DIFile(filename: "debug-info-global-var.c", directory: "/")
16 !3 = !{}
17 !4 = !{!0}
18 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
19 !6 = !{i32 2, !"Dwarf Version", i32 4}
20 !7 = !{i32 2, !"Debug Info Version", i32 3}
21 !8 = !{i32 1, !"PIC Level", i32 2}
22 !9 = !{!"clang version 4.0.0 (trunk 286129) (llvm/trunk 286128)"}
0 ; RUN: llvm-link %s -S -o - | FileCheck %s
1 ; RUN: llvm-link %s %S/Inputs/metadata-attach.ll -S -o - | FileCheck --check-prefix=CHECK-LINKED1 %s
2 ; RUN: llvm-link %S/Inputs/metadata-attach.ll %s -S -o - | FileCheck --check-prefix=CHECK-LINKED2 %s
13
2 ; CHECK: @g1 = global i32 0, !attach !0
4 ; CHECK: @g1 = global i32 0, !attach !0{{$}}
5 ; CHECK-LINKED1: @g1 = global i32 0, !attach !0{{$}}
36 @g1 = global i32 0, !attach !0
47
5 ; CHECK: @g2 = external global i32, !attach !0
8 ; CHECK: @g3 = weak global i32 1, !attach !0{{$}}
9 ; CHECK: @g2 = external global i32, !attach !0{{$}}
10 ; CHECK-LINKED1: @g2 = global i32 1, !attach !1{{$}}
611 @g2 = external global i32, !attach !0
712
8 ; CHECK: define void @f1() !attach !0
13 ; CHECK-LINKED1: @g3 = global i32 2, !attach !1{{$}}
14 @g3 = weak global i32 1, !attach !0
15
16 ; CHECK-LINKED2: @g2 = global i32 1, !attach !0{{$}}
17 ; CHECK-LINKED2: @g3 = global i32 2, !attach !0{{$}}
18 ; CHECK-LINKED2: @g1 = global i32 0, !attach !1{{$}}
19
20 ; CHECK: define void @f1() !attach !0 {
21 ; CHECK-LINKED1: define void @f1() !attach !0 {
922 define void @f1() !attach !0 {
1023 call void @f2()
1124 store i32 0, i32* @g2
1326 }
1427
1528 ; CHECK: declare !attach !0 void @f2()
29 ; CHECK-LINKED1: define void @f2() !attach !1 {
1630 declare !attach !0 void @f2()
1731
18 !0 = !{}
32 ; CHECK: define weak void @f3() !attach !0 {
33 ; CHECK-LINKED1: define void @f3() !attach !1 {
34 define weak void @f3() !attach !0 {
35 ret void
36 }
37
38 ; CHECK-LINKED2: define void @f2() !attach !0 {
39 ; CHECK-LINKED2: define void @f3() !attach !0 {
40 ; CHECK-LINKED2: define void @f1() !attach !1 {
41
42 ; CHECK-LINKED1: !0 = !{i32 0}
43 ; CHECK-LINKED1: !1 = !{i32 1}
44
45 ; CHECK-LINKED2: !0 = !{i32 1}
46 ; CHECK-LINKED2: !1 = !{i32 0}
47
48 !0 = !{i32 0}