Skip to content

Fix assert in x86 when using custom align#16145

Merged
acoates-ms merged 3 commits into
microsoft:0.81-stablefrom
acoates-ms:unalignedassertx86
May 15, 2026
Merged

Fix assert in x86 when using custom align#16145
acoates-ms merged 3 commits into
microsoft:0.81-stablefrom
acoates-ms:unalignedassertx86

Conversation

@acoates-ms
Copy link
Copy Markdown
Contributor

@acoates-ms acoates-ms commented May 15, 2026

In x86 scenarios we have the Folly assert triggering in this code:

    FOLLY_ALWAYS_INLINE static uint64_t Read8(const uint64_t* buf, size_t off) {
      if constexpr (kHasUnalignedAccess) {
        uint64_t out;
        FOLLY_BUILTIN_MEMCPY(&out, buf + off, sizeof(out));
        return out;
      } else {
        assert(0 == reinterpret_cast<uintptr_t>(buf) % sizeof(*buf));
        return buf[off];
      }
    }

The analysis had shown that this assert is not correct for the x86 code where the allocated buffer can be aligned by 32-bits instead of 64-bits.

This PR overrides the SpookyHashV2.h so that we comment out the failing assert.
In practice it must not cause any issues:

  • Intel CPUs allow unaligned memory access without issues. The assert prevents some operations that would normally work like in our cause with x86.
  • ARM64 CPUs prohibit unaligned memory access, but if it happens, then we would have an immediate crash at this point. Thus, the assert is redundant.
Microsoft Reviewers: Open in CodeFlow

@acoates-ms acoates-ms requested a review from a team as a code owner May 15, 2026 18:07
@acoates-ms acoates-ms merged commit 8620c45 into microsoft:0.81-stable May 15, 2026
4 of 35 checks passed
@acoates-ms acoates-ms deleted the unalignedassertx86 branch May 15, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants