From d03ed82c9d0c2fb1a03e4f8e1f2107a5fe15ec63 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 24 Jun 2014 23:57:13 +0000 Subject: [PATCH] MS ABI: Ignore dll attributes on partial template specializations git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211648 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 7 +++++++ test/CodeGenCXX/dllexport.cpp | 14 ++++++++++++++ test/CodeGenCXX/dllimport.cpp | 15 ++++++++++++++- test/SemaCXX/dllexport.cpp | 15 +++++++++++++-- test/SemaCXX/dllimport.cpp | 9 +++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index af216d26e5..dcb6530552 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -3858,6 +3858,13 @@ DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D, SourceRange Range, } static void handleDLLAttr(Sema &S, Decl *D, const AttributeList &A) { + if (isa(D) && + S.Context.getTargetInfo().getCXXABI().isMicrosoft()) { + S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) + << A.getName(); + return; + } + unsigned Index = A.getAttributeSpellingListIndex(); Attr *NewAttr = A.getKind() == AttributeList::AT_DLLExport ? (Attr *)S.mergeDLLExportAttr(D, A.getRange(), Index) diff --git a/test/CodeGenCXX/dllexport.cpp b/test/CodeGenCXX/dllexport.cpp index b2f2e563ab..114e5a7809 100644 --- a/test/CodeGenCXX/dllexport.cpp +++ b/test/CodeGenCXX/dllexport.cpp @@ -20,6 +20,7 @@ struct External { int v; }; #define UNIQ(name) JOIN(name, __LINE__) #define USEVAR(var) int UNIQ(use)() { return var; } #define USE(func) void UNIQ(use)() { func(); } +#define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; } #define INSTVAR(var) template int var; #define INST(func) template void func(); @@ -568,3 +569,16 @@ namespace ReferencedInlineMethodInNestedClass { // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?foo@S@ReferencedInlineMethodInNestedClass@@QAEXXZ" // M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?bar@T@S@ReferencedInlineMethodInNestedClass@@QAEXXZ" } + +// MS ignores DLL attributes on partial specializations. +template struct PartiallySpecializedClassTemplate {}; +template struct __declspec(dllexport) PartiallySpecializedClassTemplate { void f() {} }; +USEMEMFUNC(PartiallySpecializedClassTemplate, f); +// M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ" +// G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv + +template struct ExplicitlySpecializedClassTemplate {}; +template <> struct __declspec(dllexport) ExplicitlySpecializedClassTemplate { void f() {} }; +USEMEMFUNC(ExplicitlySpecializedClassTemplate, f); +// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ" +// G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv diff --git a/test/CodeGenCXX/dllimport.cpp b/test/CodeGenCXX/dllimport.cpp index 6d29399885..3f3c34b8a2 100644 --- a/test/CodeGenCXX/dllimport.cpp +++ b/test/CodeGenCXX/dllimport.cpp @@ -615,7 +615,7 @@ namespace ClassTemplateStaticDef { static int x; }; template int T::x; - // M32-DAG: @"\01?x@?$T@PAX@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 + // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = available_externally dllimport global i32 0 int g() { return T::x; } } @@ -649,3 +649,16 @@ namespace PR19933 { // MSC-DAG: @"\01?x@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 43 // MSC-DAG: @"\01?y@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 0 } + +// MS ignores DLL attributes on partial specializations. +template struct PartiallySpecializedClassTemplate {}; +template struct __declspec(dllimport) PartiallySpecializedClassTemplate { void f() {} }; +USEMEMFUNC(PartiallySpecializedClassTemplate, f); +// M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ" +// G32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv + +template struct ExplicitlySpecializedClassTemplate {}; +template <> struct __declspec(dllimport) ExplicitlySpecializedClassTemplate { void f() {} }; +USEMEMFUNC(ExplicitlySpecializedClassTemplate, f); +// M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"\01?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ" +// G32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv diff --git a/test/SemaCXX/dllexport.cpp b/test/SemaCXX/dllexport.cpp index 75f9fa9d6d..362e063590 100644 --- a/test/SemaCXX/dllexport.cpp +++ b/test/SemaCXX/dllexport.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -verify -std=c++11 %s -// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -verify -std=c++1y %s +// RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -verify -std=c++11 -DMS %s +// RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -verify -std=c++1y -DMS %s // RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -verify -std=c++1y %s // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -verify -std=c++11 %s @@ -318,6 +318,17 @@ class __declspec(dllexport) ClassDecl; class __declspec(dllexport) ClassDef { }; +#ifdef MS +// expected-warning@+3{{'dllexport' attribute ignored}} +#endif +template struct PartiallySpecializedClassTemplate {}; +template struct __declspec(dllexport) PartiallySpecializedClassTemplate { void f() {} }; + +template struct ExpliciallySpecializedClassTemplate {}; +template <> struct __declspec(dllexport) ExpliciallySpecializedClassTemplate { void f() {} }; + + + //===----------------------------------------------------------------------===// // Precedence //===----------------------------------------------------------------------===// diff --git a/test/SemaCXX/dllimport.cpp b/test/SemaCXX/dllimport.cpp index 7aaf1c64b3..8df17d7627 100644 --- a/test/SemaCXX/dllimport.cpp +++ b/test/SemaCXX/dllimport.cpp @@ -991,3 +991,12 @@ template struct __declspec(dllimport) S { }; S s; } + +#ifdef MS +// expected-warning@+3{{'dllimport' attribute ignored}} +#endif +template struct PartiallySpecializedClassTemplate {}; +template struct __declspec(dllimport) PartiallySpecializedClassTemplate { void f() {} }; + +template struct ExpliciallySpecializedClassTemplate {}; +template <> struct __declspec(dllimport) ExpliciallySpecializedClassTemplate { void f() {} }; -- 2.40.0