[PATCH] D63175: [MS] Pretend constexpr variable template specializations are inline
Reid Kleckner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 12 11:51:48 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363191: [MS] Pretend constexpr variable template specializations are inline (authored by rnk, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D63175?vs=204190&id=204339#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63175/new/
https://reviews.llvm.org/D63175
Files:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGenCXX/ms-constexpr-var-template.cpp
Index: cfe/trunk/test/CodeGenCXX/ms-constexpr-var-template.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/ms-constexpr-var-template.cpp
+++ cfe/trunk/test/CodeGenCXX/ms-constexpr-var-template.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-windows-msvc -fms-compatibility %s -o - | FileCheck %s
+
+template <typename> constexpr bool _Is_integer = false;
+template <> constexpr bool _Is_integer<int> = true;
+template <> constexpr bool _Is_integer<char> = false;
+extern "C" const bool *escape = &_Is_integer<int>;
+
+// CHECK: @"??$_Is_integer at H@@3_NB" = linkonce_odr dso_local constant i8 1, comdat, align 1
+// Should not emit _Is_integer<char>, since it's not referenced.
+// CHECK-NOT: @"??$_Is_integer at D@@3_NB"
+// CHECK: @escape = dso_local global i8* @"??$_Is_integer at H@@3_NB", align 8
Index: cfe/trunk/lib/AST/ASTContext.cpp
===================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -9799,10 +9799,22 @@
return StrongLinkage;
case TSK_ExplicitSpecialization:
- return Context.getTargetInfo().getCXXABI().isMicrosoft() &&
- VD->isStaticDataMember()
- ? GVA_StrongODR
- : StrongLinkage;
+ if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
+ // If this is a fully specialized constexpr variable template, pretend it
+ // was marked inline. MSVC 14.21.27702 headers define _Is_integral in a
+ // header this way, and we don't want to emit non-discardable definitions
+ // of these variables in every TU that includes <type_traits>. This
+ // behavior can be removed if the headers change to explicitly mark such
+ // variable template specializations inline.
+ if (isa<VarTemplateSpecializationDecl>(VD) && VD->isConstexpr())
+ return GVA_DiscardableODR;
+
+ // Use ODR linkage for static data members of fully specialized templates
+ // to prevent duplicate definition errors with MSVC.
+ if (VD->isStaticDataMember())
+ return GVA_StrongODR;
+ }
+ return StrongLinkage;
case TSK_ExplicitInstantiationDefinition:
return GVA_StrongODR;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63175.204339.patch
Type: text/x-patch
Size: 2252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190612/42f90e5e/attachment.bin>
More information about the cfe-commits
mailing list