[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
Mon Jun 10 23:41: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:

`Sema::DefineUsedVTables` is executed in all cases. However, in two phase compilation, the consumer in the first phase is not the CodeGenConsumer but the ASTWriter, so when the code get executed: https://github.com/llvm/llvm-project/blob/876c6204f12fa2738ff8ca886e664b826847d6d4/clang/lib/Sema/SemaDeclCXX.cpp#L18758-L18759

the corresponding `HandleVTable` in CodeGen Consumer won't get executed.

In the second phase, the CodeGen consumer will be the consumer, and the AST Reader will pass the interesting decls to the consumer: https://github.com/llvm/llvm-project/blob/e9a362362e03c6aea7a64473e8b8bb9140fd3855/clang/lib/Serialization/ASTReader.cpp#L8052-L8057

https://github.com/llvm/llvm-project/pull/75912


More information about the cfe-commits mailing list