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