blob: 46cab4dbf92fffccc5c6fa2456cdc5be62d7ab64 [file] [log] [blame]
Kostya Serebryany4c0fc992013-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
Bill Wendling706469b2013-02-28 22:49:57 +000012// WITHOUT: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
13// BL: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
14// TSAN: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000015__attribute__((no_sanitize_thread))
16int NoTSAN1(int *a) { return *a; }
17
Bill Wendling706469b2013-02-28 22:49:57 +000018// WITHOUT: NoTSAN2{{.*}}) [[NOATTR]]
19// BL: NoTSAN2{{.*}}) [[NOATTR]]
20// TSAN: NoTSAN2{{.*}}) [[NOATTR]]
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000021__attribute__((no_sanitize_thread))
22int NoTSAN2(int *a);
23int NoTSAN2(int *a) { return *a; }
24
Peter Collingbourne915df992015-05-15 18:33:32 +000025// WITHOUT: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
26// BL: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
27// TSAN: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
28__attribute__((no_sanitize("thread")))
29int NoTSAN3(int *a) { return *a; }
30
Bill Wendling706469b2013-02-28 22:49:57 +000031// WITHOUT: TSANOk{{.*}}) [[NOATTR]]
32// BL: TSANOk{{.*}}) [[NOATTR]]
33// TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]]
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000034int TSANOk(int *a) { return *a; }
35
Bill Wendling706469b2013-02-28 22:49:57 +000036// WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]]
37// BL: TemplateTSANOk{{.*}}) [[NOATTR]]
38// TSAN: TemplateTSANOk{{.*}}) [[WITH]]
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000039template<int i>
40int TemplateTSANOk() { return i; }
41
Bill Wendling706469b2013-02-28 22:49:57 +000042// WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]]
43// BL: TemplateNoTSAN{{.*}}) [[NOATTR]]
44// TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]]
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000045template<int i>
46__attribute__((no_sanitize_thread))
47int TemplateNoTSAN() { return i; }
48
49int force_instance = TemplateTSANOk<42>()
50 + TemplateNoTSAN<42>();
51
52// Check that __cxx_global_var_init* get the sanitize_thread attribute.
53int global1 = 0;
54int global2 = *(int*)((char*)&global1+1);
Reid Klecknerfca03382015-04-22 21:39:55 +000055// 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]+]]
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000058
Bill Wendling706469b2013-02-28 22:49:57 +000059// WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
Kostya Serebryany4c0fc992013-02-26 06:58:27 +000060
Bill Wendling706469b2013-02-28 22:49:57 +000061// BL: attributes [[NOATTR]] = { nounwind{{.*}} }
Bill Wendling706469b2013-02-28 22:49:57 +000062
63// TSAN: attributes [[NOATTR]] = { nounwind{{.*}} }
64// TSAN: attributes [[WITH]] = { nounwind sanitize_thread{{.*}} }