From 2ad7fd3ac7af15de84713d0e81fc7eeffd320aad Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 28 Aug 2022 23:28:57 -0700 Subject: [PATCH] [Instrumentation] Use std::clamp (NFC) The use of std::clamp should be safe here. MinRZ is at most 32, while kMaxRZ is 1 << 18, so we have MinRZ <= kMaxRZ, avoiding the undefind behavior of std::clamp. --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index b8d4f68..8805d37 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2398,7 +2398,7 @@ ModuleAddressSanitizer::getRedzoneSizeForGlobal(uint64_t SizeInBytes) const { RZ = MinRZ - SizeInBytes; } else { // Calculate RZ, where MinRZ <= RZ <= MaxRZ, and RZ ~ 1/4 * SizeInBytes. - RZ = std::max(MinRZ, std::min(kMaxRZ, (SizeInBytes / MinRZ / 4) * MinRZ)); + RZ = std::clamp((SizeInBytes / MinRZ / 4) * MinRZ, MinRZ, kMaxRZ); // Round up to multiple of MinRZ. if (SizeInBytes % MinRZ) -- 2.7.4