Skip to content

[clang] Make PS template DLL attribute propagation the same as MSVC #92549

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

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11124,8 +11124,7 @@ DeclResult Sema::ActOnExplicitInstantiation(
Def->setTemplateSpecializationKind(TSK);

if (!getDLLAttr(Def) && getDLLAttr(Specialization) &&
(Context.getTargetInfo().shouldDLLImportComdatSymbols() &&
!Context.getTargetInfo().getTriple().isPS())) {
Context.getTargetInfo().shouldDLLImportComdatSymbols()) {
// An explicit instantiation definition can add a dll attribute to a
// template with a previous instantiation declaration. MinGW doesn't
// allow this.
Expand All @@ -11142,8 +11141,7 @@ DeclResult Sema::ActOnExplicitInstantiation(
bool NewlyDLLExported =
!PreviouslyDLLExported && Specialization->hasAttr<DLLExportAttr>();
if (Old_TSK == TSK_ImplicitInstantiation && NewlyDLLExported &&
(Context.getTargetInfo().shouldDLLImportComdatSymbols() &&
!Context.getTargetInfo().getTriple().isPS())) {
Context.getTargetInfo().shouldDLLImportComdatSymbols()) {
// An explicit instantiation definition can add a dll attribute to a
// template with a previous implicit instantiation. MinGW doesn't allow
// this. We limit clang to only adding dllexport, to avoid potentially
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=c++11 -triple i686-windows -fdeclspec -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MS
// RUN: %clang_cc1 -std=c++11 -triple i686-windows-itanium -fdeclspec -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-IA
// RUN: %clang_cc1 -std=c++11 -triple x86_64-scei-ps4 -fdeclspec -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-PS4
// RUN: %clang_cc1 -std=c++11 -triple x86_64-sie-ps5 -fdeclspec -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-PS4
// RUN: %clang_cc1 -std=c++11 -triple i686-windows-itanium -fdeclspec -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -std=c++11 -triple x86_64-scei-ps4 -fdeclspec -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -std=c++11 -triple x86_64-sie-ps5 -fdeclspec -emit-llvm %s -o - | FileCheck %s

template <typename>
struct s {};
Expand All @@ -15,8 +15,5 @@ template class __declspec(dllexport) t<char>;
// CHECK-MS: dllexport {{.*}} @"??4?$t@D@@QAEAAV0@ABV0@@Z"
// CHECK-MS: dllexport {{.*}} @"??4?$s@D@@QAEAAU0@ABU0@@Z"

// CHECK-IA: dllexport {{.*}} @_ZN1tIcEaSERKS0_
// CHECK-IA: dllexport {{.*}} @_ZN1sIcEaSERKS0_

// CHECK-PS4-NOT: @_ZN1tIcEaSERKS0_
// CHECK-PS4-NOT: @_ZN1sIcEaSERKS0_
// CHECK: dllexport {{.*}} @_ZN1tIcEaSERKS0_
// CHECK: dllexport {{.*}} @_ZN1sIcEaSERKS0_
18 changes: 7 additions & 11 deletions clang/test/CodeGenCXX/windows-itanium-dllexport.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -emit-llvm -triple i686-windows-itanium -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,WI
// RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps4 -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,PS4
// RUN: %clang_cc1 -emit-llvm -triple x86_64-sie-ps5 -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,PS4
// RUN: %clang_cc1 -emit-llvm -triple x86_64-scei-ps4 -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,PS
// RUN: %clang_cc1 -emit-llvm -triple x86_64-sie-ps5 -fdeclspec %s -o - | FileCheck %s --check-prefixes=CHECK,PS

#define JOIN2(x, y) x##y
#define JOIN(x, y) JOIN2(x, y)
Expand All @@ -27,18 +27,14 @@ template class __declspec(dllexport) c<int>;
extern template class c<char>;
template class __declspec(dllexport) c<char>;

// WI: define {{.*}} dllexport {{.*}} @_ZN1cIcEaSERKS0_
// WI: define {{.*}} dllexport {{.*}} @_ZN1cIcE1fEv
// PS4-NOT: @_ZN1cIcEaSERKS0_
// PS4: define weak_odr void @_ZN1cIcE1fEv
// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIcEaSERKS0_
// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIcE1fEv

c<double> g;
template class __declspec(dllexport) c<double>;

// WI: define {{.*}} dllexport {{.*}} @_ZN1cIdEaSERKS0_
// WI: define {{.*}} dllexport {{.*}} @_ZN1cIdE1fEv
// PS4-NOT: @_ZN1cIdEaSERKS0_
// PS4: define weak_odr void @_ZN1cIdE1fEv
// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIdEaSERKS0_
// CHECK: define {{.*}} dllexport {{.*}} @_ZN1cIdE1fEv

template <class T>
struct outer {
Expand All @@ -59,4 +55,4 @@ USEMEMFUNC(outer<char>::inner, f)

// CHECK-DAG: declare dllimport {{.*}} @_ZN5outerIcE1fEv
// WI-DAG: define {{.*}} @_ZN5outerIcE5inner1fEv
// PS4-DAG: declare {{.*}} @_ZN5outerIcE5inner1fEv
// PS-DAG: declare {{.*}} @_ZN5outerIcE5inner1fEv
Loading