[llvm] 6efcb27 - [HWASan] Fix UB in tag-bits mask shift (#202269)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 23:16:39 PDT 2026


Author: Maosu Zhao
Date: 2026-06-09T06:16:33Z
New Revision: 6efcb27a7436004d7b78473c467a7e00d83deb4a

URL: https://github.com/llvm/llvm-project/commit/6efcb27a7436004d7b78473c467a7e00d83deb4a
DIFF: https://github.com/llvm/llvm-project/commit/6efcb27a7436004d7b78473c467a7e00d83deb4a.diff

LOG: [HWASan] Fix UB in tag-bits mask shift (#202269)

`TagMaskByte &= (1 << ClTagBits) - 1` shifts an `int` literal, which is
undefined behavior for `ClTagBits >= 32`.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 50eecdb168161..230977540bf82 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -687,7 +687,7 @@ void HWAddressSanitizer::initializeModule() {
     if (TagMaskByte < 4)
       reportFatalUsageError(
           "need more than 4 bits of tag to have non-short-granule tags");
-    TagMaskByte &= (1 << ClTagBits) - 1;
+    TagMaskByte &= (1ULL << ClTagBits) - 1;
   }
 
   Mapping.init(TargetTriple, InstrumentWithCalls, CompileKernel);


        


More information about the llvm-commits mailing list