Bill Wendling | 3bba3ef | 2013-02-20 19:30:01 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s |
| 2 | // RUN: %clang_cc1 -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 | 3bba3ef | 2013-02-20 19:30:01 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -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 | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 9 | // The address_safety attribute should be attached to functions |
| 10 | // when AddressSanitizer is enabled, unless no_address_safety_analysis attribute |
| 11 | // is present. |
| 12 | |
Bill Wendling | 3bba3ef | 2013-02-20 19:30:01 +0000 | [diff] [blame] | 13 | // WITHOUT: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]] |
| 14 | // BL: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]] |
| 15 | // ASAN: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]] |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 16 | __attribute__((no_address_safety_analysis)) |
| 17 | int NoAddressSafety1(int *a) { return *a; } |
| 18 | |
Bill Wendling | 3bba3ef | 2013-02-20 19:30:01 +0000 | [diff] [blame] | 19 | // WITHOUT: NoAddressSafety2{{.*}}) #[[NOATTR]] |
| 20 | // BL: NoAddressSafety2{{.*}}) #[[NOATTR]] |
| 21 | // ASAN: NoAddressSafety2{{.*}}) #[[NOATTR]] |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 22 | __attribute__((no_address_safety_analysis)) |
| 23 | int NoAddressSafety2(int *a); |
| 24 | int NoAddressSafety2(int *a) { return *a; } |
| 25 | |
Bill Wendling | 3bba3ef | 2013-02-20 19:30:01 +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 | 3bba3ef | 2013-02-20 19:30:01 +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 | 3bba3ef | 2013-02-20 19:30:01 +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> |
| 41 | __attribute__((no_address_safety_analysis)) |
| 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 | |
| 47 | // Check that __cxx_global_var_init* get the address_safety attribute. |
| 48 | int global1 = 0; |
| 49 | int global2 = *(int*)((char*)&global1+1); |
Bill Wendling | 478bbf3 | 2013-02-21 19:44:18 +0000 | [diff] [blame^] | 50 | // WITHOUT: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]] |
| 51 | // BL: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]] |
| 52 | // ASAN: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]] |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 53 | |
Bill Wendling | 478bbf3 | 2013-02-21 19:44:18 +0000 | [diff] [blame^] | 54 | // WITHOUT: attributes #[[NOATTR]] = { nounwind{{.*}} } |
| 55 | // WITHOUT: attributes #[[GVI]] = { nounwind{{.*}} } |
| 56 | // BL: attributes #[[NOATTR]] = { nounwind{{.*}} } |
| 57 | // BL: attributes #[[GVI]] = { nounwind{{.*}} } |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 58 | |
Bill Wendling | 478bbf3 | 2013-02-21 19:44:18 +0000 | [diff] [blame^] | 59 | // ASAN: attributes #[[NOATTR]] = { nounwind{{.*}} } |
| 60 | // ASAN: attributes #[[WITH]] = { address_safety nounwind{{.*}} } |
| 61 | // ASAN: attributes #[[GVI]] = { address_safety nounwind{{.*}} } |