-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Don't inherit dllimport/dllexport to exclude_from_explicit_in… #65961
Merged
zmodem
merged 1 commit into
llvm:main
from
zmodem:exclude_from_explicit_instantiation_vs_dllimport
Sep 14, 2023
Merged
[clang] Don't inherit dllimport/dllexport to exclude_from_explicit_in… #65961
zmodem
merged 1 commit into
llvm:main
from
zmodem:exclude_from_explicit_instantiation_vs_dllimport
Sep 14, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…stantiation members during explicit instantiation. Fixes llvm#40363
llvmbot
added
clang
Clang issues not falling into any other category
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
labels
Sep 11, 2023
@llvm/pr-subscribers-clang Changes…stantiation members during explicit instantiation. This is a continuation of https://reviews.llvm.org/D155713 Fixes #40363Full diff: https://github.com/llvm/llvm-project/pull/65961.diff 3 Files Affected:
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 2b2b7391f88fd54..1f2bb1edd3b7be5 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -6602,6 +6602,13 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl *Class) { if (!VD && !MD) continue; + if ((TSK == TSK_ExplicitInstantiationDeclaration || + TSK == TSK_ExplicitInstantiationDefinition) && + Member->hasAttr()) { + // Skip members excluded from instantiation. + continue; + } + if (MD) { // Don't process deleted methods. if (MD->isDeleted()) diff --git a/clang/test/CodeGenCXX/attr-exclude_from_explicit_instantiation.dllimport.cpp b/clang/test/CodeGenCXX/attr-exclude_from_explicit_instantiation.dllimport.cpp new file mode 100644 index 000000000000000..b3c804839be1ee4 --- /dev/null +++ b/clang/test/CodeGenCXX/attr-exclude_from_explicit_instantiation.dllimport.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-windows -fms-extensions -emit-llvm -O0 -o - %s | FileCheck %s + +// Test that dllimport and exclude_from_explicit_instantiation work properly +// together. Specifically, we check that when exclude_from_explicit_instantiation +// is used on a method, the compiler doesn't expect it to be provided externally +// even if it is marked with dllimport. +// +// https://github.com/llvm/llvm-project/issues/40363 + +#define DLLIMPORT __declspec(dllimport) +#define DLLEXPORT __declspec(dllexport) +#define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation)) + +template +struct DLLIMPORT Foo { + EXCLUDE_FROM_EXPLICIT_INSTANTIATION void x() {} +}; + +template +struct Bar { + EXCLUDE_FROM_EXPLICIT_INSTANTIATION void x() {} +}; + +extern template struct Foo; +extern template struct DLLIMPORT Bar; + + +template +struct Baz { + EXCLUDE_FROM_EXPLICIT_INSTANTIATION void f() {} +}; + +template struct DLLEXPORT Baz; + + +void test(Foo& foo, Bar& bar, Baz& baz) { + // Not imported. + // CHECK-DAG: define linkonce_odr dso_local void @"?x@?$Foo@H@@QEAAXXZ" + foo.x(); + + // Not imported. + // CHECK-DAG: define linkonce_odr dso_local void @"?x@?$Bar@H@@QEAAXXZ" + bar.x(); + + // Not exported. + // CHECK-DAG: define linkonce_odr dso_local void @"?f@?$Baz@H@@QEAAXXZ" + baz.f(); +} diff --git a/clang/test/SemaCXX/attr-exclude_from_explicit_instantiation.dllimport.cpp b/clang/test/SemaCXX/attr-exclude_from_explicit_instantiation.dllimport.cpp new file mode 100644 index 000000000000000..bdca2d8895f516c --- /dev/null +++ b/clang/test/SemaCXX/attr-exclude_from_explicit_instantiation.dllimport.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-windows -fms-extensions -verify %s + +// Test that an entity marked as both dllimport and exclude_from_explicit_instantiation +// isn't instantiated. + +#define DLLIMPORT __declspec(dllimport) +#define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation)) + +template +struct DLLIMPORT Foo { + EXCLUDE_FROM_EXPLICIT_INSTANTIATION void x(); +}; + +template +struct Bar { + DLLIMPORT EXCLUDE_FROM_EXPLICIT_INSTANTIATION inline void x(); +}; + +template +void Foo::x() { using Fail = typename T::fail; } + +template +DLLIMPORT inline void Bar::x() { using Fail = typename T::fail; } + +// expected-no-diagnostics +template struct Foo; +template struct Bar; |
rnk
approved these changes
Sep 13, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
kstoimenov
pushed a commit
to kstoimenov/llvm-project
that referenced
this pull request
Sep 14, 2023
…stantiation members during explicit instantiation (llvm#65961) This is a continuation of https://reviews.llvm.org/D155713 Fixes llvm#40363
This was referenced Sep 14, 2023
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
…stantiation members during explicit instantiation (llvm#65961) This is a continuation of https://reviews.llvm.org/D155713 Fixes llvm#40363
zmodem
added a commit
that referenced
this pull request
Sep 20, 2023
…licit_instantiation members during explicit instantiation (#65961)" This uncovered a problem with virtual methods and exclude_from_explicit_instantiation, see #66909 Reverting until that's fixed. > This is a continuation of https://reviews.llvm.org/D155713 > > Fixes #40363 This reverts commit 84216d1.
This was referenced Sep 20, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…stantiation members during explicit instantiation.
This is a continuation of https://reviews.llvm.org/D155713
Fixes #40363