Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / sanitize-thread-attr.cpp
blob15ae3a16df696ab46f0e2faead25c95840428f4d
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" | sed -e 's/\\/\\\\/g' > %t
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread -fsanitize-ignorelist=%t | FileCheck -check-prefix=BL %s
6 // The sanitize_thread attribute should be attached to functions
7 // when ThreadSanitizer is enabled, unless no_sanitize_thread attribute
8 // is present.
10 // WITHOUT: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
11 // BL: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
12 // TSAN: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]]
13 __attribute__((no_sanitize_thread))
14 int NoTSAN1(int *a) { return *a; }
16 // WITHOUT: NoTSAN2{{.*}}) [[NOATTR]]
17 // BL: NoTSAN2{{.*}}) [[NOATTR]]
18 // TSAN: NoTSAN2{{.*}}) [[NOATTR]]
19 __attribute__((no_sanitize_thread))
20 int NoTSAN2(int *a);
21 int NoTSAN2(int *a) { return *a; }
23 // WITHOUT: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
24 // BL: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
25 // TSAN: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]]
26 __attribute__((no_sanitize("thread")))
27 int NoTSAN3(int *a) { return *a; }
29 // WITHOUT: TSANOk{{.*}}) [[NOATTR]]
30 // BL: TSANOk{{.*}}) [[NOATTR]]
31 // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]]
32 int TSANOk(int *a) { return *a; }
34 // WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]]
35 // BL: TemplateTSANOk{{.*}}) [[NOATTR]]
36 // TSAN: TemplateTSANOk{{.*}}) [[WITH]]
37 template<int i>
38 int TemplateTSANOk() { return i; }
40 // WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]]
41 // BL: TemplateNoTSAN{{.*}}) [[NOATTR]]
42 // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]]
43 template<int i>
44 __attribute__((no_sanitize_thread))
45 int TemplateNoTSAN() { return i; }
47 int force_instance = TemplateTSANOk<42>()
48 + TemplateNoTSAN<42>();
50 // Check that __cxx_global_var_init* get the sanitize_thread attribute.
51 int global1 = 0;
52 int global2 = *(int*)((char*)&global1+1);
53 // WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
54 // BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
55 // TSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
57 // WITHOUT: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
59 // BL: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
61 // TSAN: attributes [[NOATTR]] = { mustprogress noinline nounwind{{.*}} }
62 // TSAN: attributes [[WITH]] = { noinline nounwind sanitize_thread{{.*}} }