← board

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:

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

Next steps

  1. Run compiler/pascal26 -Ilib/crtl/src test/csqlite_layout_probe.c /tmp/probe && /tmp/probe Compare 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 from sizes_gcc that was built previously, or use -DSQLITE_THREADSAFE=0 and standard headers.)

  2. Fix the bitfield packing (see sibling ticket) and re-build /tmp/sq_full.

  3. Verify the crash is gone.

Files