From 72dddce6523a1f1ace61a89e99c0c5866063b32f Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Wed, 6 Oct 2021 15:10:37 -0700 Subject: [PATCH] More size_t -> uint64_t fixes after 05392466 Fixes some bots where the two differ. --- .../llvm/Transforms/Utils/ASanStackFrameLayout.h | 4 +-- .../Instrumentation/AddressSanitizer.cpp | 4 +-- llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp | 32 +++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h b/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h index 3659e64..24e3368 100644 --- a/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h +++ b/llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h @@ -51,11 +51,11 @@ ASanStackFrameLayout ComputeASanStackFrameLayout( // The array of stack variables. The elements may get reordered and changed. SmallVectorImpl &Vars, // AddressSanitizer's shadow granularity. Usually 8, may also be 16, 32, 64. - size_t Granularity, + uint64_t Granularity, // The minimal size of the left-most redzone (header). // At least 4 pointer sizes, power of 2, and >= Granularity. // The resulting FrameSize should be multiple of MinHeaderSize. - size_t MinHeaderSize); + uint64_t MinHeaderSize); // Compute frame description, see DescribeAddressIfStack in ASan runtime. SmallString<64> ComputeASanStackFrameDescription( diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 74f5d84..ce6fded 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -3323,8 +3323,8 @@ void FunctionStackPoisoner::processStaticAllocas() { // Minimal header size (left redzone) is 4 pointers, // i.e. 32 bytes on 64-bit platforms and 16 bytes in 32-bit platforms. - size_t Granularity = 1ULL << Mapping.Scale; - size_t MinHeaderSize = std::max((size_t)ASan.LongSize / 2, Granularity); + uint64_t Granularity = 1ULL << Mapping.Scale; + uint64_t MinHeaderSize = std::max((uint64_t)ASan.LongSize / 2, Granularity); const ASanStackFrameLayout &L = ComputeASanStackFrameLayout(SVD, Granularity, MinHeaderSize); diff --git a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp index d987d71..cbc508b 100644 --- a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp +++ b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp @@ -38,9 +38,9 @@ static const uint64_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 Granularity, - size_t Alignment) { - size_t Res = 0; +static uint64_t VarAndRedzoneSize(uint64_t Size, uint64_t Granularity, + uint64_t Alignment) { + uint64_t Res = 0; if (Size <= 4) Res = 16; else if (Size <= 16) Res = 32; else if (Size <= 128) Res = Size + 32; @@ -52,7 +52,7 @@ static size_t VarAndRedzoneSize(size_t Size, size_t Granularity, ASanStackFrameLayout ComputeASanStackFrameLayout(SmallVectorImpl &Vars, - size_t Granularity, size_t MinHeaderSize) { + uint64_t Granularity, uint64_t MinHeaderSize) { assert(Granularity >= 8 && Granularity <= 64 && (Granularity & (Granularity - 1)) == 0); assert(MinHeaderSize >= 16 && (MinHeaderSize & (MinHeaderSize - 1)) == 0 && @@ -67,22 +67,22 @@ ComputeASanStackFrameLayout(SmallVectorImpl &Vars, ASanStackFrameLayout Layout; Layout.Granularity = Granularity; Layout.FrameAlignment = std::max(Granularity, Vars[0].Alignment); - size_t Offset = std::max(std::max(MinHeaderSize, Granularity), - Vars[0].Alignment); + uint64_t Offset = + std::max(std::max(MinHeaderSize, Granularity), Vars[0].Alignment); assert((Offset % Granularity) == 0); for (size_t i = 0; i < NumVars; i++) { bool IsLast = i == NumVars - 1; - size_t Alignment = std::max(Granularity, Vars[i].Alignment); + uint64_t Alignment = std::max(Granularity, Vars[i].Alignment); (void)Alignment; // Used only in asserts. - size_t Size = Vars[i].Size; + uint64_t Size = Vars[i].Size; assert((Alignment & (Alignment - 1)) == 0); assert(Layout.FrameAlignment >= Alignment); assert((Offset % Alignment) == 0); assert(Size > 0); - size_t NextAlignment = IsLast ? Granularity - : std::max(Granularity, Vars[i + 1].Alignment); - size_t SizeWithRedzone = VarAndRedzoneSize(Size, Granularity, - NextAlignment); + uint64_t NextAlignment = + IsLast ? Granularity : std::max(Granularity, Vars[i + 1].Alignment); + uint64_t SizeWithRedzone = + VarAndRedzoneSize(Size, Granularity, NextAlignment); Vars[i].Offset = Offset; Offset += SizeWithRedzone; } @@ -118,7 +118,7 @@ GetShadowBytes(const SmallVectorImpl &Vars, assert(Vars.size() > 0); SmallVector SB; SB.clear(); - const size_t Granularity = Layout.Granularity; + const uint64_t Granularity = Layout.Granularity; SB.resize(Vars[0].Offset / Granularity, kAsanStackLeftRedzoneMagic); for (const auto &Var : Vars) { SB.resize(Var.Offset / Granularity, kAsanStackMidRedzoneMagic); @@ -135,13 +135,13 @@ SmallVector GetShadowBytesAfterScope( const SmallVectorImpl &Vars, const ASanStackFrameLayout &Layout) { SmallVector SB = GetShadowBytes(Vars, Layout); - const size_t Granularity = Layout.Granularity; + const uint64_t Granularity = Layout.Granularity; for (const auto &Var : Vars) { assert(Var.LifetimeSize <= Var.Size); - const size_t LifetimeShadowSize = + const uint64_t LifetimeShadowSize = (Var.LifetimeSize + Granularity - 1) / Granularity; - const size_t Offset = Var.Offset / Granularity; + const uint64_t Offset = Var.Offset / Granularity; std::fill(SB.begin() + Offset, SB.begin() + Offset + LifetimeShadowSize, kAsanStackUseAfterScopeMagic); } -- 2.7.4