Bill Wendling | 0c67fc9 | 2013-02-22 00:04:55 +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=address | FileCheck -check-prefix=ASAN %s |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 3 | // RUN: echo "src:%s" > %t.file.blacklist |
| 4 | // RUN: echo "fun:*BlacklistedFunction*" > %t.func.blacklist |
| 5 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t.file.blacklist | FileCheck -check-prefix=BLFILE %s |
| 6 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t.func.blacklist | FileCheck -check-prefix=BLFUNC %s |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 7 | |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 8 | // FIXME: %t.file.blacklist is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp" |
NAKAMURA Takumi | ea8bca7 | 2013-01-18 14:11:04 +0000 | [diff] [blame] | 9 | // REQUIRES: shell |
| 10 | |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 11 | // The sanitize_address attribute should be attached to functions |
| 12 | // when AddressSanitizer is enabled, unless no_sanitize_address attribute |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 13 | // is present. |
| 14 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 15 | // WITHOUT: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 16 | // BLFILE: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] |
| 17 | // BLFUNC: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 18 | // ASAN: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 19 | __attribute__((no_sanitize_address)) |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 20 | int NoAddressSafety1(int *a) { return *a; } |
| 21 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 22 | // WITHOUT: NoAddressSafety2{{.*}}) [[NOATTR]] |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 23 | // BLFILE: NoAddressSafety2{{.*}}) [[NOATTR]] |
| 24 | // BLFUNC: NoAddressSafety2{{.*}}) [[NOATTR]] |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 25 | // ASAN: NoAddressSafety2{{.*}}) [[NOATTR]] |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 26 | __attribute__((no_sanitize_address)) |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 27 | int NoAddressSafety2(int *a); |
| 28 | int NoAddressSafety2(int *a) { return *a; } |
| 29 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 30 | // WITHOUT: AddressSafetyOk{{.*}}) [[NOATTR]] |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 31 | // BLFILE: AddressSafetyOk{{.*}}) [[NOATTR]] |
| 32 | // BLFUNC: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]] |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 33 | // ASAN: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]] |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 34 | int AddressSafetyOk(int *a) { return *a; } |
| 35 | |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 36 | // WITHOUT: BlacklistedFunction{{.*}}) [[NOATTR]] |
| 37 | // BLFILE: BlacklistedFunction{{.*}}) [[NOATTR]] |
| 38 | // BLFUNC: BlacklistedFunction{{.*}}) [[NOATTR]] |
| 39 | // ASAN: BlacklistedFunction{{.*}}) [[WITH]] |
| 40 | int BlacklistedFunction(int *a) { return *a; } |
| 41 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 42 | // WITHOUT: TemplateAddressSafetyOk{{.*}}) [[NOATTR]] |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 43 | // BLFILE: TemplateAddressSafetyOk{{.*}}) [[NOATTR]] |
| 44 | // BLFUNC: TemplateAddressSafetyOk{{.*}}) [[WITH]] |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 45 | // ASAN: TemplateAddressSafetyOk{{.*}}) [[WITH]] |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 46 | template<int i> |
| 47 | int TemplateAddressSafetyOk() { return i; } |
| 48 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 49 | // WITHOUT: TemplateNoAddressSafety{{.*}}) [[NOATTR]] |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 50 | // BLFILE: TemplateNoAddressSafety{{.*}}) [[NOATTR]] |
| 51 | // BLFUNC: TemplateNoAddressSafety{{.*}}) [[NOATTR]] |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 52 | // ASAN: TemplateNoAddressSafety{{.*}}) [[NOATTR]] |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 53 | template<int i> |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 54 | __attribute__((no_sanitize_address)) |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 55 | int TemplateNoAddressSafety() { return i; } |
| 56 | |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 57 | int force_instance = TemplateAddressSafetyOk<42>() |
| 58 | + TemplateNoAddressSafety<42>(); |
Kostya Serebryany | b9d2b3b | 2012-06-26 08:56:33 +0000 | [diff] [blame] | 59 | |
Kostya Serebryany | 85aee96 | 2013-02-26 06:58:27 +0000 | [diff] [blame] | 60 | // Check that __cxx_global_var_init* get the sanitize_address attribute. |
Kostya Serebryany | b9d2b3b | 2012-06-26 08:56:33 +0000 | [diff] [blame] | 61 | int global1 = 0; |
| 62 | int global2 = *(int*)((char*)&global1+1); |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 63 | // WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]] |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 64 | // BLFILE: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]] |
| 65 | // BLFUNC: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]] |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 66 | // ASAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]] |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 67 | |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 68 | // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} } |
| 69 | // WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind } |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 70 | |
Alexey Samsonov | 7e73f94 | 2013-03-06 10:54:18 +0000 | [diff] [blame^] | 71 | // BLFILE: attributes [[NOATTR]] = { nounwind{{.*}} } |
| 72 | // BLFILE: attributes [[NOATTR_NO_TF]] = { nounwind } |
| 73 | |
| 74 | // BLFUNC: attributes [[NOATTR]] = { nounwind{{.*}} } |
| 75 | // BLFUNC: attributes [[WITH]] = { nounwind sanitize_address{{.*}} } |
| 76 | // BLFUNC: attributes [[WITH_NO_TF]] = { nounwind sanitize_address } |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 77 | |
| 78 | // ASAN: attributes [[NOATTR]] = { nounwind{{.*}} } |
| 79 | // ASAN: attributes [[WITH]] = { nounwind sanitize_address{{.*}} } |
| 80 | // ASAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_address } |