[llvm] [CtxProf] emit fatal usage error when flatten-prethinlink runs without guid metadata (PR #194383)
Arda Serdar Pektezol via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 07:16:35 PDT 2026
https://github.com/pektezol created https://github.com/llvm/llvm-project/pull/194383
Fixes #194185
`ctx-prof-flatten-prethinlink` can call `AssignGUIDPass::getGUID()` on defined functions even when the GUID metadata is missing. In that case, LLVM currently asserts on missing `!guid` metadata.
Replace the assertion with `reportFatalUsageError()` so the pass fails with a clear user-facing error, and add a regression test for invoking only `ctx-prof-flatten-prethinlink`.
@boomanaiden154 sorry for the ping, accidentally closed the previous one. I updated the error message.
>From c0a98815d1ad04a982f70fb62d6757f487281fe3 Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <arda at pektezol.dev>
Date: Mon, 27 Apr 2026 17:14:12 +0300
Subject: [PATCH] [CtxProf] emit fatal usage error when flatten-prethinlink
runs without guid metadata
---
llvm/lib/Analysis/CtxProfAnalysis.cpp | 4 +++-
.../flatten-prethinlink-requires-guid-metadata.ll | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index c4abec02e765a..f0255e303d062 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -441,7 +441,9 @@ GlobalValue::GUID AssignGUIDPass::getGUID(const Function &F) {
return F.getGUID();
}
auto *MD = F.getMetadata(GUIDMetadataName);
- assert(MD && "guid not found for defined function");
+ if (!MD)
+ reportFatalUsageError(
+ "this pass requires the GUID metadata to be available.");
return cast<ConstantInt>(cast<ConstantAsMetadata>(MD->getOperand(0))
->getValue()
->stripPointerCasts())
diff --git a/llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll b/llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll
new file mode 100644
index 0000000000000..e234273bd7cc9
--- /dev/null
+++ b/llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll
@@ -0,0 +1,7 @@
+; RUN: not opt -passes='ctx-prof-flatten-prethinlink' %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: this pass requires the GUID metadata to be available.
+
+define void @test() {
+ ret void
+}
More information about the llvm-commits
mailing list