[test][libc] Fix aligned_alloc argument

Size must be multiple of Alignment.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D157247
This commit is contained in:
Vitaly Buka 2023-08-06 18:17:59 -07:00
parent 3bcfd6e962
commit 9abc1e080d

View File

@ -17,6 +17,7 @@
#include "MemorySizeDistributions.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/MathExtras.h"
#include <cstdint>
#include <optional>
#include <random>
@ -107,11 +108,11 @@ class AlignedBuffer {
size_t Size = 0;
public:
// Note: msan / asan can't handle Alignment > 512.
static constexpr size_t Alignment = 512;
explicit AlignedBuffer(size_t Size)
: Buffer(static_cast<char *>(aligned_alloc(Alignment, Size))),
: Buffer(static_cast<char *>(
aligned_alloc(Alignment, alignTo(Size, Alignment)))),
Size(Size) {}
~AlignedBuffer() { free(Buffer); }