[Instrumentation] Use std::clamp (NFC)
authorKazu Hirata <kazu@google.com>
Mon, 29 Aug 2022 06:28:57 +0000 (23:28 -0700)
committerKazu Hirata <kazu@google.com>
Mon, 29 Aug 2022 06:28:57 +0000 (23:28 -0700)
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

index b8d4f68..8805d37 100644 (file)
@@ -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)