[llvm] [Verifier] Add missing null-check. (PR #199170)
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Thu May 21 22:50:38 PDT 2026
https://github.com/jlebar updated https://github.com/llvm/llvm-project/pull/199170
>From 15e31c044716274bb9944d62a35b02edbca752ac Mon Sep 17 00:00:00 2001
From: Justin Lebar <justin.lebar at gmail.com>
Date: Thu, 21 May 2026 20:57:48 -0700
Subject: [PATCH] [Verifier] Add missing null-check.
visitProfMetadata's was using the result of dyn_extract without first
checkout that it's non-null. Thus one could crash the verifier by
providing invalid IR.
---
llvm/lib/IR/Verifier.cpp | 1 +
llvm/test/Verifier/value-profile.ll | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 9c6c5f245ff0b..900c92722473b 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5432,6 +5432,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
for (unsigned I = 3; I < MD->getNumOperands(); I += 2) {
ConstantInt *ProfileValue =
mdconst::dyn_extract<ConstantInt>(MD->getOperand(I));
+ Check(ProfileValue, "VP !prof value operand is not a const int", MD);
uint64_t ProfileValueInt = ProfileValue->getZExtValue();
auto [ValueIt, Inserted] = ProfileValues.insert(ProfileValueInt);
Check(Inserted, "VP !prof should not have duplicate profile values", MD);
diff --git a/llvm/test/Verifier/value-profile.ll b/llvm/test/Verifier/value-profile.ll
index 56740cc0c3035..45c8fa0c6bb16 100644
--- a/llvm/test/Verifier/value-profile.ll
+++ b/llvm/test/Verifier/value-profile.ll
@@ -6,6 +6,7 @@
; RUN: not opt -passes=verify %t/invalid-count.ll --disable-output 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT
; RUN: not opt -passes=verify %t/invalid-place.ll --disable-output 2>&1 | FileCheck %s --check-prefix=INVALID-PLACE
; RUN: not opt -passes=verify %t/invalid-duplicate-values.ll -disable-output 2>&1 | FileCheck %s --check-prefix=INVALID-DUPLICATE-VALUES
+; RUN: not opt -passes=verify %t/invalid-value-not-const-int.ll -disable-output 2>&1 | FileCheck %s --check-prefix=INVALID-VALUE-NOT-CONST-INT
;--- valid.ll
define void @test(ptr %0) {
@@ -45,3 +46,11 @@ define void @test(ptr %0) {
}
!0 = !{!"VP", i32 0, i64 1234, i64 72657670687977694852, i64 1, i64 72657670687977694852, i64 2}
; INVALID-DUPLICATE-VALUES: VP !prof should not have duplicate profile values
+
+;--- invalid-value-not-const-int.ll
+define void @test(ptr %0) {
+ call void %0(), !prof !0
+ ret void
+}
+!0 = !{!"VP", i32 0, i64 100, !"oops", i64 50}
+; INVALID-VALUE-NOT-CONST-INT: VP !prof value operand is not a const int
More information about the llvm-commits
mailing list