================
@@ -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:
> Are there any cases to emit vtables, other than excluded constructors?
I'm not sure. I think they're emitted when used, which is typically by the
constructor, but maybe there could be other cases.
> In other words, if control reaches here (`if
> (IsExplicitInstantiationDeclaration`) block), can we assume that some of
> constructors are excluded?
I don't think so. Why would we be able to assume that?
>From what I understand, all that we know at this point is that 1) there's a
>use of some class's vtable, 2) that class is an explicit instantiation decl.
The previous code assumes the explicit instantiation decl means *no* methods
are emitted here, but will be emitted elsewhere (with the explicit
instantiation definition).
With the addition of ExcludeFromExplicitInstantiationAttr, that assumption no
longer holds true.
https://github.com/llvm/llvm-project/pull/168171
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits