blob: b63b49bdfd5cab9bfd46f76b781bbac9ceb217b7 [file] [log] [blame]
Kostya Serebryany293dc9b2014-10-16 20:54:52 +00001// 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 Serebryany233877542014-10-17 00:47:30 +000019// CHECK: -fsanitize-address-field-padding ignored for ExternCStruct because it is not C++
Kostya Serebryany293dc9b2014-10-16 20:54:52 +000020//
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
26class 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
38Positive1 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
42class Negative1 {
43 public:
44 Negative1() {}
45 int public1, public2;
46};
47Negative1 negative1;
48// CHECK: type { i32, i32 }
49
50class Negative2 {
51 public:
52 Negative2() {}
53 private:
54 int private1, private2;
55};
56Negative2 negative2;
57// CHECK: type { i32, i32 }
58
59union Negative3 {
60 char m1[8];
61 long long m2;
62};
63
64Negative3 negative3;
65// CHECK: type { i64 }
66
67class 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
77Negative4 negative4;
78// CHECK: type { i32, i8, i32 }
79
80class __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
90Negative5 negative5;
91// CHECK: type <{ i32, i8, i32 }>
92
93
94namespace SomeNamespace {
95class 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
106SomeNamespace::BlacklistedByName blacklisted_by_name;
107
108extern "C" {
109class 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
120ExternCStruct extern_C_struct;
121
122// CTOR
Renato Golin031e8172014-10-17 10:09:25 +0000123// CHECK-LABEL: define {{.*}}Positive1C1Ev
Kostya Serebryany330e9f62014-10-16 21:22:40 +0000124// 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 Serebryany293dc9b2014-10-16 20:54:52 +0000129// CHECK-NOT: __asan_poison_intra_object_redzone
130// CHECK: ret void
Kostya Serebryany233877542014-10-17 00:47:30 +0000131//
Kostya Serebryany293dc9b2014-10-16 20:54:52 +0000132// DTOR
Kostya Serebryany330e9f62014-10-16 21:22:40 +0000133// 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 Serebryany293dc9b2014-10-16 20:54:52 +0000138// CHECK-NOT: __asan_unpoison_intra_object_redzone
139// CHECK: ret void