[clang] [Clang] Apply exclude_from_explicit_instantiation to dllimport/dllexport (PR #168171)
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 8 05:19:20 PST 2025
================
@@ -19108,8 +19118,23 @@ bool Sema::DefineUsedVTables() {
}
}
- if (IsExplicitInstantiationDeclaration)
+ if (IsExplicitInstantiationDeclaration) {
DefineVTable = false;
+
+ // Ensure the instance of a virtual member function which is declared
+ // with `__attribute__((exclude_from_explicit_instantiation))` is
+ // accessible from the VTable.
+ for (Decl *decl : Class->decls()) {
+ auto *Method = dyn_cast<CXXMethodDecl>(decl);
+ if (!Method || !Method->isVirtual())
+ continue;
+
+ if (Method->hasAttr<ExcludeFromExplicitInstantiationAttr>()) {
+ MarkFunctionReferenced(Loc, Method);
+ DefinedAnything = true;
+ }
+ }
----------------
zmodem wrote:
Hmm. I guess I'm confused by the contradiction of setting "DefineVTable = false" and then "ensure ... is accessible from the vtable".
The problem seems to be that some parts of the code tries to suppress vtable emission, while a different part emits it.
Would it work if we don't do the `DefineVTable = false` part, i.e. just changed the the `if (IsExplicitInstantiationDeclaration)` to something like `if (IsExplicitInstantiationDeclaration && !HasExcludeFromExplicitInstantiationAttr)`?
https://github.com/llvm/llvm-project/pull/168171
More information about the cfe-commits
mailing list