[llvm-profgen] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 2 Feb 2022 13:19:11 +0000 (13:19 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 2 Feb 2022 14:12:11 +0000 (14:12 +0000)
The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr

llvm/tools/llvm-profgen/ProfileGenerator.cpp

index 1248e37..61d4626 100644 (file)
@@ -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