Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame] | 1 | // Test -fsanitize-address-field-padding |
| 2 | // RUN: echo 'type:SomeNamespace::BlacklistedByName=field-padding' > %t.type.blacklist |
| 3 | // RUN: echo 'src:*sanitize-address-field-padding.cpp=field-padding' > %t.file.blacklist |
| 4 | // RUN: %clang_cc1 -fsanitize=address -fsanitize-address-field-padding=1 -fsanitize-blacklist=%t.type.blacklist -Rsanitize-address -emit-llvm -o - %s 2>&1 | FileCheck %s |
| 5 | // RUN: %clang_cc1 -fsanitize=address -fsanitize-address-field-padding=1 -fsanitize-blacklist=%t.file.blacklist -Rsanitize-address -emit-llvm -o - %s 2>&1 | FileCheck %s --check-prefix=FILE_BLACKLIST |
| 6 | // RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - %s 2>&1 | FileCheck %s --check-prefix=NO_PADDING |
| 7 | // REQUIRES: shell |
| 8 | // |
| 9 | |
| 10 | // The reasons to ignore a particular class are not set in stone and will change. |
| 11 | // |
| 12 | // CHECK: -fsanitize-address-field-padding applied to Positive1 |
| 13 | // CHECK: -fsanitize-address-field-padding ignored for Negative1 because it is trivially copyable |
| 14 | // CHECK: -fsanitize-address-field-padding ignored for Negative2 because it is trivially copyable |
| 15 | // CHECK: -fsanitize-address-field-padding ignored for Negative3 because it is a union |
| 16 | // CHECK: -fsanitize-address-field-padding ignored for Negative4 because it is trivially copyable |
| 17 | // CHECK: -fsanitize-address-field-padding ignored for Negative5 because it is packed |
| 18 | // CHECK: -fsanitize-address-field-padding ignored for SomeNamespace::BlacklistedByName because it is blacklisted |
Kostya Serebryany | 23387754 | 2014-10-17 00:47:30 +0000 | [diff] [blame] | 19 | // CHECK: -fsanitize-address-field-padding ignored for ExternCStruct because it is not C++ |
Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame] | 20 | // |
| 21 | // FILE_BLACKLIST: -fsanitize-address-field-padding ignored for Positive1 because it is in a blacklisted file |
| 22 | // FILE_BLACKLIST-NOT: __asan_poison_intra_object_redzone |
| 23 | // NO_PADDING-NOT: __asan_poison_intra_object_redzone |
| 24 | |
| 25 | |
| 26 | class Positive1 { |
| 27 | public: |
| 28 | Positive1() {} |
| 29 | ~Positive1() {} |
| 30 | int make_it_non_standard_layout; |
| 31 | private: |
| 32 | char private1; |
| 33 | int private2; |
| 34 | short private_array[6]; |
| 35 | long long private3; |
| 36 | }; |
| 37 | |
| 38 | Positive1 positive1; |
| 39 | // Positive1 with extra paddings |
| 40 | // CHECK: type { i32, [12 x i8], i8, [15 x i8], i32, [12 x i8], [6 x i16], [12 x i8], i64, [8 x i8] } |
| 41 | |
| 42 | class Negative1 { |
| 43 | public: |
| 44 | Negative1() {} |
| 45 | int public1, public2; |
| 46 | }; |
| 47 | Negative1 negative1; |
| 48 | // CHECK: type { i32, i32 } |
| 49 | |
| 50 | class Negative2 { |
| 51 | public: |
| 52 | Negative2() {} |
| 53 | private: |
| 54 | int private1, private2; |
| 55 | }; |
| 56 | Negative2 negative2; |
| 57 | // CHECK: type { i32, i32 } |
| 58 | |
| 59 | union Negative3 { |
| 60 | char m1[8]; |
| 61 | long long m2; |
| 62 | }; |
| 63 | |
| 64 | Negative3 negative3; |
| 65 | // CHECK: type { i64 } |
| 66 | |
| 67 | class Negative4 { |
| 68 | public: |
| 69 | Negative4() {} |
| 70 | // No DTOR |
| 71 | int make_it_non_standard_layout; |
| 72 | private: |
| 73 | char private1; |
| 74 | int private2; |
| 75 | }; |
| 76 | |
| 77 | Negative4 negative4; |
| 78 | // CHECK: type { i32, i8, i32 } |
| 79 | |
| 80 | class __attribute__((packed)) Negative5 { |
| 81 | public: |
| 82 | Negative5() {} |
| 83 | ~Negative5() {} |
| 84 | int make_it_non_standard_layout; |
| 85 | private: |
| 86 | char private1; |
| 87 | int private2; |
| 88 | }; |
| 89 | |
| 90 | Negative5 negative5; |
| 91 | // CHECK: type <{ i32, i8, i32 }> |
| 92 | |
| 93 | |
| 94 | namespace SomeNamespace { |
| 95 | class BlacklistedByName { |
| 96 | public: |
| 97 | BlacklistedByName() {} |
| 98 | ~BlacklistedByName() {} |
| 99 | int make_it_non_standard_layout; |
| 100 | private: |
| 101 | char private1; |
| 102 | int private2; |
| 103 | }; |
| 104 | } // SomeNamespace |
| 105 | |
| 106 | SomeNamespace::BlacklistedByName blacklisted_by_name; |
| 107 | |
| 108 | extern "C" { |
| 109 | class ExternCStruct { |
| 110 | public: |
| 111 | ExternCStruct() {} |
| 112 | ~ExternCStruct() {} |
| 113 | int make_it_non_standard_layout; |
| 114 | private: |
| 115 | char private1; |
| 116 | int private2; |
| 117 | }; |
| 118 | } // extern "C" |
| 119 | |
| 120 | ExternCStruct extern_C_struct; |
| 121 | |
| 122 | // CTOR |
Renato Golin | 031e817 | 2014-10-17 10:09:25 +0000 | [diff] [blame^] | 123 | // CHECK-LABEL: define {{.*}}Positive1C1Ev |
Kostya Serebryany | 330e9f6 | 2014-10-16 21:22:40 +0000 | [diff] [blame] | 124 | // CHECK: call void @__asan_poison_intra_object_redzone({{.*}}12) |
| 125 | // CHECK: call void @__asan_poison_intra_object_redzone({{.*}}15) |
| 126 | // CHECK: call void @__asan_poison_intra_object_redzone({{.*}}12) |
| 127 | // CHECK: call void @__asan_poison_intra_object_redzone({{.*}}12) |
| 128 | // CHECK: call void @__asan_poison_intra_object_redzone({{.*}}8) |
Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame] | 129 | // CHECK-NOT: __asan_poison_intra_object_redzone |
| 130 | // CHECK: ret void |
Kostya Serebryany | 23387754 | 2014-10-17 00:47:30 +0000 | [diff] [blame] | 131 | // |
Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame] | 132 | // DTOR |
Kostya Serebryany | 330e9f6 | 2014-10-16 21:22:40 +0000 | [diff] [blame] | 133 | // CHECK: call void @__asan_unpoison_intra_object_redzone({{.*}}12) |
| 134 | // CHECK: call void @__asan_unpoison_intra_object_redzone({{.*}}15) |
| 135 | // CHECK: call void @__asan_unpoison_intra_object_redzone({{.*}}12) |
| 136 | // CHECK: call void @__asan_unpoison_intra_object_redzone({{.*}}12) |
| 137 | // CHECK: call void @__asan_unpoison_intra_object_redzone({{.*}}8) |
Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame] | 138 | // CHECK-NOT: __asan_unpoison_intra_object_redzone |
| 139 | // CHECK: ret void |