Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 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 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 12 | // WITHOUT: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]] |
| 13 | // BL: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]] |
| 14 | // TSAN: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]] |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 15 | __attribute__((no_sanitize_thread)) |
| 16 | int NoTSAN1(int *a) { return *a; } |
| 17 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 18 | // WITHOUT: NoTSAN2{{.*}}) [[NOATTR]] |
| 19 | // BL: NoTSAN2{{.*}}) [[NOATTR]] |
| 20 | // TSAN: NoTSAN2{{.*}}) [[NOATTR]] |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 21 | __attribute__((no_sanitize_thread)) |
| 22 | int NoTSAN2(int *a); |
| 23 | int NoTSAN2(int *a) { return *a; } |
| 24 | |
Peter Collingbourne | 915df99 | 2015-05-15 18:33:32 +0000 | [diff] [blame] | 25 | // WITHOUT: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]] |
| 26 | // BL: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]] |
| 27 | // TSAN: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]] |
| 28 | __attribute__((no_sanitize("thread"))) |
| 29 | int NoTSAN3(int *a) { return *a; } |
| 30 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 31 | // WITHOUT: TSANOk{{.*}}) [[NOATTR]] |
| 32 | // BL: TSANOk{{.*}}) [[NOATTR]] |
| 33 | // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]] |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 34 | int TSANOk(int *a) { return *a; } |
| 35 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 36 | // WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]] |
| 37 | // BL: TemplateTSANOk{{.*}}) [[NOATTR]] |
| 38 | // TSAN: TemplateTSANOk{{.*}}) [[WITH]] |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 39 | template<int i> |
| 40 | int TemplateTSANOk() { return i; } |
| 41 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 42 | // WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]] |
| 43 | // BL: TemplateNoTSAN{{.*}}) [[NOATTR]] |
| 44 | // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]] |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 45 | template<int i> |
| 46 | __attribute__((no_sanitize_thread)) |
| 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); |
Reid Kleckner | fca0338 | 2015-04-22 21:39:55 +0000 | [diff] [blame] | 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]+]] |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 58 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 59 | // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} } |
Kostya Serebryany | 4c0fc99 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 60 | |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 61 | // BL: attributes [[NOATTR]] = { nounwind{{.*}} } |
Bill Wendling | 706469b | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 62 | |
| 63 | // TSAN: attributes [[NOATTR]] = { nounwind{{.*}} } |
| 64 | // TSAN: attributes [[WITH]] = { nounwind sanitize_thread{{.*}} } |