llvm.org GIT mirror llvm / ed2fd58
[PDB] Fix and re-enable BinaryStreamArray test. This was due to the test stream choosing an arbitrary partition index for introducing the discontinuity rather than choosing an index that would be correctly aligned for the type of data. Also added an assertion into FixedStreamArray so that this will be caught on all bots in the future, and not just the UBSan bot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296661 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
2 changed file(s) with 45 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
242242 // an exact multiple of the element size.
243243 consumeError(std::move(EC));
244244 }
245 assert(llvm::alignmentAdjustment(Data.data(), alignof(T)) == 0);
245246 return *reinterpret_cast(Data.data());
246247 }
247248
4747
4848 class DiscontiguousStream : public WritableBinaryStream {
4949 public:
50 DiscontiguousStream(MutableArrayRef Data, endianness Endian)
51 : Data(Data), PartitionIndex(Data.size() / 2), Endian(Endian) {}
50 DiscontiguousStream(MutableArrayRef Data, endianness Endian,
51 uint32_t Align)
52 : Data(Data), PartitionIndex(alignDown(Data.size() / 2, Align)),
53 Endian(Endian) {}
5254
5355 endianness getEndian() const override { return Endian; }
5456
149151 std::unique_ptr Output;
150152 };
151153
152 void initializeInput(ArrayRef Input) {
154 void initializeInput(ArrayRef Input, uint32_t Align) {
153155 InputData = Input;
154156
155157 BrokenInputData.resize(InputData.size());
156158 if (!Input.empty()) {
157 uint32_t PartitionIndex = InputData.size() / 2;
159 uint32_t PartitionIndex = alignDown(InputData.size() / 2, Align);
158160 uint32_t RightBytes = InputData.size() - PartitionIndex;
159161 uint32_t LeftBytes = PartitionIndex;
160162 if (RightBytes > 0)
166168 for (uint32_t I = 0; I < NumEndians; ++I) {
167169 auto InByteStream =
168170 llvm::make_unique(InputData, Endians[I]);
169 auto InBrokenStream =
170 llvm::make_unique(BrokenInputData, Endians[I]);
171 auto InBrokenStream = llvm::make_unique(
172 BrokenInputData, Endians[I], Align);
171173
172174 Streams[I * 2].Input = std::move(InByteStream);
173175 Streams[I * 2 + 1].Input = std::move(InBrokenStream);
174176 }
175177 }
176178
177 void initializeOutput(uint32_t Size) {
179 void initializeOutput(uint32_t Size, uint32_t Align) {
178180 OutputData.resize(Size);
179181 BrokenOutputData.resize(Size);
180182
181183 for (uint32_t I = 0; I < NumEndians; ++I) {
182184 Streams[I * 2].Output =
183185 llvm::make_unique(OutputData, Endians[I]);
184 Streams[I * 2 + 1].Output =
185 llvm::make_unique(BrokenOutputData, Endians[I]);
186 }
187 }
188
189 void initializeOutputFromInput() {
186 Streams[I * 2 + 1].Output = llvm::make_unique(
187 BrokenOutputData, Endians[I], Align);
188 }
189 }
190
191 void initializeOutputFromInput(uint32_t Align) {
190192 for (uint32_t I = 0; I < NumEndians; ++I) {
191193 Streams[I * 2].Output =
192194 llvm::make_unique(InputData, Endians[I]);
193 Streams[I * 2 + 1].Output =
194 llvm::make_unique(BrokenInputData, Endians[I]);
195 }
196 }
197
198 void initializeInputFromOutput() {
195 Streams[I * 2 + 1].Output = llvm::make_unique(
196 BrokenInputData, Endians[I], Align);
197 }
198 }
199
200 void initializeInputFromOutput(uint32_t Align) {
199201 for (uint32_t I = 0; I < NumEndians; ++I) {
200202 Streams[I * 2].Input =
201203 llvm::make_unique(OutputData, Endians[I]);
202 Streams[I * 2 + 1].Input =
203 llvm::make_unique(BrokenOutputData, Endians[I]);
204 Streams[I * 2 + 1].Input = llvm::make_unique(
205 BrokenOutputData, Endians[I], Align);
204206 }
205207 }
206208
216218 // Tests that a we can read from a BinaryByteStream without a StreamReader.
217219 TEST_F(BinaryStreamTest, BinaryByteStreamBounds) {
218220 std::vector InputData = {1, 2, 3, 4, 5};
219 initializeInput(InputData);
221 initializeInput(InputData, 1);
220222
221223 for (auto &Stream : Streams) {
222224 ArrayRef Buffer;
235237
236238 TEST_F(BinaryStreamTest, StreamRefBounds) {
237239 std::vector InputData = {1, 2, 3, 4, 5};
238 initializeInput(InputData);
240 initializeInput(InputData, 1);
239241
240242 for (const auto &Stream : Streams) {
241243 ArrayRef Buffer;
288290 // Test that we can write to a BinaryStream without a StreamWriter.
289291 TEST_F(BinaryStreamTest, MutableBinaryByteStreamBounds) {
290292 std::vector InputData = {'T', 'e', 's', 't', '\0'};
291 initializeInput(InputData);
292 initializeOutput(InputData.size());
293 initializeInput(InputData, 1);
294 initializeOutput(InputData.size(), 1);
293295
294296 // For every combination of input stream and output stream.
295297 for (auto &Stream : Streams) {
329331 ArrayRef IntBytes(reinterpret_cast(Ints.data()),
330332 Ints.size() * sizeof(uint32_t));
331333
332 initializeInput(IntBytes);
334 initializeInput(IntBytes, alignof(uint32_t));
333335
334336 for (auto &Stream : Streams) {
335337 MutableArrayRef Buffer;
351353 "Extra Longest Test Of All");
352354 ArrayRef StringBytes(
353355 reinterpret_cast(Strings.data()), Strings.size());
354 initializeInput(StringBytes);
356 initializeInput(StringBytes, 1);
355357
356358 struct StringExtractor {
357359 public:
391393 TEST_F(BinaryStreamTest, StreamReaderBounds) {
392394 std::vector Bytes;
393395
394 initializeInput(Bytes);
396 initializeInput(Bytes, 1);
395397 for (auto &Stream : Streams) {
396398 StringRef S;
397399 BinaryStreamReader Reader(*Stream.Input);
400402 }
401403
402404 Bytes.resize(5);
403 initializeInput(Bytes);
405 initializeInput(Bytes, 1);
404406 for (auto &Stream : Streams) {
405407 StringRef S;
406408 BinaryStreamReader Reader(*Stream.Input);
419421 constexpr uint32_t Size =
420422 sizeof(Little) + sizeof(Big) + sizeof(NS) + sizeof(NI) + sizeof(NUL);
421423
422 initializeOutput(Size);
423 initializeInputFromOutput();
424 initializeOutput(Size, alignof(support::ulittle64_t));
425 initializeInputFromOutput(alignof(support::ulittle64_t));
424426
425427 for (auto &Stream : Streams) {
426428 BinaryStreamWriter Writer(*Stream.Output);
453455 }
454456 }
455457
456 TEST_F(BinaryStreamTest, DISABLED_StreamReaderIntegerArray) {
458 TEST_F(BinaryStreamTest, StreamReaderIntegerArray) {
457459 // 1. Arrays of integers
458460 std::vector Ints = {1, 2, 3, 4, 5};
459461 ArrayRef IntBytes(reinterpret_cast(&Ints[0]),
460462 Ints.size() * sizeof(int));
461463
462 initializeInput(IntBytes);
464 initializeInput(IntBytes, alignof(int));
463465 for (auto &Stream : Streams) {
464466 BinaryStreamReader Reader(*Stream.Input);
465467 ArrayRef IntsRef;
480482
481483 std::vector Enums = {MyEnum::Bar, MyEnum::Baz, MyEnum::Foo};
482484
483 initializeOutput(Enums.size() * sizeof(MyEnum));
484 initializeInputFromOutput();
485 initializeOutput(Enums.size() * sizeof(MyEnum), alignof(MyEnum));
486 initializeInputFromOutput(alignof(MyEnum));
485487 for (auto &Stream : Streams) {
486488 BinaryStreamWriter Writer(*Stream.Output);
487489 for (auto Value : Enums)
514516
515517 const uint8_t *Bytes = reinterpret_cast(&Foos[0]);
516518
517 initializeInput(makeArrayRef(Bytes, 2 * sizeof(Foo)));
519 initializeInput(makeArrayRef(Bytes, 2 * sizeof(Foo)), alignof(Foo));
518520
519521 for (auto &Stream : Streams) {
520522 // 1. Reading object pointers.
533535 std::vector Bytes = {'O', 'n', 'e', '\0', 'T', 'w', 'o',
534536 '\0', 'T', 'h', 'r', 'e', 'e', '\0',
535537 'F', 'o', 'u', 'r', '\0'};
536 initializeInput(Bytes);
538 initializeInput(Bytes, 1);
537539
538540 for (auto &Stream : Streams) {
539541 BinaryStreamReader Reader(*Stream.Input);
573575 }
574576
575577 TEST_F(BinaryStreamTest, StreamWriterBounds) {
576 initializeOutput(5);
578 initializeOutput(5, 1);
577579
578580 for (auto &Stream : Streams) {
579581 BinaryStreamWriter Writer(*Stream.Output);
599601 ArrayRef SourceBytes(reinterpret_cast(&SourceInts[0]),
600602 SourceInts.size() * sizeof(int));
601603
602 initializeInput(SourceBytes);
603 initializeOutputFromInput();
604 initializeInput(SourceBytes, alignof(int));
605 initializeOutputFromInput(alignof(int));
604606
605607 for (auto &Stream : Streams) {
606608 BinaryStreamReader Reader(*Stream.Input);
624626 size_t Length = 0;
625627 for (auto S : Strings)
626628 Length += S.size() + 1;
627 initializeOutput(Length);
628 initializeInputFromOutput();
629 initializeOutput(Length, 1);
630 initializeInputFromOutput(1);
629631
630632 for (auto &Stream : Streams) {
631633 BinaryStreamWriter Writer(*Stream.Output);