[clang] [Clang] Apply exclude_from_explicit_instantiation to dllimport/dllexport (PR #168171)
Tomohiro Kashiwada via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 9 05:13:34 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;
+ }
+ }
----------------
kikairoya wrote:
I wasn't sure if `Consumer.HandleVTable(Class);` below should be called in this case; that was not called previously. However, since the VTable is actually emitted, it might need to be called.
Surprisingly, setting `DefineVTable = true` regardless `IsExplicitInstantiationDeclaration` doesn't break any tests.
The current construction was introduced in 88d292ccb86c108, but the commit doesn't mention MSVC ABI.
How do I check "correct" behavior?
https://github.com/llvm/llvm-project/pull/168171
More information about the cfe-commits
mailing list