[llvm] 86bbf01 - [llvm-profgen] CSProfileGenerator::generateLineNumBasedProfile - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 14 06:51:40 PST 2022


Author: Simon Pilgrim
Date: 2022-01-14T14:49:57Z
New Revision: 86bbf01d896cfe82acd4379be436a0417976000b

URL: https://github.com/llvm/llvm-project/commit/86bbf01d896cfe82acd4379be436a0417976000b
DIFF: https://github.com/llvm/llvm-project/commit/86bbf01d896cfe82acd4379be436a0417976000b.diff

LOG: [llvm-profgen] CSProfileGenerator::generateLineNumBasedProfile - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is always dereferenced immediately below, 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 7155ec4a42191..4fd649df17b18 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -614,8 +614,8 @@ void CSProfileGenerator::computeSizeForProfiledFunctions() {
 
 void CSProfileGenerator::generateLineNumBasedProfile() {
   for (const auto &CI : SampleCounters) {
-    const StringBasedCtxKey *CtxKey =
-        dyn_cast<StringBasedCtxKey>(CI.first.getPtr());
+    const auto *CtxKey = cast<StringBasedCtxKey>(CI.first.getPtr());
+
     // Get or create function profile for the range
     FunctionSamples &FunctionProfile =
         getFunctionProfileForContext(CtxKey->Context, CtxKey->WasLeafInlined);


        


More information about the llvm-commits mailing list