[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 18:10:37 PDT 2023


rsmith added a comment.

In D154658#4479170 <https://reviews.llvm.org/D154658#4479170>, @rjmccall wrote:

> I don't think it's an intended guarantee of the Itanium ABI that the v-table will be unique, and v-tables are frequently not unique in the presence of shared libraries.

https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-general explicitly guarantees this: "[...] However, the virtual table pointers within all the objects (instances) of a particular most-derived class point to the same set of virtual tables."

> They should be unique for classes with internal linkage, but of course that's a vastly reduced domain for the optimization.

I think (hope?) we should be able to apply this to a much larger set of cases. Would it be correct to do this optimization unless the vtable might be emitted with vague linkage and non-default visibility (that is, unless we're in the odd case where people expect non-default visibility classes to be the same type across DSOs)? Or are there cases where we might be using a vtable that (eg) doesn't even have the right symbol?

> If there are multiple subobjects of the source type in the destination type, consider just casting to `void*` first instead of doing multiple comparisons.

Ha, that seems obvious in retrospect :) Will do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154658



More information about the cfe-commits mailing list