================
@@ -19109,7 +19119,17 @@ bool Sema::DefineUsedVTables() {
         }
       }
 
-      if (IsExplicitInstantiationDeclaration)
+      if (IsExplicitInstantiationDeclaration &&
+          llvm::none_of(Class->decls(), [](Decl *decl) {
+            // If the class has a virtual member function declared with
+            // `__attribute__((exclude_from_explicit_instantiation))`, the
+            // explicit instantiation declaration shouldn't suppress emitting
+            // the vtable to ensure that the excluded member function is
+            // accessible through the vtable.
+            auto *Method = dyn_cast<CXXMethodDecl>(decl);
+            return Method && Method->isVirtual() &&
+                   Method->hasAttr<ExcludeFromExplicitInstantiationAttr>();
+          }))
----------------
zmodem wrote:

> Why are non-virtual functions allowed to affect vtables?

When there's no key function, emitting a constructor will trigger emitting the 
vtable, because the constructor needs to set the vptr to point to it.

That's why the reasoning above about "vtable will live with the explicit 
instantiation" won't hold if the constructor is excluded.

https://github.com/llvm/llvm-project/pull/168171
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to