Explicitly cast std::min's arguments to avoid type mismatches.
[oota-llvm.git] / include / llvm / Support / Allocator.h
index 4c848788c73dd2abae3f2f3275938a36251a5006..cdb0fc85582193f4964d1ff991e5009af7adda79 100644 (file)
 #define LLVM_SUPPORT_ALLOCATOR_H
 
 #include "llvm/Support/AlignOf.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/MathExtras.h"
+#include "llvm/System/DataTypes.h"
+#include <algorithm>
 #include <cassert>
 #include <cstdlib>
+#include <cstddef>
 
 namespace llvm {
 
@@ -175,4 +178,22 @@ public:
 
 }  // end namespace llvm
 
+inline void *operator new(size_t Size, llvm::BumpPtrAllocator &Allocator) {
+  struct S {
+    char c;
+#ifdef __GNUC__
+    char x __attribute__((aligned));
+#else
+    union {
+      double D;
+      long double LD;
+      long long L;
+      void *P;
+    } x;
+#endif
+  };
+  return Allocator.Allocate(Size, std::min((size_t)llvm::NextPowerOf2(Size),
+                                           (size_t)offsetof(S, x)));
+}
+
 #endif // LLVM_SUPPORT_ALLOCATOR_H