Skip to content

Fixed to handle composite types in conditional expressions#14

Open
mycoboco wants to merge 1 commit into
drh:masterfrom
mycoboco:compose-on-cond
Open

Fixed to handle composite types in conditional expressions#14
mycoboco wants to merge 1 commit into
drh:masterfrom
mycoboco:compose-on-cond

Conversation

@mycoboco
Copy link
Copy Markdown

lcc currently fails to correctly handle composite types in conditoinal expressions. For example,

void foo(void)
{
    extern int cond;
    int (*a)[], (*b)[10], (*c)[20];

    c = cond? a: b;
    c = cond? b: a;
}

The two assignments to c are both invalid, but lcc complains that only the latter is.

This commit fixes the problem by adding two calls to composite() when checking types for conditional expressions.

AJBats added a commit to AJBats/saturncc that referenced this pull request Apr 18, 2026
LCC's front-end wraps `int + int_disp` results in LOAD(LOAD(...))
nodes when the value is cast to pointer for INDIR. This blocks the
compound `reg: INDIRI2(ADDI4(reg,immi8))` dispload rule from
matching — the INDIRI2 sees LOAD, not ADDI4, as its direct child.

The `char * + int_disp` path produces ADDP4 directly (no LOAD
wrappers) and the compound rule matches cleanly. Same ABI either
way — both pass in r4 as a 32-bit value.

Impact:
- FUN_06044834: 20 -> 16 diffs vs prod.
- All three .w loads now use displacement mode:
    mov.w @(14,r4),r0    (was: mov r4,r1; add drh#14,r1; mov.w @r1,r1)
    mov.w @(26,r4),r0
    mov.w @(30,r4),r0

Remaining 16-diff divergence decomposes into three gaps, tracked
for proof-of-thesis progress:
- Gap 9: 3x redundant `exts.w` (SH-2's mov.w already sign-extends)
- peephole: 2x extra `mov r0,rN; add rN,r1` vs prod's direct `add r0,r1`
- Gap 2: prod uses indexed for offsets 26 and 30 despite both
  fitting .w disp range (max 30). SHC heuristic under investigation.

Baseline re-pinned. All 28 validate_build stages green; broad
corpus 168/168 unchanged.

Co-Authored-By: Claude Opus 4.7 (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.

1 participant