[llvm] 5ea5b9e - [profcheck] Fix assert in getInitializer call on global with no initializer (#193514)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 22 09:52:30 PDT 2026
Author: Nick Sarnie
Date: 2026-04-22T16:52:25Z
New Revision: 5ea5b9eb8eec9c5ba7f053cb74327a3efd6b762d
URL: https://github.com/llvm/llvm-project/commit/5ea5b9eb8eec9c5ba7f053cb74327a3efd6b762d
DIFF: https://github.com/llvm/llvm-project/commit/5ea5b9eb8eec9c5ba7f053cb74327a3efd6b762d.diff
LOG: [profcheck] Fix assert in getInitializer call on global with no initializer (#193514)
This code calls `getInitializer` without checking if the global has an
initializer, which causes an assert if there isn't one. These globals
may have no initializer after optimization from `globalopt`.
Check for an initializer first.
This is already locked down with
`CodeGen/SPIRV/legalize-zero-size-arrays-appending.ll` so we don't need
a new test.
This issue was exposed by
https://github.com/llvm/llvm-project/pull/192730.
Signed-off-by: Nick Sarnie <nick.sarnie at intel.com>
Added:
Modified:
llvm/lib/Transforms/Utils/ProfileVerify.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/ProfileVerify.cpp b/llvm/lib/Transforms/Utils/ProfileVerify.cpp
index 63f83749e9636..cba4afb557800 100644
--- a/llvm/lib/Transforms/Utils/ProfileVerify.cpp
+++ b/llvm/lib/Transforms/Utils/ProfileVerify.cpp
@@ -206,14 +206,15 @@ PreservedAnalyses ProfileVerifierPass::run(Module &M,
ModuleAnalysisManager &MAM) {
auto PopulateIgnoreList = [&](StringRef GVName) {
if (const auto *CT = M.getGlobalVariable(GVName))
- if (const auto *CA =
- dyn_cast_if_present<ConstantArray>(CT->getInitializer()))
- for (const auto &Elt : CA->operands())
- if (const auto *CS = dyn_cast<ConstantStruct>(Elt))
- if (CS->getNumOperands() >= 2 && CS->getOperand(1))
- if (const auto *F = dyn_cast<Function>(
- CS->getOperand(1)->stripPointerCasts()))
- IgnoreList.insert(F);
+ if (CT->hasInitializer())
+ if (const auto *CA =
+ dyn_cast_if_present<ConstantArray>(CT->getInitializer()))
+ for (const auto &Elt : CA->operands())
+ if (const auto *CS = dyn_cast<ConstantStruct>(Elt))
+ if (CS->getNumOperands() >= 2 && CS->getOperand(1))
+ if (const auto *F = dyn_cast<Function>(
+ CS->getOperand(1)->stripPointerCasts()))
+ IgnoreList.insert(F);
};
PopulateIgnoreList("llvm.global_ctors");
PopulateIgnoreList("llvm.global_dtors");
More information about the llvm-commits
mailing list