Skip to content

Commit a888e07

Browse files
vitalybukaAdvenamTacet
authored andcommitted
rename old/new -> src/dst
1 parent c73606e commit a888e07

File tree

1 file changed

+76
-76
lines changed

1 file changed

+76
-76
lines changed

compiler-rt/test/asan/TestCases/copy_container_annotations.cpp

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -60,62 +60,62 @@ static size_t CountUnpoisoned(std::deque<int> &poison_states, size_t n) {
6060
return result;
6161
}
6262

63-
void TestNonOverlappingContainers(size_t capacity, size_t off_old,
64-
size_t off_new, bool poison_old,
65-
bool poison_new) {
66-
size_t old_buffer_size = capacity + off_old + kGranularity * 2;
67-
size_t new_buffer_size = capacity + off_new + kGranularity * 2;
68-
69-
std::unique_ptr<char[]> old_buffer =
70-
std::make_unique<char[]>(old_buffer_size);
71-
std::unique_ptr<char[]> new_buffer =
72-
std::make_unique<char[]>(new_buffer_size);
73-
74-
char *old_buffer_end = old_buffer.get() + old_buffer_size;
75-
char *new_buffer_end = new_buffer.get() + new_buffer_size;
76-
char *old_beg = old_buffer.get() + off_old;
77-
char *new_beg = new_buffer.get() + off_new;
78-
char *old_end = old_beg + capacity;
79-
char *new_end = new_beg + capacity;
63+
void TestNonOverlappingContainers(size_t capacity, size_t off_src,
64+
size_t off_dst, bool poison_src,
65+
bool poison_dst) {
66+
size_t src_buffer_size = capacity + off_src + kGranularity * 2;
67+
size_t dst_buffer_size = capacity + off_dst + kGranularity * 2;
68+
69+
std::unique_ptr<char[]> src_buffer =
70+
std::make_unique<char[]>(src_buffer_size);
71+
std::unique_ptr<char[]> dst_buffer =
72+
std::make_unique<char[]>(dst_buffer_size);
73+
74+
char *src_buffer_end = src_buffer.get() + src_buffer_size;
75+
char *dst_buffer_end = dst_buffer.get() + dst_buffer_size;
76+
char *src_beg = src_buffer.get() + off_src;
77+
char *dst_beg = dst_buffer.get() + off_dst;
78+
char *src_end = src_beg + capacity;
79+
char *dst_end = dst_beg + capacity;
8080

8181
for (int i = 0; i < 35; i++) {
82-
if (poison_old)
83-
__asan_poison_memory_region(old_buffer.get(), old_buffer_size);
84-
if (poison_new)
85-
__asan_poison_memory_region(new_buffer.get(), new_buffer_size);
82+
if (poison_src)
83+
__asan_poison_memory_region(src_buffer.get(), src_buffer_size);
84+
if (poison_dst)
85+
__asan_poison_memory_region(dst_buffer.get(), dst_buffer_size);
8686

87-
RandomPoison(old_beg, old_end);
88-
std::deque<int> poison_states = GetPoisonedState(old_beg, old_end);
89-
__sanitizer_copy_contiguous_container_annotations(old_beg, old_end, new_beg,
90-
new_end);
87+
RandomPoison(src_beg, src_end);
88+
std::deque<int> poison_states = GetPoisonedState(src_beg, src_end);
89+
__sanitizer_copy_contiguous_container_annotations(src_beg, src_end, dst_beg,
90+
dst_end);
9191

92-
// If old_buffer were poisoned, expected state of memory before old_beg
92+
// If src_buffer were poisoned, expected state of memory before src_beg
9393
// is undetermined.
9494
// If old buffer were not poisoned, that memory should still be unpoisoned.
9595
char *cur;
96-
if (!poison_old) {
97-
for (cur = old_buffer.get(); cur < old_beg; ++cur) {
96+
if (!poison_src) {
97+
for (cur = src_buffer.get(); cur < src_beg; ++cur) {
9898
assert(!__asan_address_is_poisoned(cur));
9999
}
100100
}
101101
for (size_t i = 0; i < poison_states.size(); ++i) {
102-
assert(__asan_address_is_poisoned(&old_beg[i]) == poison_states[i]);
102+
assert(__asan_address_is_poisoned(&src_beg[i]) == poison_states[i]);
103103
}
104-
// Memory after old_end should be the same as at the beginning.
105-
for (cur = old_end; cur < old_buffer_end; ++cur) {
106-
assert(__asan_address_is_poisoned(cur) == poison_old);
104+
// Memory after src_end should be the same as at the beginning.
105+
for (cur = src_end; cur < src_buffer_end; ++cur) {
106+
assert(__asan_address_is_poisoned(cur) == poison_dst);
107107
}
108108

109-
// If new_buffer were not poisoned, memory before new_beg should never
109+
// If dst_buffer were not poisoned, memory before dst_beg should never
110110
// be poisoned. Otherwise, its state is undetermined.
111-
if (!poison_new) {
112-
for (cur = new_buffer.get(); cur < new_beg; ++cur) {
111+
if (!poison_dst) {
112+
for (cur = dst_buffer.get(); cur < dst_beg; ++cur) {
113113
assert(!__asan_address_is_poisoned(cur));
114114
}
115115
}
116116

117117
char *next;
118-
for (cur = new_beg; cur + kGranularity <= new_end; cur = next) {
118+
for (cur = dst_beg; cur + kGranularity <= dst_end; cur = next) {
119119
next = RoundUp(cur + 1);
120120
size_t unpoisoned = CountUnpoisoned(poison_states, next - cur);
121121
if (unpoisoned > 0) {
@@ -125,72 +125,72 @@ void TestNonOverlappingContainers(size_t capacity, size_t off_old,
125125
assert(__asan_address_is_poisoned(cur + unpoisoned));
126126
}
127127
}
128-
// [cur; new_end) is not checked yet.
129-
// If new_buffer were not poisoned, it cannot be poisoned.
130-
// If new_buffer were poisoned, it should be same as earlier.
131-
if (cur < new_end) {
132-
size_t unpoisoned = CountUnpoisoned(poison_states, new_end - cur);
128+
// [cur; dst_end) is not checked yet.
129+
// If dst_buffer were not poisoned, it cannot be poisoned.
130+
// If dst_buffer were poisoned, it should be same as earlier.
131+
if (cur < dst_end) {
132+
size_t unpoisoned = CountUnpoisoned(poison_states, dst_end - cur);
133133
if (unpoisoned > 0) {
134134
assert(!__asan_address_is_poisoned(cur + unpoisoned - 1));
135135
}
136-
if (cur + unpoisoned < new_end && poison_new) {
136+
if (cur + unpoisoned < dst_end && poison_dst) {
137137
assert(__asan_address_is_poisoned(cur + unpoisoned));
138138
}
139139
}
140-
// Memory annotations after new_end should be unchanged.
141-
for (cur = new_end; cur < new_buffer_end; ++cur) {
142-
assert(__asan_address_is_poisoned(cur) == poison_new);
140+
// Memory annotations after dst_end should be unchanged.
141+
for (cur = dst_end; cur < dst_buffer_end; ++cur) {
142+
assert(__asan_address_is_poisoned(cur) == poison_dst);
143143
}
144144
}
145145

146-
__asan_unpoison_memory_region(old_buffer.get(), old_buffer_size);
147-
__asan_unpoison_memory_region(new_buffer.get(), new_buffer_size);
146+
__asan_unpoison_memory_region(src_buffer.get(), src_buffer_size);
147+
__asan_unpoison_memory_region(dst_buffer.get(), dst_buffer_size);
148148
}
149149

150-
void TestOverlappingContainers(size_t capacity, size_t off_old, size_t off_new,
151-
bool poison_whole, bool poison_new) {
152-
size_t buffer_size = capacity + off_old + off_new + kGranularity * 3;
150+
void TestOverlappingContainers(size_t capacity, size_t off_src, size_t off_dst,
151+
bool poison_whole, bool poison_dst) {
152+
size_t buffer_size = capacity + off_src + off_dst + kGranularity * 3;
153153

154154
// Use unique_ptr with a custom deleter to manage the buffer
155155
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(buffer_size);
156156

157157
char *buffer_end = buffer.get() + buffer_size;
158-
char *old_beg = buffer.get() + kGranularity + off_old;
159-
char *new_beg = buffer.get() + kGranularity + off_new;
160-
char *old_end = old_beg + capacity;
161-
char *new_end = new_beg + capacity;
158+
char *src_beg = buffer.get() + kGranularity + off_src;
159+
char *dst_beg = buffer.get() + kGranularity + off_dst;
160+
char *src_end = src_beg + capacity;
161+
char *dst_end = dst_beg + capacity;
162162

163163
for (int i = 0; i < 35; i++) {
164164
if (poison_whole)
165165
__asan_poison_memory_region(buffer.get(), buffer_size);
166-
if (poison_new)
167-
__asan_poison_memory_region(new_beg, new_end - new_beg);
166+
if (poison_dst)
167+
__asan_poison_memory_region(dst_beg, dst_end - dst_beg);
168168

169-
RandomPoison(old_beg, old_end);
170-
auto poison_states = GetPoisonedState(old_beg, old_end);
171-
__sanitizer_copy_contiguous_container_annotations(old_beg, old_end, new_beg,
172-
new_end);
169+
RandomPoison(src_beg, src_end);
170+
auto poison_states = GetPoisonedState(src_beg, src_end);
171+
__sanitizer_copy_contiguous_container_annotations(src_beg, src_end, dst_beg,
172+
dst_end);
173173
// This variable is used only when buffer ends in the middle of a granule.
174-
bool can_modify_last_granule = __asan_address_is_poisoned(new_end);
174+
bool can_modify_last_granule = __asan_address_is_poisoned(dst_end);
175175

176176
// If whole buffer were poisoned, expected state of memory before first container
177177
// is undetermined.
178178
// If old buffer were not poisoned, that memory should still be unpoisoned.
179179
char *cur;
180180
if (!poison_whole) {
181-
for (cur = buffer.get(); cur < old_beg && cur < new_beg; ++cur) {
181+
for (cur = buffer.get(); cur < src_beg && cur < dst_beg; ++cur) {
182182
assert(!__asan_address_is_poisoned(cur));
183183
}
184184
}
185185

186186
// Memory after end of both containers should be the same as at the beginning.
187-
for (cur = (old_end > new_end) ? old_end : new_end; cur < buffer_end;
187+
for (cur = (src_end > dst_end) ? src_end : dst_end; cur < buffer_end;
188188
++cur) {
189189
assert(__asan_address_is_poisoned(cur) == poison_whole);
190190
}
191191

192192
char *next;
193-
for (cur = new_beg; cur + kGranularity <= new_end; cur = next) {
193+
for (cur = dst_beg; cur + kGranularity <= dst_end; cur = next) {
194194
next = RoundUp(cur + 1);
195195
size_t unpoisoned = CountUnpoisoned(poison_states, next - cur);
196196
if (unpoisoned > 0) {
@@ -200,15 +200,15 @@ void TestOverlappingContainers(size_t capacity, size_t off_old, size_t off_new,
200200
assert(__asan_address_is_poisoned(cur + unpoisoned));
201201
}
202202
}
203-
// [cur; new_end) is not checked yet, if container ends in the middle of a granule.
203+
// [cur; dst_end) is not checked yet, if container ends in the middle of a granule.
204204
// It can be poisoned, only if non-container bytes in that granule were poisoned.
205205
// Otherwise, it should be unpoisoned.
206-
if (cur < new_end) {
207-
size_t unpoisoned = CountUnpoisoned(poison_states, new_end - cur);
206+
if (cur < dst_end) {
207+
size_t unpoisoned = CountUnpoisoned(poison_states, dst_end - cur);
208208
if (unpoisoned > 0) {
209209
assert(!__asan_address_is_poisoned(cur + unpoisoned - 1));
210210
}
211-
if (cur + unpoisoned < new_end && can_modify_last_granule) {
211+
if (cur + unpoisoned < dst_end && can_modify_last_granule) {
212212
assert(__asan_address_is_poisoned(cur + unpoisoned));
213213
}
214214
}
@@ -219,15 +219,15 @@ void TestOverlappingContainers(size_t capacity, size_t off_old, size_t off_new,
219219

220220
int main(int argc, char **argv) {
221221
int n = argc == 1 ? 64 : atoi(argv[1]);
222-
for (size_t off_old = 0; off_old < kGranularity + 2; off_old++) {
223-
for (size_t off_new = 0; off_new < kGranularity + 2; off_new++) {
222+
for (size_t off_src = 0; off_src < kGranularity + 2; off_src++) {
223+
for (size_t off_dst = 0; off_dst < kGranularity + 2; off_dst++) {
224224
for (int capacity = 0; capacity <= n; capacity++) {
225-
for (int poison_old = 0; poison_old < 2; ++poison_old) {
226-
for (int poison_new = 0; poison_new < 2; ++poison_new) {
227-
TestNonOverlappingContainers(capacity, off_old, off_new, poison_old,
228-
poison_new);
229-
TestOverlappingContainers(capacity, off_old, off_new, poison_old,
230-
poison_new);
225+
for (int poison_dst = 0; poison_dst < 2; ++poison_dst) {
226+
for (int poison_dst = 0; poison_dst < 2; ++poison_dst) {
227+
TestNonOverlappingContainers(capacity, off_src, off_dst, poison_dst,
228+
poison_dst);
229+
TestOverlappingContainers(capacity, off_src, off_dst, poison_dst,
230+
poison_dst);
231231
}
232232
}
233233
}

0 commit comments

Comments
 (0)