Compiler bugs

The tracker for wrong-code and wrong-parse bugs in the C compiler: every bug fixed in this fork, and the known bugs still open. Most are inherited from the upstream cc65 2.19 base this SDK forked from.

1. How bugs are found and tracked

The compiler is under a standing correctness audit (design/LYNX_COMPILER_AUDIT_DESIGN.md): every test function is compiled at all four optimization levels (no -O, -O, -Oi, -Ors), executed on the headless GearLynx emulator, and its results are compared across levels and against the same source compiled with a host C compiler. Any disagreement is a compiler bug. The audit combines a directed test corpus (tests/compiler/corpus/), a random-program generator (lynxsmith), and mining of the fixes upstream cc65 made after the 2.19 release (tests/compiler/upstream/FIXES.md).

Every bug on this page has an execution-checked regression test that runs in CI (tests/run.sh). Open bugs live in tests/compiler/corpus/known/ marked known-bug; the harness expects them to fail, and the moment a fix lands it flags the stale marker so the entry moves to the fixed table below in the same change.

2. Fixed bugs

FixedComponentBugDetails and tests
2026-07-18
e1ce3e123
expr.c
(ArrayRef)
A constant subscript applied to the address of a struct member reached through a pointer dropped the member offset: ((unsigned char*)&s->vsize)[1] accessed ((unsigned char*)s)[1] instead. Variable subscripts and explicit pointer arithmetic were always correct. Inherited from cc65 2.19; surfaced in the raycaster example as sprite-control bytes overwritten by wall heights. design/LYNX_MEMBER_ADDR_CAST_FIX_DESIGN.md; asm-shape test tests/compiler/member_addr_cast.py; execution tests corpus/member_addr.c, corpus/upstream_shapes.c
2026-07-19
e7262013f
codegen.c
(g_div)
Signed division by a power-of-two constant (n / 2, n / 8, n / 256…) was strength-reduced to a bare arithmetic shift, which rounds toward negative infinity instead of C’s required truncation toward zero: -7 / 2 gave -4 (must be -3), -300 / 256 gave -2 (must be -1). Inherited from cc65 2.19 (upstream fixed it shortly after that release); found by the audit’s host-oracle on the day the audit went live. The fix adds (2^k)-1 to negative 8/16-bit dividends before the shift; signed 32-bit dividends use the runtime divide. Execution tests corpus/sdiv_pow2.c, corpus/sdiv_bounds.c; upstream classification in tests/compiler/upstream/FIXES.md
2026-07-19
6e783c67d
expr.c
(hie_compare)
signed char compared with an unsigned constant could give the wrong truth value: sc > 100u, sc == 0x80u… The char-vs-constant fast path clamped the unsigned constant into char range and compared as a char op. Inherited from cc65 2.19; port of upstream fix d628772cd1: the fast path now requires a signed constant, and mixed signedness compares full-width unsigned, as ISO’s usual arithmetic conversions require. Execution test corpus/scharcmp_uconst.c; upstream classification in tests/compiler/upstream/FIXES.md
2026-07-19
6e783c67d
codegen.c
(g_typeadjust)
expr.c
(hie_compare)
signed long against a smaller unsigned type was compared (and divided) as unsigned: -2L < 40000u came out false. ISO converts the smaller unsigned operand to plain (signed) long — only an unsigned long operand makes the operation unsigned. Inherited from cc65 2.19 (upstream fixed it in c8956ce19b); the fork fix teaches g_typeadjust the usual arithmetic conversions and makes hie_compare’s constant fold and unsigned strength reduction follow the converted common type. Also corrects signed-long / and % with smaller unsigned operands. Execution test corpus/slongcmp_mixed.c; upstream classification in tests/compiler/upstream/FIXES.md
2026-07-19
6e783c67d
parser
(hie11)
A subscript, call, or member operator directly after a postfix ++/-- was rejected with a parse error: p++[0] did not compile (accepts-valid bug, not a miscompile). Inherited from cc65 2.19; port of upstream fix 1450f146a5: postfix ++/-- are handled in hie11’s postfix-operator loop so further postfix operators may follow them. Execution test corpus/upstream_shapes.c (p++[0] shape); upstream classification in tests/compiler/upstream/FIXES.md
2026-07-19
d42945671
coptind.c
(OptDeadCode)
In a jump-table-dispatched switch (5+ dense cases), a case body consisting of a bare infinite loop — case k: for(;;); — was deleted as dead code: the pass’s self-jump exception counted only the visible jump reference and could not see the case label’s reference from the rodata jump table, so dispatching k fell into the next case. Fork-introduced (0d92ee308); found by the phase-4 fork-diff review (T5). design/LYNX_COMPILER_AUDIT_DESIGN.md sec. 9 (F1); shape test tests/compiler/forkdiff_t5.py
2026-07-19
d42945671
expr.c
(fused muldiv)
The fused a !* b !/ c silently truncated a long divisor to 16 bits (c == 0x10000 even became a divide by zero). Now a compile error — the Suzy divider takes 16 bits and the divisor’s type is only known after the fusion is committed; write (a !* b) !/ c to divide by a long through the software routines. Fork-introduced (ad4095a6c); found by the phase-4 fork-diff review (T5). design/LYNX_COMPILER_AUDIT_DESIGN.md sec. 9 (F2); diagnostic test tests/compiler/forkdiff_t5.py
2026-07-19
d42945671
codegen.c
(g_suzydiv)
Signed !/ by a power-of-two constant floored instead of truncating: -7 !/ 2 gave -4 instead of -3. Same class as the g_div bug above, reintroduced by strength-reducing straight to g_asr and bypassing the fixup; now delegates to g_div. Fork-introduced (d2908f2a6); found by the phase-4 fork-diff review (T5). design/LYNX_COMPILER_AUDIT_DESIGN.md sec. 9 (F3); execution test corpus/suzyops.c (constant power-of-two section)

3. Known open bugs

None currently. When the audit confirms a new miscompile it gets an expected-to-fail regression in tests/compiler/corpus/known/, an upstream fix reference in tests/compiler/upstream/FIXES.md, and an entry here with a workaround until it is fixed.