================
@@ -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>();
+          }))
----------------
kikairoya wrote:

Are there any cases to emit vtables, other than excluded constructors?
In other words, if control reaches here (` if 
(IsExplicitInstantiationDeclaration)` block), can we assume that some of 
constructors are excluded?

- If so, `IsExplicitInstantiationDeclaration && 
!HasExcludeFromExplicitInstantiationAttr` is always `false`; therefore, `if 
(!KeyFunc)` block can be removed.
- Otherwise, the template might not have an excluded constructor; then, 
non-virtual non-ctor members are unrelated to the vtable, therefore, 
`isVirtual` shouldn't be omitted.

Am I missing something else?

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