• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:  NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
26 // BL:  NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
27 // TSAN:  NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
28 __attribute__((no_sanitize("thread")))
NoTSAN3(int * a)29 int NoTSAN3(int *a) { return *a; }
30 
31 // WITHOUT:  TSANOk{{.*}}) [[NOATTR]]
32 // BL:  TSANOk{{.*}}) [[NOATTR]]
33 // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]]
TSANOk(int * a)34 int TSANOk(int *a) { return *a; }
35 
36 // WITHOUT:  TemplateTSANOk{{.*}}) [[NOATTR]]
37 // BL:  TemplateTSANOk{{.*}}) [[NOATTR]]
38 // TSAN: TemplateTSANOk{{.*}}) [[WITH]]
39 template<int i>
TemplateTSANOk()40 int TemplateTSANOk() { return i; }
41 
42 // WITHOUT:  TemplateNoTSAN{{.*}}) [[NOATTR]]
43 // BL:  TemplateNoTSAN{{.*}}) [[NOATTR]]
44 // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]]
45 template<int i>
46 __attribute__((no_sanitize_thread))
TemplateNoTSAN()47 int TemplateNoTSAN() { return i; }
48 
49 int force_instance = TemplateTSANOk<42>()
50                    + TemplateNoTSAN<42>();
51 
52 // Check that __cxx_global_var_init* get the sanitize_thread attribute.
53 int global1 = 0;
54 int global2 = *(int*)((char*)&global1+1);
55 // WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
56 // BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
57 // TSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
58 
59 // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
60 
61 // BL: attributes [[NOATTR]] = { nounwind{{.*}} }
62 
63 // TSAN: attributes [[NOATTR]] = { nounwind{{.*}} }
64 // TSAN: attributes [[WITH]] = { nounwind sanitize_thread{{.*}} }
65