Kostya Serebryany | 85aee96 | 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 | be9e8bf | 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 | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 15 | __attribute__((no_sanitize_thread)) |
| 16 | int NoTSAN1(int *a) { return *a; } |
| 17 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 18 | // WITHOUT: NoTSAN2{{.*}}) [[NOATTR]] |
| 19 | // BL: NoTSAN2{{.*}}) [[NOATTR]] |
| 20 | // TSAN: NoTSAN2{{.*}}) [[NOATTR]] |
Kostya Serebryany | 85aee96 | 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 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 25 | // WITHOUT: TSANOk{{.*}}) [[NOATTR]] |
| 26 | // BL: TSANOk{{.*}}) [[NOATTR]] |
| 27 | // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]] |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 28 | int TSANOk(int *a) { return *a; } |
| 29 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 30 | // WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]] |
| 31 | // BL: TemplateTSANOk{{.*}}) [[NOATTR]] |
| 32 | // TSAN: TemplateTSANOk{{.*}}) [[WITH]] |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 33 | template<int i> |
| 34 | int TemplateTSANOk() { return i; } |
| 35 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 36 | // WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]] |
| 37 | // BL: TemplateNoTSAN{{.*}}) [[NOATTR]] |
| 38 | // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]] |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 39 | template<int i> |
| 40 | __attribute__((no_sanitize_thread)) |
| 41 | int TemplateNoTSAN() { return i; } |
| 42 | |
| 43 | int force_instance = TemplateTSANOk<42>() |
| 44 | + TemplateNoTSAN<42>(); |
| 45 | |
| 46 | // Check that __cxx_global_var_init* get the sanitize_thread attribute. |
| 47 | int global1 = 0; |
| 48 | int global2 = *(int*)((char*)&global1+1); |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 49 | // 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 Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 52 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 53 | // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} } |
| 54 | // WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind } |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 55 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 56 | // 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 } |