bugfix: cfront — sqlite3 aggregate crash from inline struct pointer field
Track: A+C
Status: done
Priority: high
Resolution
Fixed 2026-06-28. The original VdbeCursor/bitfield diagnosis was stale: direct
full-amalgamation probes now show PXX and GCC agree on VdbeCursor and the
nearby VDBE layouts.
The actual aggregate-query crash was in findOrCreateAggInfoFunc:
struct AggInfo_func *pItem = pAggInfo->aFunc;
if( pItem->pFExpr==pExpr ) ...
ParseCStructInto handled inline nested aggregate members by value, but did not
handle declarators with stars after the closing brace:
struct AggInfo_func { ... } *aFunc;
The parser skipped those pointer fields, so later pAggInfo->aFunc resolved as
offset 0. At runtime that read the first byte fields of AggInfo as a pointer,
producing a sign-extended bogus address and a segfault.
Fix: the inline nested aggregate branch now parses per-declarator *, records
tyPointer fields with the nested record as the pointee for one-star
declarators, uses pointer size/alignment for layout, and preserves by-value
nested aggregate behavior.
Guards:
test/cinline_struct_ptr_field_b129.ctest/csqlite_extended_test.cnow completes through aggregate query:COUNT,SUM,AVG, and close all succeed.
Problem
/tmp/sq_full — pxx-compiled sqlite3 amalgamation — crashes with SIGSEGV at
address 0x0 when exercised (crash at 0x4b74ab, dereferencing a NULL aOp
field of Vdbe). Root cause investigation over two sessions points to struct
layout mismatches from the bitfield packing bug (see sibling ticket).
Session work summary
-
Session
d7edc492(~2026-06-28 16:50):- Built
sq_fullfromlibrary_candidates/sqlite/sqlite3.cvia pxx - Confirmed GDB crash: NULL pointer dereference in Vdbe VDBE operation
- Disassembled caller at
0x4b73e6, traced it to a field access at offset0x88 = 136into a struct, which is past what GCC saysVdbeCursorshould be (sizeof = 120) - Confirmed pxx computes
VdbeCursor.uc = 48,pKeyInfo = 56on a simplified mock vs GCC'suc = 40,pKeyInfo = 48 - Identified bitfield storage unit bug as root cause
- Built
-
Current session
3c6d84a7(~2026-06-28 18:07):- Verified
bftest.csimplified struct gives matching results pxx vs GCC (seekHit=6for both) — so the packing is not always wrong, only in specific layout combinations involving the real VdbeCursor - Did NOT run
csqlite_layout_probe.cagainst the full sqlite3.c — that is the first next step
- Verified
Next steps
-
Run
compiler/pascal26 -Ilib/crtl/src test/csqlite_layout_probe.c /tmp/probe && /tmp/probeCompare output to GCC-compiled version:gcc -Ilib/crtl/src library_candidates/sqlite/sqlite3.c test/csqlite_layout_probe.c -o /tmp/probe_gcc && /tmp/probe_gcc(Note: GCC won't compile our crtl headers directly — use the approach fromsizes_gccthat was built previously, or use-DSQLITE_THREADSAFE=0and standard headers.) -
Fix the bitfield packing (see sibling ticket) and re-build
/tmp/sq_full. -
Verify the crash is gone.
Files
test/csqlite_layout_probe.c— layout probe test (exists)test/csqlite_extended_test.c— functional test (exists)library_candidates/sqlite/sqlite3.c— the amalgamationcompiler/cparser.inc— fix site