#include "llvm/Transforms/Utils/ASanStackFrameLayout.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/MathExtras.h"
#include <algorithm>
namespace llvm {
// with e.g. alignment 1 and alignment 16 do not get reordered by CompareVars.
static const size_t kMinAlignment = 16;
-static size_t RoundUpTo(size_t X, size_t RoundTo) {
- assert((RoundTo & (RoundTo - 1)) == 0);
- return (X + RoundTo - 1) & ~(RoundTo - 1);
-}
-
// The larger the variable Size the larger is the redzone.
// The resulting frame size is a multiple of Alignment.
static size_t VarAndRedzoneSize(size_t Size, size_t Alignment) {
else if (Size <= 512) Res = Size + 64;
else if (Size <= 4096) Res = Size + 128;
else Res = Size + 256;
- return RoundUpTo(Res, Alignment);
+ return RoundUpToAlignment(Res, Alignment);
}
void
Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
- small_string_ostream<2048> StackDescription;
+ SmallString<2048> StackDescriptionStorage;
+ raw_svector_ostream StackDescription(StackDescriptionStorage);
StackDescription << NumVars;
Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
SmallVector<uint8_t, 64> &SB(Layout->ShadowBytes);