[PATCH] D139452: [LLVM] Use dyn_cast instead of cast for objects that require it

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 12:54:29 PST 2022


MaskRay added a comment.

I agree that the call site uses are somewhat problematic, but `cast` has stronger guarantee. Do you have a test case to trigger a code path that `dyn_cast` returns nullptr? If not, the `if` statement should just be replaced with unconditional `cast`.



================
Comment at: llvm/lib/Object/ELFObjectFile.cpp:803
     return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex);
-  if (const auto *Obj = cast<ELF64BEObjectFile>(this))
+  if (const auto *Obj = dyn_cast<ELF64BEObjectFile>(this))
     return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex);
----------------
This can just used `cast` and delete `llvm_unreachable`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139452/new/

https://reviews.llvm.org/D139452



More information about the llvm-commits mailing list