Skip to content

Commit c574fb2

Browse files
committed
Verify ref metadata node is not placed on a declaration.
1 parent 3617a36 commit c574fb2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,9 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
771771
}
772772

773773
if (GO->hasMetadata(LLVMContext::MD_ref)) {
774+
Check(!GO->isDeclaration(),
775+
"ref metadata must not be placed on a declaration", GO);
776+
774777
SmallVector<MDNode *> MDs;
775778
GO->getMetadata(LLVMContext::MD_ref, MDs);
776779
for (const MDNode *MD : MDs) {

llvm/test/Verifier/ref.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@b = global i32 2, !ref !1
55
@c = global i32 3, !ref !1, !ref !2
66
@d = global i32 4, !ref !3
7+
@e = external global i32, !ref !1
78

89
!0 = !{i32 1}
910
!1 = !{ptr @b}
@@ -25,3 +26,6 @@
2526
; CHECK: ref metadata must have one operand
2627
; CHECK: ptr @d
2728
; CHECK: !3 = !{ptr @c, ptr @a}
29+
30+
; CHECK: ref metadata must not be placed on a declaration
31+
; CHECK: @e

0 commit comments

Comments
 (0)