From 5e64528195b97d5992aafb4dd90376d4e03a5d85 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 llvm-svn: 211648 --- clang/lib/Sema/SemaDeclAttr.cpp | 7 +++++++ clang/test/CodeGenCXX/dllexport.cpp | 14 ++++++++++++++ clang/test/CodeGenCXX/dllimport.cpp | 15 ++++++++++++++- clang/test/SemaCXX/dllexport.cpp | 15 +++++++++++++-- clang/test/SemaCXX/dllimport.cpp | 9 +++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index af216d2..dcb6530 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/CodeGenCXX/dllexport.cpp b/clang/test/CodeGenCXX/dllexport.cpp index b2f2e56..114e5a7 100644 --- a/clang/test/CodeGenCXX/dllexport.cpp +++ b/clang/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/clang/test/CodeGenCXX/dllimport.cpp b/clang/test/CodeGenCXX/dllimport.cpp index 6d29399..3f3c34b 100644 --- a/clang/test/CodeGenCXX/dllimport.cpp +++ b/clang/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/clang/test/SemaCXX/dllexport.cpp b/clang/test/SemaCXX/dllexport.cpp index 75f9fa9..362e063 100644 --- a/clang/test/SemaCXX/dllexport.cpp +++ b/clang/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/clang/test/SemaCXX/dllimport.cpp b/clang/test/SemaCXX/dllimport.cpp index 7aaf1c6..8df17d7 100644 --- a/clang/test/SemaCXX/dllimport.cpp +++ b/clang/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.7.4