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/address-safety-attr.cpp b/test/CodeGen/address-safety-attr.cpp
index a830e23..c9f6ddc 100644
--- a/test/CodeGen/address-safety-attr.cpp
+++ b/test/CodeGen/address-safety-attr.cpp
@@ -6,20 +6,20 @@
// FIXME: %t is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp"
// REQUIRES: shell
-// The address_safety attribute should be attached to functions
-// when AddressSanitizer is enabled, unless no_address_safety_analysis attribute
+// The sanitize_address attribute should be attached to functions
+// when AddressSanitizer is enabled, unless no_sanitize_address attribute
// is present.
// WITHOUT: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
// BL: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
// ASAN: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
-__attribute__((no_address_safety_analysis))
+__attribute__((no_sanitize_address))
int NoAddressSafety1(int *a) { return *a; }
// WITHOUT: NoAddressSafety2{{.*}}) #[[NOATTR]]
// BL: NoAddressSafety2{{.*}}) #[[NOATTR]]
// ASAN: NoAddressSafety2{{.*}}) #[[NOATTR]]
-__attribute__((no_address_safety_analysis))
+__attribute__((no_sanitize_address))
int NoAddressSafety2(int *a);
int NoAddressSafety2(int *a) { return *a; }
@@ -38,13 +38,13 @@
// BL: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
// ASAN: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
template<int i>
-__attribute__((no_address_safety_analysis))
+__attribute__((no_sanitize_address))
int TemplateNoAddressSafety() { return i; }
int force_instance = TemplateAddressSafetyOk<42>()
+ TemplateNoAddressSafety<42>();
-// Check that __cxx_global_var_init* get the address_safety attribute.
+// Check that __cxx_global_var_init* get the sanitize_address attribute.
int global1 = 0;
int global2 = *(int*)((char*)&global1+1);
// WITHOUT: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
@@ -57,5 +57,5 @@
// BL: attributes #[[GVI]] = { nounwind{{.*}} }
// ASAN: attributes #[[NOATTR]] = { nounwind{{.*}} }
-// ASAN: attributes #[[WITH]] = { address_safety nounwind{{.*}} }
-// ASAN: attributes #[[GVI]] = { address_safety nounwind{{.*}} }
+// ASAN: attributes #[[WITH]] = {{.*}}sanitize_address
+// ASAN: attributes #[[GVI]] = {{.*}}sanitize_address
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
diff --git a/test/CodeGenObjCXX/address-safety-attr.mm b/test/CodeGenObjCXX/address-safety-attr.mm
index cd9abaf..1b6f0e8 100644
--- a/test/CodeGenObjCXX/address-safety-attr.mm
+++ b/test/CodeGenObjCXX/address-safety-attr.mm
@@ -17,5 +17,5 @@
@end
-// WITHOUT: attributes #0 = { nounwind{{.*}} }
-// ASAN: attributes #0 = { address_safety nounwind{{.*}} }
+// ASAN: attributes #0 = {{.*}}sanitize_address
+// WITHOUT-NOT: attributes #0 = {{.*}}sanitize_address
diff --git a/test/SemaCXX/attr-no-sanitize-address.cpp b/test/SemaCXX/attr-no-sanitize-address.cpp
new file mode 100644
index 0000000..dc4d797
--- /dev/null
+++ b/test/SemaCXX/attr-no-sanitize-address.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
+
+#if !__has_attribute(no_sanitize_address)
+#error "Should support no_sanitize_address"
+#endif
+
+void noanal_fun() NO_SANITIZE_ADDRESS;
+
+void noanal_fun_args() __attribute__((no_sanitize_address(1))); // \
+ // expected-error {{attribute takes no arguments}}
+
+int noanal_testfn(int y) NO_SANITIZE_ADDRESS;
+
+int noanal_testfn(int y) {
+ int x NO_SANITIZE_ADDRESS = y; // \
+ // expected-error {{'no_sanitize_address' attribute only applies to functions and methods}}
+ return x;
+}
+
+int noanal_test_var NO_SANITIZE_ADDRESS; // \
+ // expected-error {{'no_sanitize_address' attribute only applies to functions and methods}}
+
+class NoanalFoo {
+ private:
+ int test_field NO_SANITIZE_ADDRESS; // \
+ // expected-error {{'no_sanitize_address' attribute only applies to functions and methods}}
+ void test_method() NO_SANITIZE_ADDRESS;
+};
+
+class NO_SANITIZE_ADDRESS NoanalTestClass { // \
+ // expected-error {{'no_sanitize_address' attribute only applies to functions and methods}}
+};
+
+void noanal_fun_params(int lvar NO_SANITIZE_ADDRESS); // \
+ // expected-error {{'no_sanitize_address' attribute only applies to functions and methods}}
diff --git a/test/SemaCXX/attr-no-sanitize-memory.cpp b/test/SemaCXX/attr-no-sanitize-memory.cpp
new file mode 100644
index 0000000..84acdac
--- /dev/null
+++ b/test/SemaCXX/attr-no-sanitize-memory.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
+
+#if !__has_attribute(no_sanitize_memory)
+#error "Should support no_sanitize_memory"
+#endif
+
+void noanal_fun() NO_SANITIZE_MEMORY;
+
+void noanal_fun_args() __attribute__((no_sanitize_memory(1))); // \
+ // expected-error {{attribute takes no arguments}}
+
+int noanal_testfn(int y) NO_SANITIZE_MEMORY;
+
+int noanal_testfn(int y) {
+ int x NO_SANITIZE_MEMORY = y; // \
+ // expected-error {{'no_sanitize_memory' attribute only applies to functions and methods}}
+ return x;
+}
+
+int noanal_test_var NO_SANITIZE_MEMORY; // \
+ // expected-error {{'no_sanitize_memory' attribute only applies to functions and methods}}
+
+class NoanalFoo {
+ private:
+ int test_field NO_SANITIZE_MEMORY; // \
+ // expected-error {{'no_sanitize_memory' attribute only applies to functions and methods}}
+ void test_method() NO_SANITIZE_MEMORY;
+};
+
+class NO_SANITIZE_MEMORY NoanalTestClass { // \
+ // expected-error {{'no_sanitize_memory' attribute only applies to functions and methods}}
+};
+
+void noanal_fun_params(int lvar NO_SANITIZE_MEMORY); // \
+ // expected-error {{'no_sanitize_memory' attribute only applies to functions and methods}}
diff --git a/test/SemaCXX/attr-no-sanitize-thread.cpp b/test/SemaCXX/attr-no-sanitize-thread.cpp
new file mode 100644
index 0000000..50960c4
--- /dev/null
+++ b/test/SemaCXX/attr-no-sanitize-thread.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
+
+#if !__has_attribute(no_sanitize_thread)
+#error "Should support no_sanitize_thread"
+#endif
+
+void noanal_fun() NO_SANITIZE_THREAD;
+
+void noanal_fun_args() __attribute__((no_sanitize_thread(1))); // \
+ // expected-error {{attribute takes no arguments}}
+
+int noanal_testfn(int y) NO_SANITIZE_THREAD;
+
+int noanal_testfn(int y) {
+ int x NO_SANITIZE_THREAD = y; // \
+ // expected-error {{'no_sanitize_thread' attribute only applies to functions and methods}}
+ return x;
+}
+
+int noanal_test_var NO_SANITIZE_THREAD; // \
+ // expected-error {{'no_sanitize_thread' attribute only applies to functions and methods}}
+
+class NoanalFoo {
+ private:
+ int test_field NO_SANITIZE_THREAD; // \
+ // expected-error {{'no_sanitize_thread' attribute only applies to functions and methods}}
+ void test_method() NO_SANITIZE_THREAD;
+};
+
+class NO_SANITIZE_THREAD NoanalTestClass { // \
+ // expected-error {{'no_sanitize_thread' attribute only applies to functions and methods}}
+};
+
+void noanal_fun_params(int lvar NO_SANITIZE_THREAD); // \
+ // expected-error {{'no_sanitize_thread' attribute only applies to functions and methods}}