[llvm] 4635942 - [llvm-libtool-darwin] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 12:44:35 PST 2022


Author: Simon Pilgrim
Date: 2022-02-10T20:44:25Z
New Revision: 46359424bb2d6eb04508227d6c8ba433298b0ab9

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

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index 0c429c0494dba..591a884c73be5 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -364,7 +364,7 @@ class MembersBuilder {
                                  "'%s': format not supported",
                                  Member.MemberName.data());
 
-      auto *O = dyn_cast<MachOObjectFile>(ObjOrErr->get());
+      auto *O = cast<MachOObjectFile>(ObjOrErr->get());
       uint32_t FileCPUType, FileCPUSubtype;
       std::tie(FileCPUType, FileCPUSubtype) = MachO::getCPUTypeFromArchitecture(
           MachO::getArchitectureFromName(O->getArchTriple().getArchName()));


        


More information about the llvm-commits mailing list