[llvm] 946f290 - [llvm-objdump] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 23 04:51:01 PST 2022


Author: Simon Pilgrim
Date: 2022-01-23T12:50:12Z
New Revision: 946f29028e063c768dc9b8c6e87c2eb584993df6

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

LOG: [llvm-objdump] 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-objdump/WasmDump.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-objdump/WasmDump.cpp b/llvm/tools/llvm-objdump/WasmDump.cpp
index 28311361d97e..df0a08e5b1dd 100644
--- a/llvm/tools/llvm-objdump/WasmDump.cpp
+++ b/llvm/tools/llvm-objdump/WasmDump.cpp
@@ -20,7 +20,7 @@ using namespace llvm;
 using namespace llvm::object;
 
 void objdump::printWasmFileHeader(const object::ObjectFile *Obj) {
-  const auto *File = dyn_cast<const WasmObjectFile>(Obj);
+  const auto *File = cast<const WasmObjectFile>(Obj);
 
   outs() << "Program Header:\n";
   outs() << "Version: 0x";


        


More information about the llvm-commits mailing list