[llvm] [CtxProf] emit fatal usage error when flatten-prethinlink runs without guid metadata (PR #194383)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 07:17:39 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Arda Serdar Pektezol (pektezol)

<details>
<summary>Changes</summary>

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 (#<!-- -->194186). I updated the error message.

---
Full diff: https://github.com/llvm/llvm-project/pull/194383.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/CtxProfAnalysis.cpp (+3-1) 
- (added) llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll (+7) 


``````````diff
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/194383


More information about the llvm-commits mailing list