Skip to content

Pitfall: GCC 6.5 tests the wrong byte with btst on a value in memory - #57

Merged
WDrijver merged 2 commits into
mainfrom
pitfall/gcc-btst-memory-bit-number
Nov 17, 2026
Merged

WDrijver merged 2 commits into
mainfrom
pitfall/gcc-btst-memory-bit-number

Conversation

@WDrijver

Copy link
Copy Markdown
Contributor

New pitfall toolchain/pitfalls/gcc-btst-memory-bit-number.md (status draft, origin ai-assisted, owner WDrijver).

What it covers

ApolloCrossDev's GCC 6.5 compiles a one-bit test on an int/short in memory (if (info[i] & 2), if (*req & MEMF_CLEAR)) as btst with a bit number below 0 on the operand's first byte, e.g. btst #-23,(a3) instead of btst #1,(3,a3). btst on memory uses only the low three bits of the number, so the wrong byte is tested. The cause is in *tst_bftst_mem, *tst_bftst_mem1 and *tst_bftst_mem2 (m68k.md); it is not the bbb pass.

Checks

Knowledge base files relied on

  • toolchain/compiler-variants.md (which variant applies which patches)
  • toolchain/pitfalls/gcc-bbb-shift-wrong-code.md and gcc-bbb-autoinc.md (format, and to rule out the bbb pass)

Evidence

Measured and source-level: compiler output with and without the patch; ApolloOS R10 (7662 C files) compiled both ways (4 sites, otherwise identical assembly); Regina REXX on a V4 (Core 12856) before and after.

🤖 Generated with Claude Code

*tst_bftst_mem/_mem1/_mem2 used bit number 7 - POS on the operand's first
byte, giving e.g. btst #-23,(a3) for bit 1 of a long. Found in ApolloOS R10;
fixed by ApolloCrossDev PR #26. Workaround for older installs:
-mno-bitfield. Includes a kb:compile check (kb:expect-not btst #-).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WDrijver
WDrijver requested a review from TuKo1982 as a code owner November 16, 2026 20:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WDrijver
WDrijver merged commit 4868ca0 into main Nov 17, 2026
3 of 4 checks passed
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.

1 participant