Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s |
Richard Smith | d6396a6 | 2012-11-05 22:21:05 +0000 | [diff] [blame] | 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 |
| 4 | // RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t | FileCheck %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 | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame^] | 13 | // CHECK: NoAddressSafety1{{.*}}#0 |
| 14 | // ASAN: NoAddressSafety1{{.*}}#0 |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 15 | __attribute__((no_address_safety_analysis)) |
| 16 | int NoAddressSafety1(int *a) { return *a; } |
| 17 | |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame^] | 18 | // CHECK: NoAddressSafety2{{.*}}#0 |
| 19 | // ASAN: NoAddressSafety2{{.*}}#0 |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 20 | __attribute__((no_address_safety_analysis)) |
| 21 | int NoAddressSafety2(int *a); |
| 22 | int NoAddressSafety2(int *a) { return *a; } |
| 23 | |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame^] | 24 | // CHECK: AddressSafetyOk{{.*}}#0 |
| 25 | // ASAN: AddressSafetyOk{{.*}}#1 |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 26 | int AddressSafetyOk(int *a) { return *a; } |
| 27 | |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame^] | 28 | // CHECK: TemplateAddressSafetyOk{{.*}}#0 |
| 29 | // ASAN: TemplateAddressSafetyOk{{.*}}#1 |
| 30 | template<int i> |
| 31 | int TemplateAddressSafetyOk() { return i; } |
| 32 | |
| 33 | // CHECK: TemplateNoAddressSafety{{.*}}#0 |
| 34 | // ASAN: TemplateNoAddressSafety{{.*}}#0 |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 35 | template<int i> |
| 36 | __attribute__((no_address_safety_analysis)) |
| 37 | int TemplateNoAddressSafety() { return i; } |
| 38 | |
Kostya Serebryany | 71efba0 | 2012-01-24 19:25:38 +0000 | [diff] [blame] | 39 | int force_instance = TemplateAddressSafetyOk<42>() |
| 40 | + TemplateNoAddressSafety<42>(); |
Kostya Serebryany | b9d2b3b | 2012-06-26 08:56:33 +0000 | [diff] [blame] | 41 | |
| 42 | // Check that __cxx_global_var_init* get the address_safety attribute. |
| 43 | int global1 = 0; |
| 44 | int global2 = *(int*)((char*)&global1+1); |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame^] | 45 | // CHECK: @__cxx_global_var_init{{.*}}#1 |
| 46 | // ASAN: @__cxx_global_var_init{{.*}}#2 |
| 47 | |
| 48 | // CHECK: attributes #0 = { nounwind "target-features"={{.*}} } |
| 49 | // CHECK: attributes #1 = { nounwind } |
| 50 | |
| 51 | // ASAN: attributes #0 = { nounwind "target-features"={{.*}} } |
| 52 | // ASAN: attributes #1 = { address_safety nounwind "target-features"={{.*}} } |
| 53 | // ASAN: attributes #2 = { address_safety nounwind } |