-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Clang] Allow simpler visibility annotations when targeting win32 and mingw #133699
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4185,6 +4185,14 @@ def DLLExport : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> { | |
| let Documentation = [DLLExportDocs]; | ||
| } | ||
|
|
||
| def DLLExportOnDecl : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> { | ||
| // This attribute is only used to warn if there was a `__declspec(dllexport)` | ||
| // on a declaration, but not on the defintion of an explciit instantiation | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still this typo. |
||
| let Spellings = []; | ||
| let Subjects = SubjectList<[CXXRecord]>; | ||
| let Documentation = [InternalOnly]; | ||
| } | ||
|
|
||
| def DLLExportStaticLocal : InheritableAttr, TargetSpecificAttr<TargetHasDLLImportExport> { | ||
| // This attribute is used internally only when -fno-dllexport-inlines is | ||
| // passed. This attribute is added to inline functions of a class having the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -487,6 +487,9 @@ def Dangling : DiagGroup<"dangling", [DanglingAssignment, | |
| ReturnStackAddress]>; | ||
| def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; | ||
| def DllexportExplicitInstantiationDecl : DiagGroup<"dllexport-explicit-instantiation-decl">; | ||
| def DllexportExplicitInstantiation : | ||
| DiagGroup<"dllexport-explicit-instantiation", | ||
| [DllexportExplicitInstantiationDecl]>; | ||
| def ExcessInitializers : DiagGroup<"excess-initializers">; | ||
| def ExpansionToDefined : DiagGroup<"expansion-to-defined">; | ||
| def FlagEnum : DiagGroup<"flag-enum">; | ||
|
|
@@ -870,7 +873,8 @@ def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">; | |
|
|
||
| def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">; | ||
| def UnknownAttributes : DiagGroup<"unknown-attributes">; | ||
| def IgnoredAttributes : DiagGroup<"ignored-attributes">; | ||
| def IgnoredAttributes : DiagGroup<"ignored-attributes", | ||
| [DllexportExplicitInstantiation]>; | ||
|
Comment on lines
+876
to
+877
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this change? It does not seem correct to me given the attribute has no spelling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need some way to track that the attribute has been applied, even though it's being ignored. That's what the new attribute is for. This diagnostic is issued if the attribute has been ignored on the declaration and there is no attribute on the definition. Morally I'm still warning about the |
||
| def Attributes : DiagGroup<"attributes", [UnknownAttributes, | ||
| IgnoredAttributes]>; | ||
| def UnknownSanitizers : DiagGroup<"unknown-sanitizers">; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6606,7 +6606,10 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl *Class) { | |
| if (ClassExported && !ClassAttr->isInherited() && | ||
| TSK == TSK_ExplicitInstantiationDeclaration && | ||
| !Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) { | ||
| Class->dropAttr<DLLExportAttr>(); | ||
| if (auto *DEA = Class->getAttr<DLLExportAttr>()) { | ||
| Class->addAttr(DLLExportOnDeclAttr::Create(Context, DEA->getLoc())); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly would like this better if we just kept the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that would be possible. The main problem I see with this is that we'd have to check in a bunch of places whether the attribute is actually valid, and not just whether it exists (AFAICT it's usually assumed that if an attribute is in the AST it is valid). |
||
| Class->dropAttr<DLLExportAttr>(); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify=win32,win32-pedantic -DMS %s -Wdllexport-explicit-instantiation | ||
philnik777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -fms-extensions -verify=win32 -DMS %s -Wno-dllexport-explicit-instantiation | ||
| // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify=mingw,mingw-pedantic -DMS %s -Wdllexport-explicit-instantiation | ||
| // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify=mingw -DMS %s -Wno-dllexport-explicit-instantiation | ||
|
|
||
| template <class> | ||
| class S {}; | ||
|
|
||
| extern template class __declspec(dllexport) S<short>; // win32-pedantic-warning {{explicit instantiation declaration should not be 'dllexport'}} \ | ||
| win32-pedantic-note {{attribute is here}} | ||
| template class __declspec(dllexport) S<short>; // mingw-pedantic-warning {{'dllexport' attribute ignored on explicit instantiation definition}} | ||
|
|
||
| extern template class __declspec(dllexport) S<int>; // win32-pedantic-warning {{explicit instantiation declaration should not be 'dllexport'}} \ | ||
| win32-pedantic-note {{attribute is here}} \ | ||
| win32-note {{'dllexport' attribute on the declaration is ignored}} | ||
| template class S<int>; // win32-warning {{explicit instantiation definition is not exported without 'dllexport'}} | ||
|
|
||
| extern template class S<long>; // mingw-note {{'dllexport' attribute is missing on previous declaration}} | ||
| template class __declspec(dllexport) S<long>; // mingw-warning {{'dllexport' attribute ignored on explicit instantiation definition}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -462,6 +462,9 @@ template struct ExplicitlyInstantiatedTemplate<int>; | |
| template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func() {} }; | ||
| template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>; | ||
| template <typename T> struct ExplicitlyExportDeclaredInstantiatedTemplate { void func() {} }; | ||
| #ifdef GNU | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Urgh, I hate macros for this purpose, we have the Could you instead of 'making it worse' (even though only slightly), change it to I realize the rest of the file is still badly done, but it is at least... a step in the right direction. |
||
| // expected-note@+2 {{attribute is missing}} | ||
| #endif | ||
| extern template struct ExplicitlyExportDeclaredInstantiatedTemplate<int>; | ||
| #if not defined(MS) && not defined (WI) && not defined(PS) | ||
| // expected-warning@+2{{'dllexport' attribute ignored on explicit instantiation definition}} | ||
|
|
||
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.
Hmm... I'm not a huge fan of this TBH. An attribute for the sole purpose of diagnostics is a little novel and not particularly in keeping with our "represent the AST" nature of attributes. Is there really no way we can figure this out later?
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.
Since we don't represent invalid attribute in the AST currently I don't think there is.