blob: fe5d81026db2108b9cbc5a9d6971f9cc73e02efd [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
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000012// WITHOUT: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
13// BL: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
14// TSAN: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000015__attribute__((no_sanitize_thread))
16int NoTSAN1(int *a) { return *a; }
17
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000018// WITHOUT: NoTSAN2{{.*}}) [[NOATTR]]
19// BL: NoTSAN2{{.*}}) [[NOATTR]]
20// TSAN: NoTSAN2{{.*}}) [[NOATTR]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000021__attribute__((no_sanitize_thread))
22int NoTSAN2(int *a);
23int NoTSAN2(int *a) { return *a; }
24
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000025// WITHOUT: TSANOk{{.*}}) [[NOATTR]]
26// BL: TSANOk{{.*}}) [[NOATTR]]
27// TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000028int TSANOk(int *a) { return *a; }
29
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000030// WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]]
31// BL: TemplateTSANOk{{.*}}) [[NOATTR]]
32// TSAN: TemplateTSANOk{{.*}}) [[WITH]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000033template<int i>
34int TemplateTSANOk() { return i; }
35
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000036// WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]]
37// BL: TemplateNoTSAN{{.*}}) [[NOATTR]]
38// TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000039template<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);
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000049// 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]+]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000052
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000053// WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
54// WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind }
Kostya Serebryany85aee962013-02-26 06:58:27 +000055
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000056// 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 }