Unify clang/llvm attributes for asan/tsan/msan (Clang part)

These are two related changes (one in llvm, one in clang).
LLVM: 
- rename address_safety => sanitize_address (the enum value is the same, so we preserve binary compatibility with old bitcode)
- rename thread_safety => sanitize_thread
- rename no_uninitialized_checks -> sanitize_memory

CLANG: 
- add __attribute__((no_sanitize_address)) as a synonym for __attribute__((no_address_safety_analysis))
- add __attribute__((no_sanitize_thread))
- add __attribute__((no_sanitize_memory))

for S in address thread memory
If -fsanitize=S is present and __attribute__((no_sanitize_S)) is not
set llvm attribute sanitize_S


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176076 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/sanitize-thread-attr.cpp b/test/CodeGen/sanitize-thread-attr.cpp
new file mode 100644
index 0000000..09f4db5
--- /dev/null
+++ b/test/CodeGen/sanitize-thread-attr.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread | FileCheck -check-prefix=TSAN %s
+// RUN: echo "src:%s" > %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
+
+// REQUIRES: shell
+
+// The sanitize_thread attribute should be attached to functions
+// when ThreadSanitizer is enabled, unless no_sanitize_thread attribute
+// is present.
+
+// WITHOUT:  NoTSAN1{{.*}}) #[[NOATTR:[0-9]+]]
+// BL:  NoTSAN1{{.*}}) #[[NOATTR:[0-9]+]]
+// TSAN:  NoTSAN1{{.*}}) #[[NOATTR:[0-9]+]]
+__attribute__((no_sanitize_thread))
+int NoTSAN1(int *a) { return *a; }
+
+// WITHOUT:  NoTSAN2{{.*}}) #[[NOATTR]]
+// BL:  NoTSAN2{{.*}}) #[[NOATTR]]
+// TSAN:  NoTSAN2{{.*}}) #[[NOATTR]]
+__attribute__((no_sanitize_thread))
+int NoTSAN2(int *a);
+int NoTSAN2(int *a) { return *a; }
+
+// WITHOUT:  TSANOk{{.*}}) #[[NOATTR]]
+// BL:  TSANOk{{.*}}) #[[NOATTR]]
+// TSAN: TSANOk{{.*}}) #[[WITH:[0-9]+]]
+int TSANOk(int *a) { return *a; }
+
+// WITHOUT:  TemplateTSANOk{{.*}}) #[[NOATTR]]
+// BL:  TemplateTSANOk{{.*}}) #[[NOATTR]]
+// TSAN: TemplateTSANOk{{.*}}) #[[WITH]]
+template<int i>
+int TemplateTSANOk() { return i; }
+
+// WITHOUT:  TemplateNoTSAN{{.*}}) #[[NOATTR]]
+// BL:  TemplateNoTSAN{{.*}}) #[[NOATTR]]
+// TSAN: TemplateNoTSAN{{.*}}) #[[NOATTR]]
+template<int i>
+__attribute__((no_sanitize_thread))
+int TemplateNoTSAN() { return i; }
+
+int force_instance = TemplateTSANOk<42>()
+                   + TemplateNoTSAN<42>();
+
+// Check that __cxx_global_var_init* get the sanitize_thread attribute.
+int global1 = 0;
+int global2 = *(int*)((char*)&global1+1);
+// WITHOUT: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
+// BL: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
+// TSAN: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
+
+// WITHOUT: attributes #[[NOATTR]] = { nounwind{{.*}} }
+// WITHOUT: attributes #[[GVI]] = { nounwind{{.*}} }
+// BL: attributes #[[NOATTR]] = { nounwind{{.*}} }
+// BL: attributes #[[GVI]] = { nounwind{{.*}} }
+
+// TSAN: attributes #[[NOATTR]] = { nounwind{{.*}} }
+// TSAN: attributes #[[WITH]] = { nounwind{{.*}} sanitize_thread
+// TSAN: attributes #[[GVI]] = { nounwind{{.*}} sanitize_thread