blob: 09f4db57503138383cea3e5cadad15340113899c [file] [log] [blame]
Kostya Serebryany85aee962013-02-26 06:58:27 +00001// 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))
16int NoTSAN1(int *a) { return *a; }
17
18// WITHOUT: NoTSAN2{{.*}}) #[[NOATTR]]
19// BL: NoTSAN2{{.*}}) #[[NOATTR]]
20// TSAN: NoTSAN2{{.*}}) #[[NOATTR]]
21__attribute__((no_sanitize_thread))
22int NoTSAN2(int *a);
23int NoTSAN2(int *a) { return *a; }
24
25// WITHOUT: TSANOk{{.*}}) #[[NOATTR]]
26// BL: TSANOk{{.*}}) #[[NOATTR]]
27// TSAN: TSANOk{{.*}}) #[[WITH:[0-9]+]]
28int TSANOk(int *a) { return *a; }
29
30// WITHOUT: TemplateTSANOk{{.*}}) #[[NOATTR]]
31// BL: TemplateTSANOk{{.*}}) #[[NOATTR]]
32// TSAN: TemplateTSANOk{{.*}}) #[[WITH]]
33template<int i>
34int TemplateTSANOk() { return i; }
35
36// WITHOUT: TemplateNoTSAN{{.*}}) #[[NOATTR]]
37// BL: TemplateNoTSAN{{.*}}) #[[NOATTR]]
38// TSAN: TemplateNoTSAN{{.*}}) #[[NOATTR]]
39template<int i>
40__attribute__((no_sanitize_thread))
41int TemplateNoTSAN() { return i; }
42
43int force_instance = TemplateTSANOk<42>()
44 + TemplateNoTSAN<42>();
45
46// Check that __cxx_global_var_init* get the sanitize_thread attribute.
47int global1 = 0;
48int global2 = *(int*)((char*)&global1+1);
49// WITHOUT: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
50// BL: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
51// TSAN: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
52
53// WITHOUT: attributes #[[NOATTR]] = { nounwind{{.*}} }
54// WITHOUT: attributes #[[GVI]] = { nounwind{{.*}} }
55// BL: attributes #[[NOATTR]] = { nounwind{{.*}} }
56// BL: attributes #[[GVI]] = { nounwind{{.*}} }
57
58// TSAN: attributes #[[NOATTR]] = { nounwind{{.*}} }
59// TSAN: attributes #[[WITH]] = { nounwind{{.*}} sanitize_thread
60// TSAN: attributes #[[GVI]] = { nounwind{{.*}} sanitize_thread