Index: llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp =================================================================== --- llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp +++ llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp @@ -36,9 +36,11 @@ // with e.g. alignment 1 and alignment 16 do not get reordered by CompareVars. static const size_t kMinAlignment = 16; +// We want to add a full redzone after every variable. // 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) { +static size_t VarAndRedzoneSize(size_t Size, size_t Granularity, + size_t Alignment) { size_t Res = 0; if (Size <= 4) Res = 16; else if (Size <= 16) Res = 32; @@ -46,7 +48,7 @@ else if (Size <= 512) Res = Size + 64; else if (Size <= 4096) Res = Size + 128; else Res = Size + 256; - return alignTo(Res, Alignment); + return alignTo(std::max(Res, 2 * Granularity), Alignment); } ASanStackFrameLayout @@ -80,7 +82,8 @@ assert(Size > 0); size_t NextAlignment = IsLast ? Granularity : std::max(Granularity, Vars[i + 1].Alignment); - size_t SizeWithRedzone = VarAndRedzoneSize(Size, NextAlignment); + size_t SizeWithRedzone = VarAndRedzoneSize(Size, Granularity, + NextAlignment); Vars[i].Offset = Offset; Offset += SizeWithRedzone; } Index: llvm/unittests/Transforms/Utils/ASanStackFrameLayoutTest.cpp =================================================================== --- llvm/unittests/Transforms/Utils/ASanStackFrameLayoutTest.cpp +++ llvm/unittests/Transforms/Utils/ASanStackFrameLayoutTest.cpp @@ -70,7 +70,7 @@ VAR(a, 105, 103, 1, 0); TEST_LAYOUT({a1_1}, 8, 16, "1 16 1 4 a1_1", "LL1R", "LL1R"); - TEST_LAYOUT({a1_1}, 64, 64, "1 64 1 4 a1_1", "L1", "L1"); + TEST_LAYOUT({a1_1}, 64, 64, "1 64 1 4 a1_1", "L1R", "L1R"); TEST_LAYOUT({p1_32}, 8, 32, "1 32 1 8 p1_32:15", "LLLL1RRR", "LLLL1RRR"); TEST_LAYOUT({p1_32}, 8, 64, "1 64 1 8 p1_32:15", "LLLLLLLL1RRRRRRR", "LLLLLLLL1RRRRRRR");