[llvm] c56a85f - [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:23 PST 2022


Author: Simon Pilgrim
Date: 2022-02-02T14:12:10Z
New Revision: c56a85fde0d6568cb12858bcf1db93c3e590f5e3

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

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

The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    llvm/tools/llvm-profgen/ProfiledBinary.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index a773a3c98d409..e477eb86f2652 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -211,9 +211,9 @@ void ProfiledBinary::load() {
   if (!DebugBinaryPath.empty()) {
     OwningBinary<Binary> DebugPath =
         unwrapOrError(createBinary(DebugBinaryPath), DebugBinaryPath);
-    loadSymbolsFromDWARF(*dyn_cast<ObjectFile>(DebugPath.getBinary()));
+    loadSymbolsFromDWARF(*cast<ObjectFile>(DebugPath.getBinary()));
   } else {
-    loadSymbolsFromDWARF(*dyn_cast<ObjectFile>(&ExeBinary));
+    loadSymbolsFromDWARF(*cast<ObjectFile>(&ExeBinary));
   }
 
   // Disassemble the text sections.


        


More information about the llvm-commits mailing list