xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/sanitize-thread-attr.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
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
5 
6 // REQUIRES: shell
7 
8 // The sanitize_thread attribute should be attached to functions
9 // when ThreadSanitizer is enabled, unless no_sanitize_thread attribute
10 // is present.
11 
12 // WITHOUT:  NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
13 // BL:  NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
14 // TSAN:  NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
15 __attribute__((no_sanitize_thread))
NoTSAN1(int * a)16 int NoTSAN1(int *a) { return *a; }
17 
18 // WITHOUT:  NoTSAN2{{.*}}) [[NOATTR]]
19 // BL:  NoTSAN2{{.*}}) [[NOATTR]]
20 // TSAN:  NoTSAN2{{.*}}) [[NOATTR]]
21 __attribute__((no_sanitize_thread))
22 int NoTSAN2(int *a);
NoTSAN2(int * a)23 int NoTSAN2(int *a) { return *a; }
24 
25 // WITHOUT:  TSANOk{{.*}}) [[NOATTR]]
26 // BL:  TSANOk{{.*}}) [[NOATTR]]
27 // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]]
TSANOk(int * a)28 int TSANOk(int *a) { return *a; }
29 
30 // WITHOUT:  TemplateTSANOk{{.*}}) [[NOATTR]]
31 // BL:  TemplateTSANOk{{.*}}) [[NOATTR]]
32 // TSAN: TemplateTSANOk{{.*}}) [[WITH]]
33 template<int i>
TemplateTSANOk()34 int TemplateTSANOk() { return i; }
35 
36 // WITHOUT:  TemplateNoTSAN{{.*}}) [[NOATTR]]
37 // BL:  TemplateNoTSAN{{.*}}) [[NOATTR]]
38 // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]]
39 template<int i>
40 __attribute__((no_sanitize_thread))
TemplateNoTSAN()41 int TemplateNoTSAN() { return i; }
42 
43 int force_instance = TemplateTSANOk<42>()
44                    + TemplateNoTSAN<42>();
45 
46 // Check that __cxx_global_var_init* get the sanitize_thread attribute.
47 int global1 = 0;
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]+]]
52 
53 // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
54 // WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind }
55 
56 // BL: attributes [[NOATTR]] = { nounwind{{.*}} }
57 // BL: attributes [[NOATTR_NO_TF]] = { nounwind{{.*}} }
58 
59 // TSAN: attributes [[NOATTR]] = { nounwind{{.*}} }
60 // TSAN: attributes [[WITH]] = { nounwind sanitize_thread{{.*}} }
61 // TSAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_thread }
62