[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 12 02:35:41 PDT 2024
================
@@ -6853,6 +6853,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
DI->completeUnusedClass(*CRD);
}
+ // If we're emitting a dynamic class from the importable module we're
+ // emitting, we always need to emit the virtual table according to the ABI
+ // requirement.
+ if (CRD->getDefinition() && CRD->isDynamicClass() &&
+ CRD->isInCurrentModuleUnit())
+ EmitVTable(CRD);
----------------
ChuanqiXu9 wrote:
> So DefineUsedVTables is called, but the ASTWriter eats the call without actually recording the fact anywhere? Okay, that makes more sense. So I guess that gives a potential alternate approach; we could teach ASTWriter to record the fact that HandleVTable was called, and replay it later.
Done. Although it is somewhat not efficient, I made it if it makes the structure more clear.
> But if we can reliably handle emitting vtables in EmitTopLevelDecl, it's probably simpler to just eliminate HandleVTable.
I tried but it looks not so easy. The problem is that `EmitTopLevelDecl` getting called on the fly during the parsing but `Sema::DefineUsedVTables` is only get called after Sema finished parsing the translation unit. So we still need some special function to replace `HandleVTable`, but then it is meaningless.
https://github.com/llvm/llvm-project/pull/75912
More information about the cfe-commits
mailing list