← board

C: sqlite offsetof-style field address in array bound

Symptom

sqlite stopped at:

Expected: ], but got:  (Kind: 81, Line: 91408)
  near:  Parse     >>>  sLastToken
pascal26:91408: error: unexpected token ()

Preprocessed source:

char saveBuf[(sizeof(Parse)-((size_t)&(((Parse *)0)->sLastToken)))];

This is sqlite's offsetof(Parse,sLastToken) expansion (PARSE_RECURSE_SZ) in an automatic array bound.

Cause

ParseCLocalDeclAST evaluates fixed array dimensions with CEvalConstExpr. That folder handled integer arithmetic and sizeof(...), but not unary &. For ((size_t)&(((Parse *)0)->sLastToken)), it consumed the (size_t) cast, then returned 0 at & without consuming the field-address expression. The declarator still saw sLastToken while expecting ].

Fix

CEvalConstPrimary now recognizes unary & for the narrow macro-expanded offsetof shape &(((T *)0)->field). It parses the cast type to recover the record id, returns RecFieldOffset(record, field), and restores the CType globals after the nested ParseCDeclType call.

Regression

Added test/coffsetof_constexpr_array_b104.c, wired into make test-core.

Also rechecked existing nearby coverage:

Result

sqlite advances to:

pascal26:105031: error: call to undeclared function: sqlite3OsDlSym ()

Filed [[bug-c-function-returning-function-pointer-prototype-sqlite]].