r237337 - [MS ABI] __declspec(thread) behaves like thread_local in MSVC 2015

David Majnemer david.majnemer at gmail.com
Wed May 13 22:19:23 PDT 2015


Author: majnemer
Date: Thu May 14 00:19:23 2015
New Revision: 237337

URL: http://llvm.org/viewvc/llvm-project?rev=237337&view=rev
Log:
[MS ABI] __declspec(thread) behaves like thread_local in MSVC 2015

MSVC 2015 changed __declspec(thread) to make it behave like C++11's
thread_local keyword instead of acting similarly to __thread.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/SemaCXX/declspec-thread.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=237337&r1=237336&r2=237337&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu May 14 00:19:23 2015
@@ -1795,9 +1795,12 @@ void VarDecl::setStorageClass(StorageCla
 VarDecl::TLSKind VarDecl::getTLSKind() const {
   switch (VarDeclBits.TSCSpec) {
   case TSCS_unspecified:
-    if (hasAttr<ThreadAttr>())
-      return TLS_Static;
-    return TLS_None;
+    if (!hasAttr<ThreadAttr>())
+      return TLS_None;
+    return getASTContext().getLangOpts().isCompatibleWithMSVC(
+               LangOptions::MSVC2015)
+               ? TLS_Dynamic
+               : TLS_Static;
   case TSCS___thread: // Fall through.
   case TSCS__Thread_local:
       return TLS_Static;

Modified: cfe/trunk/test/SemaCXX/declspec-thread.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/declspec-thread.cpp?rev=237337&r1=237336&r2=237337&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/declspec-thread.cpp (original)
+++ cfe/trunk/test/SemaCXX/declspec-thread.cpp Thu May 14 00:19:23 2015
@@ -1,17 +1,30 @@
-// RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -fms-extensions -verify %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -fms-extensions -fms-compatibility-version=18.00 -verify %s
+// RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -fms-extensions -fms-compatibility-version=19.00 -verify %s
 
 __thread __declspec(thread) int a; // expected-error {{already has a thread-local storage specifier}}
 __declspec(thread) __thread int b; // expected-error {{already has a thread-local storage specifier}}
 __declspec(thread) int c(); // expected-warning {{only applies to variables}}
 __declspec(thread) int d;
 int foo();
+#if _MSC_VER >= 1900
+__declspec(thread) int e = foo();
+#else
 __declspec(thread) int e = foo(); // expected-error {{must be a constant expression}} expected-note {{thread_local}}
+#endif
 
 struct HasCtor { HasCtor(); int x; };
+#if _MSC_VER >= 1900
+__declspec(thread) HasCtor f;
+#else
 __declspec(thread) HasCtor f; // expected-error {{must be a constant expression}} expected-note {{thread_local}}
+#endif
 
 struct HasDtor { ~HasDtor(); int x; };
-__declspec(thread) HasDtor g; // expected-error {{non-trivial destruction}} expected-note {{thread_local}}
+#if _MSC_VER >= 1900
+__declspec(thread) HasDtor g;
+#else
+__declspec(thread) HasCtor f; // expected-error {{must be a constant expression}} expected-note {{thread_local}}
+#endif
 
 struct HasDefaultedDefaultCtor {
   HasDefaultedDefaultCtor() = default;





More information about the cfe-commits mailing list