[llvm] f519bd9 - [Verifier] Require !callsite with !memprof metadata (#205053)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 18:46:09 PDT 2026
Author: lijinpei-amd
Date: 2026-06-23T09:46:04+08:00
New Revision: f519bd91d300238660914d9094b5e70090da1d85
URL: https://github.com/llvm/llvm-project/commit/f519bd91d300238660914d9094b5e70090da1d85
DIFF: https://github.com/llvm/llvm-project/commit/f519bd91d300238660914d9094b5e70090da1d85.diff
LOG: [Verifier] Require !callsite with !memprof metadata (#205053)
Fixes: https://github.com/llvm/llvm-project/issues/181237
Added:
Modified:
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/memprof-metadata-bad.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 2a0892d1af11a..648446555793b 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5343,6 +5343,9 @@ void Verifier::visitCallStackMetadata(MDNode *MD) {
void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) {
Check(isa<CallBase>(I), "!memprof metadata should only exist on calls", &I);
+ if (isa<CallBase>(I))
+ Check(I.hasMetadata(LLVMContext::MD_callsite),
+ "!memprof metadata requires !callsite metadata", &I, MD);
Check(MD->getNumOperands() >= 1,
"!memprof annotations should have at least 1 metadata operand "
"(MemInfoBlock)",
diff --git a/llvm/test/Verifier/memprof-metadata-bad.ll b/llvm/test/Verifier/memprof-metadata-bad.ll
index be212f062ef0b..408e47b12b12a 100644
--- a/llvm/test/Verifier/memprof-metadata-bad.ll
+++ b/llvm/test/Verifier/memprof-metadata-bad.ll
@@ -3,13 +3,14 @@
define ptr @test1() {
entry:
- %call1 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !0
- %call2 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !1
- %call3 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !3
- %call4 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !5
+ %call1 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !0, !callsite !9
+ %call2 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !1, !callsite !9
+ %call3 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !3, !callsite !9
+ %call4 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !5, !callsite !9
%call5 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !7, !callsite !9
- %call6 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !12
- %call7 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !15
+ %call6 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !12, !callsite !9
+ %call7 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !15, !callsite !9
+ %call8 = call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40), !memprof !18
ret ptr %call5
}
@@ -54,6 +55,9 @@ declare dso_local noalias noundef ptr @malloc(i64 noundef)
; CHECK: Not all !memprof MemInfoBlock operands 2 to N are MDNode with 2 operands
!16 = !{!14, !"default", !17}
!17 = !{i64 789}
+!18 = !{!19}
+; CHECK: !memprof metadata requires !callsite metadata
+!19 = !{!14, !"default"}
!9 = !{i64 123}
; CHECK: call stack metadata operand should be constant integer
!10 = !{!"wrongtype"}
More information about the llvm-commits
mailing list