<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/94175>94175</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [compiler-rt]: hwasan fails to build on x32 with LLVM 17, works fine with LLVM 18 and later
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          glaubitz
      </td>
    </tr>
</table>

<pre>
    For Debian unstable, I need to build LLVM 17 for x32 (x86_64 with 32-bit pointers).

However, this fails due to the newly introduced `hwasan` which has no switch to be disabled:

```
FAILED: compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o 
/<<PKGBUILDDIR>>/build-llvm/bin/clang++ --target=x86_64-linux-gnux32 -DHWASAN_WITH_INTERCEPTORS=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/.. -fstack-protector-strong -Wformat -Werror=format-security -fcf-protection -Wno-unused-command-line-argument -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fdebug-prefix-map=/<<PKGBUILDDIR>>/build-llvm/runtimes/runtimes-bins=build-llvm/runtimes/runtimes-bins -fdebug-prefix-map=/<<PKGBUILDDIR>>/= -no-canonical-prefixes -ffile-prefix-map=/<<PKGBUILDDIR>>/build-llvm/runtimes/runtimes-bins=build-llvm/runtimes/runtimes-bins -ffile-prefix-map=/<<PKGBUILDDIR>>/= -no-canonical-prefixes -Wall -Wno-unused-parameter -O3 -DNDEBUG -std=c++17 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -ffreestanding -Wno-format -MD -MT compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o -MF compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o.d -o compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o -c /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_linux.cpp
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_linux.cpp:32:
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan.h:71:16: error: constexpr variable 'kAddressTagMask' must be initialized by a constant expression
   71 | constexpr uptr kAddressTagMask = kTagMask << kAddressTagShift;
      |                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan.h:71:43: note: shift count 57 >= width of type 'uptr' (aka 'unsigned int') (32 bits)
   71 | constexpr uptr kAddressTagMask = kTagMask << kAddressTagShift;
      | ^
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan.h:93:36: warning: shift count >= width of type [-Wshift-count-overflow]
   93 |   return InTaggableRegion(p) ? ((p >> kAddressTagShift) & kTagMask) : 0;
      | ^ ~~~~~~~~~~~~~~~~
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan.h:108:53: warning: shift count >= width of type [-Wshift-count-overflow]
  108 | ? ((p & ~kAddressTagMask) | ((uptr)tag << kAddressTagShift))
 |                                                     ^ ~~~~~~~~~~~~~~~~
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_linux.cpp:37:
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_thread.h:16:
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_allocator.h:69:47: warning: shift count >= width of type [-Wshift-count-overflow]
   69 | static const uptr kMaxAllowedMallocSize = 1UL << 40;  // 1T
      | ^ ~~
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_allocator.h:72:33: warning: implicit conversion from 'unsigned long long' to 'const uptr' (aka 'const unsigned int') changes value from 18446744073709551615 to 4294967295 [-Wconstant-conversion]
   72 |   static const uptr kSpaceBeg = ~0ULL;
 |                     ~~~~~~~~~ ^~~~~
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_allocator.h:78:34: warning: implicit conversion from 'unsigned long long' to 'const uptr' (aka 'const unsigned int') changes value from 4398046511104 to 0 [-Wconstant-conversion]
   78 |   static const uptr kSpaceSize = 0x40000000000ULL;  // 4T.
      |                     ~~~~~~~~~~ ^~~~~~~~~~~~~~~~
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_linux.cpp:37:
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_thread.h:16:
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_allocator.h:20:
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/../lsan/lsan_common.h:17:
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_allocator.h:74:
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_allocator_primary64.h:639:17: error: static assertion failed due to requirement 'kRegionSize >= SizeClassMap<3, 4, 8, 17, 128, 16>::kMaxSize'
  639 | static_assert(kRegionSize >= SizeClassMap::kMaxSize);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_allocator_combined.h:26:35: note: in instantiation of template class '__sanitizer::SizeClassAllocator64<__hwasan::AP64>' requested here
   26 | using AllocatorCache = typename PrimaryAllocator::AllocatorCache;
 | ^
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_allocator.h:93:9: note: in instantiation of template class '__sanitizer::CombinedAllocator<__sanitizer::SizeClassAllocator64<__hwasan::AP64>>' requested here
   93 | typedef Allocator::AllocatorCache AllocatorCache;
      | ^
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/../sanitizer_common/sanitizer_allocator_primary64.h:639:29: note: expression evaluates to '0 >= 131072'
  639 | static_assert(kRegionSize >= SizeClassMap::kMaxSize);
      | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_linux.cpp:37:
/<<PKGBUILDDIR>>/compiler-rt/lib/hwasan/hwasan_thread.h:22:22: error: no template named 'CompactRingBuffer' in namespace '__sanitizer'
 22 | typedef __sanitizer::CompactRingBuffer<uptr> StackAllocationsRingBuffer;
      |         ~~~~~~~~~~~~~^
5 warnings and 3 errors generated.
```

Trying to build LLVM 18 on x32 works fine though, so the underlying issue must have been fixed.

I have searched the git log and git blame, but couldn't find any obvious fix. I'm hoping that someone can point me to the set of commits that fix this issue from the tip of their head, so I don't have to bisect LLVM for hours.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWVtT47iX_zTmRaWUIztx8sBDSMh0aqHpgvRS-5RSrGNbiy1lJJlAP_Rn3zqSc6NppmcGZrbqn6KMLUvn8jtXWdxaWSqA82hwEQ1mZ7x1lTbnZc3btXTfztZaPJ_PtSEzWEuuSKus4-saIjYlC6IABHGarFtZC3J19d_XpJ-RQh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