[PATCH] D154658: Optimize emission of `dynamic_cast` to final classes.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 14:58:14 PDT 2023


rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added subscribers: nlopes, mgrang.
Herald added a project: All.
rsmith requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

- When the destination is a final class type that does not derive from the source type, the cast always fails and is now emitted as a null pointer or call to __cxa_bad_cast.

- When the destination is a final class type that does derive from the source type, emit a direct comparison against the corresponding base class vptr value(s). There may be more than one such value in the case of multiple inheritance; check them all.

For now, this is supported only for the Itanium ABI. I expect the same thing is
possible for the MS ABI too, but I don't know what guarantees are made about
vfptr uniqueness.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154658

Files:
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/dynamic-cast-always-null.cpp
  clang/test/CodeGenCXX/dynamic-cast-exact.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154658.537893.patch
Type: text/x-patch
Size: 18807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230706/a7864864/attachment-0001.bin>


More information about the cfe-commits mailing list