Print an error for uses of __thread on targets which don't support it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69553 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 1c2b0e9..b2f1463 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -97,6 +97,8 @@
   "'__thread' is only allowed on variable declarations">;
 def err_thread_non_global : Error<
   "'__thread' variables must have global storage">;
+def err_thread_unsupported : Error<
+  "thread-local storage is unsupported for the current target">;
 
 /// Built-in functions.
 def ext_implicit_lib_function_decl : ExtWarn<
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 90df45a..64fcddd 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1734,6 +1734,8 @@
   if (D.getDeclSpec().isThreadSpecified()) {
     if (NewVD->hasLocalStorage())
       Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_thread_non_global);
+    else if (!Context.Target.isTLSSupported())
+      Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_thread_unsupported);
     else
       NewVD->setThreadSpecified(true);
   }
diff --git a/test/CodeGen/thread-specifier.c b/test/CodeGen/thread-specifier.c
index 08992a6..456f7a6 100644
--- a/test/CodeGen/thread-specifier.c
+++ b/test/CodeGen/thread-specifier.c
@@ -1,4 +1,4 @@
-// RUN: clang-cc -emit-llvm -o - %s | grep thread_local | count 4
+// RUN: clang-cc -triple i686-pc-linux-gnu -emit-llvm -o - %s | grep thread_local | count 4
 
 __thread int a;
 extern __thread int b;
diff --git a/test/Sema/thread-specifier.c b/test/Sema/thread-specifier.c
index 1d711c1..8d66e53 100644
--- a/test/Sema/thread-specifier.c
+++ b/test/Sema/thread-specifier.c
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify %s
+// RUN: clang-cc -triple i686-pc-linux-gnu -fsyntax-only -verify %s
 
 __thread int t1;
 __thread extern int t2;