26 changes: 26 additions & 0 deletions llvm/test/Linker/associated-global.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; RUN: llvm-link -S %s %S/Inputs/associated-global.ll | FileCheck %s

; CHECK: @c = internal global i32 1, !associated !0
; CHECK: @d = global i32 0, !associated !1
; CHECK: @a = global i32 0, !associated !2
; CHECK: @b = global i32 0, !associated !3
; CHECK: @c.3 = internal global i32 1, !associated !4
; CHECK: @e = global i32 0, !associated !5

; CHECK: !0 = !{ptr @d}
; CHECK: !1 = !{ptr @c}
; CHECK: !2 = !{ptr @b}
; CHECK: !3 = !{ptr @a}
; CHECK: !4 = !{ptr @e}
; CHECK: !5 = !{ptr @c.3}


@a = external global i32, !associated !0
@b = global i32 0, !associated !1
@c = internal global i32 1, !associated !2
@d = global i32 0, !associated !3

!0 = !{ptr @b}
!1 = !{ptr @a}
!2 = !{ptr @d}
!3 = !{ptr @c}
4 changes: 2 additions & 2 deletions llvm/test/Linker/metadata-global.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
; CHECK-DAG: @a = global i32 0
; CHECK-DAG: @b = global i32 0, !associated !0

; CHECK-DAG: !0 = !{ptr @b}
; CHECK-DAG: !0 = !{ptr @a}

@a = global i32 0
@b = global i32 0, !associated !0

!0 = !{ptr @b}
!0 = !{ptr @a}
47 changes: 47 additions & 0 deletions llvm/test/Verifier/associated-metadata.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
; RUN: not llvm-as -disable-output < %s -o /dev/null 2>&1 | FileCheck %s

; CHECK: associated value must be pointer typed
; CHECK-NEXT: ptr addrspace(1) @associated.int
; CHECK-NEXT: !0 = !{i32 1}
@associated.int = external addrspace(1) constant [8 x i8], !associated !0

; CHECK: associated value must be pointer typed
; CHECK-NEXT: ptr addrspace(1) @associated.float
; CHECK-NEXT: !1 = !{float 1.000000e+00}
@associated.float = external addrspace(1) constant [8 x i8], !associated !1

; CHECK: associated metadata must have one operand
; CHECK-NEXT: ptr addrspace(1) @associated.too.many.ops
; CHECK-NEXT: !2 = !{ptr @gv.decl0, ptr @gv.decl1}
@associated.too.many.ops = external addrspace(1) constant [8 x i8], !associated !2

; CHECK: associated metadata must have one operand
; CHECK-NEXT: ptr addrspace(1) @associated.empty
; CHECK-NEXT: !3 = !{}
@associated.empty = external addrspace(1) constant [8 x i8], !associated !3

; CHECK: associated metadata must have a global value
; CHECK-NEXT: ptr addrspace(1) @associated.null.metadata
; CHECK-NEXT: !4 = !{null}
@associated.null.metadata = external addrspace(1) constant [8 x i8], !associated !4

; CHECK: global values should not associate to themselves
; CHECK-NEXT: ptr @associated.self
; CHECK-NEXT: !5 = !{ptr @associated.self}
@associated.self = external constant [8 x i8], !associated !5

; CHECK: associated metadata must be ValueAsMetadata
; CHECK-NEXT: ptr @associated.string
; CHECK-NEXT: !6 = !{!"string"}
@associated.string = external constant [8 x i8], !associated !6

@gv.decl0 = external constant [8 x i8]
@gv.decl1 = external constant [8 x i8]

!0 = !{i32 1}
!1 = !{float 1.000000e+00}
!2 = !{ptr @gv.decl0, ptr @gv.decl1}
!3 = !{}
!4 = !{null}
!5 = !{ptr @associated.self}
!6 = !{!"string"}