Skip to content

kencc: `auto <type> <name>;' parses -- root the C23 declarator at LNAME - #609

Merged
staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd
Oct 8, 2026
Merged

staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd

Conversation

@staalmannen

Copy link
Copy Markdown
Owner

The first pcc run over EDG's generated C stopped on the fourth file:

array_new_aligned.c:25 syntax error, last name: __T41392176

autoadlist' began with xdecor', and xdecor -> xdecor2 -> tag -> ltag -> LNAME | LTYPE', so after LAUTO the parser could SHIFT a typedef name as the variable being declared. That collides with cname: LAUTO', the storage-class reduction, and yacc resolves shift/reduce in favour of SHIFT -- so auto size_t x;' took the C23 deduction path, read size_t' as the NAME, and died on the next token.

EDG's C writes `auto ;' for every local: 116,079 of them across 103 of its 133 files, so one conflict blocked the whole port.

-std= would not have fixed this. The conflict is resolved when yacc builds the table, so no runtime flag has a say; and there is no dialect disagreement to arbitrate, because C23 kept auto' as a storage-class specifier and its type inference applies only where auto' is the sole type specifier. Both standards want the same answer. The grammar can decide alone, since size_t' is LTYPE and x' is LNAME: a new autoxdecor' roots the first declarator at LNAME, so LTYPE leaves the shift set and that lookahead reduces to the storage class. *' still shifts -- auto *p = &x;' is deduction, while auto *p;' as a storage class would need implicit int.

Measured with bison, since kencc's sources need Plan 9's <u.h> and <libc.h> and cannot be compiled on the host:

                    before   after

shift/reduce 26 22
reduce/reduce 6 6 (pre-existing, LTYPEOF)
state 417 (adecl) 4 2 LTYPE and '(' shifts gone
state 517 (forexpr) 4 2 same, renumbered from 513

Claude-Session: https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs

The first pcc run over EDG's generated C stopped on the fourth file:

  array_new_aligned.c:25 syntax error, last name: __T41392176

`autoadlist' began with `xdecor', and `xdecor -> xdecor2 -> tag ->
ltag -> LNAME | LTYPE', so after LAUTO the parser could SHIFT a
typedef name as the variable being declared.  That collides with
`cname: LAUTO', the storage-class reduction, and yacc resolves
shift/reduce in favour of SHIFT -- so `auto size_t x;' took the C23
deduction path, read `size_t' as the NAME, and died on the next token.

EDG's C writes `auto <type> <name>;' for every local: 116,079 of them
across 103 of its 133 files, so one conflict blocked the whole port.

-std= would not have fixed this.  The conflict is resolved when yacc
builds the table, so no runtime flag has a say; and there is no
dialect disagreement to arbitrate, because C23 kept `auto' as a
storage-class specifier and its type inference applies only where
`auto' is the sole type specifier.  Both standards want the same
answer.  The grammar can decide alone, since `size_t' is LTYPE and `x'
is LNAME: a new `autoxdecor' roots the first declarator at LNAME, so
LTYPE leaves the shift set and that lookahead reduces to the storage
class.  `*' still shifts -- `auto *p = &x;' is deduction, while
`auto *p;' as a storage class would need implicit int.

Measured with bison, since kencc's sources need Plan 9's <u.h> and
<libc.h> and cannot be compiled on the host:

                        before   after
  shift/reduce            26      22
  reduce/reduce            6       6    (pre-existing, LTYPEOF)
  state 417 (adecl)        4       2    LTYPE and '(' shifts gone
  state 517 (forexpr)      4       2    same, renumbered from 513

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
@staalmannen
staalmannen merged commit 686d880 into main Oct 8, 2026
1 check 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.

2 participants