[llvm] [CGProfile] Fix unhandled error crash on empty canonical function names (PR #201821)

Arseniy Obolenskiy via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 05:02:35 PDT 2026


https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/201821

A function whose entire name is a strippable suffix  canonicalizes to an empty name, making InstrProfSymtab::create return an error

The current solution with `(void)(bool)` does not really suppress the error which leads to the crash

>From 391f816eb9e7a05c3c23dcffdd47aa9996ab85a7 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Fri, 5 Jun 2026 14:01:07 +0200
Subject: [PATCH] [CGProfile] Fix unhandled error crash on empty canonical
 function names

A function whose entire name is a strippable suffix  canonicalizes to an empty name, making InstrProfSymtab::create return an error

The current solution with `(void)(bool)` does not really suppress the error which leads to the crash
---
 llvm/lib/Transforms/Instrumentation/CGProfile.cpp      |  2 +-
 .../Instrumentation/cgprofile-empty-canonical-name.ll  | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Instrumentation/cgprofile-empty-canonical-name.ll

diff --git a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
index 60e7acc77ca29..07bbd2b8fccfd 100644
--- a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
+++ b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
@@ -60,7 +60,7 @@ static bool runCGProfilePass(Module &M, FunctionAnalysisManager &FAM,
     Count = SaturatingAdd(Count, NewCount);
   };
   // Ignore error here.  Indirect calls are ignored if this fails.
-  (void)(bool)Symtab.create(M, InLTO);
+  consumeError(Symtab.create(M, InLTO));
   for (auto &F : M) {
     // Avoid extra cost of running passes for BFI when the function doesn't have
     // entry count.
diff --git a/llvm/test/Instrumentation/cgprofile-empty-canonical-name.ll b/llvm/test/Instrumentation/cgprofile-empty-canonical-name.ll
new file mode 100644
index 0000000000000..a4fbf1d18ece0
--- /dev/null
+++ b/llvm/test/Instrumentation/cgprofile-empty-canonical-name.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -passes='cg-profile' -S | FileCheck %s
+
+; A function whose entire name is a strippable suffix (e.g. ".llvm.123")
+; canonicalizes to an empty name. Building the InstrProfSymtab
+; for such a name returns an error that cg-profile intentionally ignores.
+
+; CHECK: define void @.llvm.123()
+define void @.llvm.123() {
+  ret void
+}



More information about the llvm-commits mailing list