diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -546,7 +546,7 @@ Printf("%s\n", s.data()); } -static const u8 kFallbackTag = 0xBB; +static const u8 kFallbackTag = 0xBB & kTagMask; u8 __hwasan_generate_tag() { Thread *t = GetCurrentThread(); diff --git a/compiler-rt/test/hwasan/lit.cfg.py b/compiler-rt/test/hwasan/lit.cfg.py --- a/compiler-rt/test/hwasan/lit.cfg.py +++ b/compiler-rt/test/hwasan/lit.cfg.py @@ -22,6 +22,12 @@ # the x86_64 implementation is for testing purposes only there is no # equivalent target feature implemented on x86_64. clang_hwasan_common_cflags += ["-mcmodel=large"] + + # The callback instrumentation used on x86_64 has a 1/64 chance of choosing a + # stack tag of 0. This causes stack tests to become flaky, so we force tags + # to be generated via calls to __hwasan_generate_tag, which never returns 0. + # TODO: See if we can remove this once we use the outlined instrumentation. + clang_hwasan_common_cflags += ["-mllvm", "-hwasan-generate-tags-with-calls=1"] clang_hwasan_cflags = clang_hwasan_common_cflags + ["-mllvm", "-hwasan-globals", "-mllvm", "-hwasan-use-short-granules", "-mllvm", "-hwasan-instrument-landing-pads=0",