[libc-commits] [libc] 9abc1e0 - [test][libc] Fix aligned_alloc argument

Vitaly Buka via libc-commits libc-commits at lists.llvm.org
Mon Aug 7 16:36:32 PDT 2023


Author: Vitaly Buka
Date: 2023-08-07T16:36:20-07:00
New Revision: 9abc1e080dc9e1b40b88de4c116942e8ae52dc54

URL: https://github.com/llvm/llvm-project/commit/9abc1e080dc9e1b40b88de4c116942e8ae52dc54
DIFF: https://github.com/llvm/llvm-project/commit/9abc1e080dc9e1b40b88de4c116942e8ae52dc54.diff

LOG: [test][libc] Fix aligned_alloc argument

Size must be multiple of Alignment.

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D157247

Added: 
    

Modified: 
    libc/benchmarks/LibcMemoryBenchmark.h

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/LibcMemoryBenchmark.h b/libc/benchmarks/LibcMemoryBenchmark.h
index 382ff867e36fbf..f00bed4f693117 100644
--- a/libc/benchmarks/LibcMemoryBenchmark.h
+++ b/libc/benchmarks/LibcMemoryBenchmark.h
@@ -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); }
 


        


More information about the libc-commits mailing list