Skip to content

Commit

Permalink
Reland "For #64088: mark vtable as used if we might emit a reference …
Browse files Browse the repository at this point in the history
…to it."

This reverts commit 3b34d69.
  • Loading branch information
steelannelida committed Aug 2, 2023
1 parent be0dac2 commit 9a370a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,14 @@ void CastOperation::CheckDynamicCast() {
<< isClangCL;
}

// For a dynamic_cast to a final type, IR generation might emit a reference
// to the vtable.
if (DestRecord) {
auto *DestDecl = DestRecord->getAsCXXRecordDecl();
if (DestDecl->isEffectivelyFinal())
Self.MarkVTableUsed(OpRange.getBegin(), DestDecl);
}

// Done. Everything else is run-time checks.
Kind = CK_Dynamic;
}
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGenCXX/dynamic-cast-exact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,12 @@ H *exact_multi(A *a) {
// CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null, %[[LABEL_FAILED]] ]
return dynamic_cast<H*>(a);
}

namespace GH64088 {
// Ensure we mark the B vtable as used here, because we're going to emit a
// reference to it.
// CHECK: define {{.*}} @_ZN7GH640881BD0
struct A { virtual ~A(); };
struct B final : A { virtual ~B() = default; };
B *cast(A *p) { return dynamic_cast<B*>(p); }
}

0 comments on commit 9a370a1

Please sign in to comment.