Skip to content

Commit b6847ed

Browse files
committed
For #64088: mark vtable as used if we might emit a reference to it.
1 parent 774b614 commit b6847ed

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/Sema/SemaCast.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,14 @@ void CastOperation::CheckDynamicCast() {
935935
<< isClangCL;
936936
}
937937

938+
// For a dynamic_cast to a final type, IR generation might emit a reference
939+
// to the vtable.
940+
if (DestRecord) {
941+
auto *DestDecl = DestRecord->getAsCXXRecordDecl();
942+
if (DestDecl->isEffectivelyFinal())
943+
Self.MarkVTableUsed(OpRange.getBegin(), DestDecl);
944+
}
945+
938946
// Done. Everything else is run-time checks.
939947
Kind = CK_Dynamic;
940948
}

clang/test/CodeGenCXX/dynamic-cast-exact.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ H *exact_multi(A *a) {
7676
// CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null, %[[LABEL_FAILED]] ]
7777
return dynamic_cast<H*>(a);
7878
}
79+
80+
namespace GH64088 {
81+
// Ensure we mark the B vtable as used here, because we're going to emit a
82+
// reference to it.
83+
// CHECK: define {{.*}} @_ZN7GH640881BD0
84+
struct A { virtual ~A(); };
85+
struct B final : A { virtual ~B() = default; };
86+
B *cast(A *p) { return dynamic_cast<B*>(p); }
87+
}

0 commit comments

Comments
 (0)