[llvm] 2ad7fd3 - [Instrumentation] Use std::clamp (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 28 23:29:19 PDT 2022


Author: Kazu Hirata
Date: 2022-08-28T23:28:57-07:00
New Revision: 2ad7fd3ac7af15de84713d0e81fc7eeffd320aad

URL: https://github.com/llvm/llvm-project/commit/2ad7fd3ac7af15de84713d0e81fc7eeffd320aad
DIFF: https://github.com/llvm/llvm-project/commit/2ad7fd3ac7af15de84713d0e81fc7eeffd320aad.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index b8d4f68c00bc2..8805d379d9ae3 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)


        


More information about the llvm-commits mailing list