[all-commits] [llvm/llvm-project] 494697: [CodeGen] Disable exact dynamic_cast for duplicabl...

Akira Hatanaka via All-commits all-commits at lists.llvm.org
Thu Jul 9 09:13:11 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 494697f79f5f7f6b40b78c8f49a98588ee87f1bd
      https://github.com/llvm/llvm-project/commit/494697f79f5f7f6b40b78c8f49a98588ee87f1bd
  Author: Akira Hatanaka <ahatanak at gmail.com>
  Date:   2026-07-09 (Thu, 09 Jul 2026)

  Changed paths:
    M clang/include/clang/Basic/CodeGenOptions.def
    M clang/include/clang/Basic/CodeGenOptions.h
    M clang/include/clang/Basic/TargetInfo.h
    M clang/include/clang/Options/Options.td
    M clang/lib/Basic/TargetInfo.cpp
    M clang/lib/Basic/Targets/OSTargets.h
    M clang/lib/CodeGen/ItaniumCXXABI.cpp
    M clang/test/CodeGenCXX/dynamic-cast-exact-disabled.cpp
    M clang/test/CodeGenCXX/dynamic-cast-exact.cpp
    M clang/test/CodeGenCXX/ptrauth-dynamic-cast-exact.cpp

  Log Message:
  -----------
  [CodeGen] Disable exact dynamic_cast for duplicable vtables (#205929)

Add `TargetInfo::getVTableUniqueness()`, which returns a
`VTableUniquenessKind` that describes whether a target's ABI guarantees
a class's vtable has a single address program-wide. Apple Mach-O targets
return `UniqueIfStrongLinkage`, since a vague-linkage (weak) vtable may
be autohidden and duplicated per image, while a vtable with strong
linkage (e.g., a class with a key function) still has a unique address.
Every other target keeps the default, `AlwaysUnique`.

Rename the `CodeGenOpts` flag backing `-f[no-]assume-unique-vtables`
from `AssumeUniqueVTables` to `DisableExactDynamicCast`, defaulting to
false so the optimization stays on unless `-fno-assume-unique-vtables`
is given. Use it together with `getVTableUniqueness()` in
`ItaniumCXXABI::hasUniqueVTablePointer()` so a weak vtable on a target
that may duplicate vtables no longer qualifies for the exact
`dynamic_cast` optimization; a vtable with a key function, or any vtable
on a target with `AlwaysUnique` semantics, is unaffected.

Fixes https://github.com/llvm/llvm-project/issues/120129

rdar://129380573



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list