Repository navigation
Conversation
|
can't repro |
16c7299 to
51e6673
Compare
|
Re "can't repro": the warning only shows up if Steps to reproduce (against That fails with 8 Building the same command against this branch's I also rebased the branch onto the latest |
|
i don't see it on ubuntu... [cktan]% |
cell_realloc()'s header-before-payload pattern and its call sites that cast the returned char* back to a wider-aligned pointer type trigger -Wcast-align under -Werror. The casts are safe: p is always either REALLOC()'s own return value, or p - sizeof(cell_t) recovers that exact same, maximally-aligned pointer -- the compiler just can't prove it from byte-level pointer arithmetic on a char*. Route each cast through an intermediate (void *), the standard idiom for a deliberate alignment-increasing cast. No behavioral change.
The review of this PR stalled on "can't repro": the same command that reports eight errors for me reports none on an x86-64 Ubuntu box. Both observations are correct, and the reason is the compiler. -Wcast-align is not implied by -Wall or -Wextra, and gcc's plain -Wcast-align is a no-op on x86-64 -- gcc only reports it on targets that genuinely require the stricter alignment. clang reports it on any target. So `cc -Wcast-align` is silent when cc is gcc on x86-64, and noisy when cc is clang, which is exactly the split in the thread. Measured on the commit before this fix: gcc -Wall -Wextra -Wcast-align -> 0 diagnostics gcc -Wall -Wextra -Wcast-align=strict -> 8 diagnostics clang -Wall -Wextra -Wcast-align -> 8 diagnostics and on this fix, all three report 0. Rather than leave that as a footnote in a comment thread, add a CI job running both spellings with -Werror, so the warning is reproducible on either compiler and a regression shows up as a failing check instead of an argument. Verified that the job's exact commands pass on this commit and fail on its parent, so it is not vacuous. Also rebased onto current main: the branch was ten commits behind, and the merge is clean with no new cast sites introduced in the meantime.
51e6673 to
029dc93
Compare
|
Found it -- we're both right, and it's the compiler.
Measured on the commit before the fix: and on this branch, all three report 0. To reproduce on your Ubuntu box without installing anything, add Rather than leave that buried in this thread, I've pushed a CI job Also rebased onto current Entirely reasonable to take the CI job and skip the source change if you |
cell_realloc()'s header-before-payload pattern and its call sites that cast the returned char* back to a wider-aligned pointer type trigger -Wcast-align under -Werror. The casts are safe: p is always either REALLOC()'s own return value, or p - sizeof(cell_t) recovers that exact same, maximally-aligned pointer -- the compiler just can't prove it from byte-level pointer arithmetic on a char*. Route each cast through an intermediate (void *), the standard idiom for a deliberate alignment-increasing cast. No behavioral change.