diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1587,9 +1587,15 @@ for (GlobalVariable *GV : Globals) { Tag &= TagMaskByte; - // Skip tag 0 in order to avoid collisions with untagged memory. - if (Tag == 0) + if (ClUseShortGranules && Tag < 16) { + // Don't allow globals to be tagged with something that looks like a + // short-granule tag, otherwise we lose inter-granule overflow detection, + // as the fast path shadow-vs-address check succeeds. + Tag = 16; + } else if (Tag == 0) { + // Skip tag 0 in order to avoid collisions with untagged memory. Tag = 1; + } instrumentGlobal(GV, Tag++); } }