Support the tls_model attribute (PR9788)

This adds support for the tls_model attribute. This allows the user to
choose a TLS model that is better than what LLVM would select by
default. For example, a variable might be declared as:

  __thread int x __attribute__((tls_model("initial-exec")));

if it will not be used in a shared library that is dlopen'ed.

This depends on LLVM r159077.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159078 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/thread-specifier.c b/test/CodeGen/thread-specifier.c
index a1f3e16..a2d3e62 100644
--- a/test/CodeGen/thread-specifier.c
+++ b/test/CodeGen/thread-specifier.c
@@ -3,7 +3,13 @@
 // CHECK: @b = external thread_local global
 // CHECK: @d.e = internal thread_local global
 // CHECK: @d.f = internal thread_local global
+// CHECK: @f.a = internal thread_local(initialexec) global
 // CHECK: @a = thread_local global
+// CHECK: @g = thread_local global
+// CHECK: @h = thread_local(localdynamic) global
+// CHECK: @i = thread_local(initialexec) global
+// CHECK: @j = thread_local(localexec) global
+
 __thread int a;
 extern __thread int b;
 int c() { return *&b; }
@@ -13,3 +19,12 @@
   return 0;
 }
 
+__thread int g __attribute__((tls_model("global-dynamic")));
+__thread int h __attribute__((tls_model("local-dynamic")));
+__thread int i __attribute__((tls_model("initial-exec")));
+__thread int j __attribute__((tls_model("local-exec")));
+
+int f() {
+  __thread static int a __attribute__((tls_model("initial-exec")));
+  return a++;
+}
diff --git a/test/Sema/attr-tls_model.c b/test/Sema/attr-tls_model.c
new file mode 100644
index 0000000..46f7d9b
--- /dev/null
+++ b/test/Sema/attr-tls_model.c
@@ -0,0 +1,14 @@
+// RUN: %clang -Xclang -verify -fsyntax-only %s
+
+#if !__has_attribute(tls_model)
+#error "Should support tls_model attribute"
+#endif
+
+int f() __attribute((tls_model("global-dynamic"))); // expected-error {{'tls_model' attribute only applies to thread-local variables}}
+
+int x __attribute((tls_model("global-dynamic"))); // expected-error {{'tls_model' attribute only applies to thread-local variables}}
+static __thread int y __attribute((tls_model("global-dynamic"))); // no-warning
+
+static __thread int y __attribute((tls_model("local", "dynamic"))); // expected-error {{attribute takes one argument}}
+static __thread int y __attribute((tls_model(123))); // expected-error {{argument to tls_model attribute was not a string literal}}
+static __thread int y __attribute((tls_model("foobar"))); // expected-error {{tls_model must be "global-dynamic", "local-dynamic", "initial-exec" or "local-exec"}}