1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread | FileCheck -check-prefix=TSAN %s
3 // RUN: echo "src:%s" > %t
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
8 // The sanitize_thread attribute should be attached to functions
9 // when ThreadSanitizer is enabled, unless no_sanitize_thread attribute
12 // WITHOUT: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
13 // BL: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
14 // TSAN: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
15 __attribute__((no_sanitize_thread))
16 int NoTSAN1(int *a) { return *a; }
18 // WITHOUT: NoTSAN2{{.*}}) [[NOATTR]]
19 // BL: NoTSAN2{{.*}}) [[NOATTR]]
20 // TSAN: NoTSAN2{{.*}}) [[NOATTR]]
21 __attribute__((no_sanitize_thread))
23 int NoTSAN2(int *a) { return *a; }
25 // WITHOUT: TSANOk{{.*}}) [[NOATTR]]
26 // BL: TSANOk{{.*}}) [[NOATTR]]
27 // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]]
28 int TSANOk(int *a) { return *a; }
30 // WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]]
31 // BL: TemplateTSANOk{{.*}}) [[NOATTR]]
32 // TSAN: TemplateTSANOk{{.*}}) [[WITH]]
34 int TemplateTSANOk() { return i; }
36 // WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]]
37 // BL: TemplateNoTSAN{{.*}}) [[NOATTR]]
38 // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]]
40 __attribute__((no_sanitize_thread))
41 int TemplateNoTSAN() { return i; }
43 int force_instance = TemplateTSANOk<42>()
44 + TemplateNoTSAN<42>();
46 // Check that __cxx_global_var_init* get the sanitize_thread attribute.
48 int global2 = *(int*)((char*)&global1+1);
49 // WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
50 // BL: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
51 // TSAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]]
53 // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
54 // WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind }
56 // BL: attributes [[NOATTR]] = { nounwind{{.*}} }
57 // BL: attributes [[NOATTR_NO_TF]] = { nounwind{{.*}} }
59 // TSAN: attributes [[NOATTR]] = { nounwind{{.*}} }
60 // TSAN: attributes [[WITH]] = { nounwind sanitize_thread{{.*}} }
61 // TSAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_thread }