Skip to content

make it build with llvm 22 - #240

Merged
vtjnash merged 2 commits into
JuliaHubOSS:masterfrom
el-ev:master
Aug 10, 2026
Merged

vtjnash merged 2 commits into
JuliaHubOSS:masterfrom
el-ev:master

Conversation

@el-ev

@el-ev el-ev commented Aug 2, 2026

Copy link
Copy Markdown

No description provided.

@el-ev

el-ev commented Aug 2, 2026

Copy link
Copy Markdown
Author

Is that a false alarm? for unsigned char, 4294967046 % 256 == 6.

Comment thread lib/Target/CBackend/CBackend.cpp Outdated
@vtjnash

vtjnash commented Aug 10, 2026

Copy link
Copy Markdown
Member

yeah, claude figured out thats a separate bug in the test:

That's test_char_sized_ptr_math_decr — the file you were asking about. And it is not caused by PR 240; it's a latent flake in the test itself.

At -O1/-O2 LLVM folds the whole thing to arithmetic on &a, with zext(trunc i8) narrowed to and 252 (low 2 bits known zero from alignment):

return ((llvm_sub_u32((((uint32_t)(uintptr_t)(&a)) & 252),
(((uint32_t)(uintptr_t)((uint8_t*)(&a) - 4)) & 252))) | 2);

The result depends on the low byte of the stack address of a. Since a is 4-byte aligned, &a & 255 ∈ {0, 4, …, 252}, and the byte-truncated subtraction wraps for exactly one of those 64 values:

addr low byte 0x00 -> 4294967046 <-- the CI failure, 2^32-250
addr low byte 0x40 -> 6
addr low byte 0x04 -> 6

(That's the CBE -O1 body run against forced addresses; 400 consecutive runs of the real binary on Linux gave 6 every time.) So it's a ~1-in-64 stack-address lottery, and the Windows runner drew the losing ticket — the
reference MSVC binary got a non-zero low byte and returned 6, the CBE binary got 0x00. Master's Windows job passed on the run one day earlier with no code difference in this path.

Worth noting the C source has the same address dependence — unsigned char inc0/inc1 with inc0 - inc1 in int arithmetic underflows identically. So the test is testing something genuinely unspecified-ish, not a CBE bug.
The fix belongs in the test (e.g. mask the difference, or compare (unsigned char)(inc0 - inc1)), not in PR 240 — and it's an argument for re-running the Windows job rather than blocking the PR on it.

@vtjnash
vtjnash merged commit a4e7364 into JuliaHubOSS:master Aug 10, 2026
2 of 3 checks passed
vtjnash added a commit that referenced this pull request Aug 11, 2026
…242)

test_char_sized_ptr_math_{incr,decr} truncate two addresses four bytes
apart to unsigned char and subtract them, expecting a difference of 4.
That only holds when the subtraction does not borrow out of the low
byte, so the tests fail whenever the stack happens to place `a` at an
address whose low byte is 0x00 (decr) or 0xfc (incr) -- roughly a 1 in
64 chance, since `a` is 4-byte aligned. This is what failed the Windows
job on #240:

  FAILED test_consistent_return_value_c[test_char_sized_ptr_math_decr--O1]
    - assert 4294967046 == 6

Truncating the difference back to unsigned char makes the result 4 for
every address while still exercising the same char-sized pointer math at
-O0. At -O1 and above the optimizer now folds main() to `return 6`,
which is itself a proof that the result no longer depends on the address.

Separately, check_no_output() treats any stderr as a failure, including
diagnostics that describe the toolchain rather than the code under test.
When the macOS SDK and the Homebrew bottles are built for different OS
versions, every compile emits

  clang: warning: overriding deployment version from '16.0' to '26.0'

which failed all 540 tests on #237 despite an exit code of 0. Filter
that class of environmental warning out before deciding whether the
process misbehaved; real diagnostics are unaffected.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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