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 | |
| 13 | // CHECK-NOT: NoAddressSafety1{{.*}} address_safety |
| 14 | // ASAN-NOT: NoAddressSafety1{{.*}} address_safety |
| 15 | __attribute__((no_address_safety_analysis)) |
| 16 | int NoAddressSafety1(int *a) { return *a; } |
| 17 | |
| 18 | // CHECK-NOT: NoAddressSafety2{{.*}} address_safety |
| 19 | // ASAN-NOT: NoAddressSafety2{{.*}} address_safety |
| 20 | __attribute__((no_address_safety_analysis)) |
| 21 | int NoAddressSafety2(int *a); |
| 22 | int NoAddressSafety2(int *a) { return *a; } |
| 23 | |
| 24 | // CHECK-NOT: AddressSafetyOk{{.*}} address_safety |
| 25 | // ASAN: AddressSafetyOk{{.*}} address_safety |
| 26 | int AddressSafetyOk(int *a) { return *a; } |
| 27 | |
| 28 | // CHECK-NOT: TemplateNoAddressSafety{{.*}} address_safety |
| 29 | // ASAN-NOT: TemplateNoAddressSafety{{.*}} address_safety |
| 30 | template<int i> |
| 31 | __attribute__((no_address_safety_analysis)) |
| 32 | int TemplateNoAddressSafety() { return i; } |
| 33 | |
| 34 | // CHECK-NOT: TemplateAddressSafetyOk{{.*}} address_safety |
| 35 | // ASAN: TemplateAddressSafetyOk{{.*}} address_safety |
| 36 | template<int i> |
| 37 | int TemplateAddressSafetyOk() { return i; } |
| 38 | |
| 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); |
| 45 | // CHECK-NOT: @__cxx_global_var_init{{.*}}address_safety |
| 46 | // ASAN: @__cxx_global_var_init{{.*}}address_safety |