[llvm] 01d5254 - [llvm-profgen] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 2 06:12:25 PST 2022
Author: Simon Pilgrim
Date: 2022-02-02T14:12:11Z
New Revision: 01d5254f3de0e8870e3550a792801fa1da59b931
URL: https://github.com/llvm/llvm-project/commit/01d5254f3de0e8870e3550a792801fa1da59b931
DIFF: https://github.com/llvm/llvm-project/commit/01d5254f3de0e8870e3550a792801fa1da59b931.diff
LOG: [llvm-profgen] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
Added:
Modified:
llvm/tools/llvm-profgen/ProfileGenerator.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 1248e37dc506..61d4626574a0 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -820,8 +820,7 @@ static void extractPrefixContextStack(
void CSProfileGenerator::generateProbeBasedProfile() {
for (const auto &CI : SampleCounters) {
- const ProbeBasedCtxKey *CtxKey =
- dyn_cast<ProbeBasedCtxKey>(CI.first.getPtr());
+ const auto *CtxKey = cast<ProbeBasedCtxKey>(CI.first.getPtr());
SampleContextFrameVector ContextStack;
extractPrefixContextStack(ContextStack, CtxKey->Probes, Binary);
// Fill in function body samples from probes, also infer caller's samples
More information about the llvm-commits
mailing list