You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
c_import("stdlib.h") no longer exposes malloc/realloc when clang_bridge.o is rebuilt by stage2 #74
When clang_bridge.o is rebuilt by stage2 rather than copied from the seed runtime, c_import("stdlib.h") no longer exposes allocator symbols like malloc and realloc.
Spec reference: docs/with-specification.md §16.1 c_import: imported C functions are made available as With symbols and are callable directly.
Repro
Minimal shape:
use c_import("stdlib.h")
fn main:
let raw = malloc(8)
let _ = realloc(raw.unwrap(), 0)
malloc and realloc imported from stdlib.h should resolve as callable With symbols.
Actual
Stage2 reports undefined variable for imported allocator functions.
Notes
This only surfaced once stage2 actually rebuilt rt/clang_bridge.w and produced a fresh clang_bridge.o; the same tests had been masked when a seed-built bridge object was copied into place.
Likely subsystem: c_import translation / symbol emission in the stage2-built clang_bridge path.
Root cause: @[callconv("c")] stored the raw string-literal token text, including quotes, so codegen saw "c" instead of c and skipped the C ABI lowering path for defined functions. That left stage2-built clang_bridge.w visitor callbacks taking CXCursor by value instead of the indirect C ABI form, so clang_visitChildren passed garbage cursors and declaration collection returned zero results.
The fix normalizes callconv metadata in the parser, keeps codegen defensive by stripping accidental quotes, and preserves the large-struct C ABI lowering path for defined callconv/C-export functions.
Verified with:
make build
make selfcheck
make fixpoint
a minimal @[callconv("c")] large-struct IR probe
a stage2-built clang_bridge.o probe against stdlib.h and malloc/_malloc.h
the original malloc c_import repro with an empty cache
Activity
ehartford commentedon Apr 6, 2026
Fixed by
56f189a.Root cause:
@[callconv("c")]stored the raw string-literal token text, including quotes, so codegen saw"c"instead ofcand skipped the C ABI lowering path for defined functions. That left stage2-builtclang_bridge.wvisitor callbacks takingCXCursorby value instead of the indirect C ABI form, soclang_visitChildrenpassed garbage cursors and declaration collection returned zero results.The fix normalizes
callconvmetadata in the parser, keeps codegen defensive by stripping accidental quotes, and preserves the large-struct C ABI lowering path for defined callconv/C-export functions.Verified with:
make buildmake selfcheckmake fixpoint@[callconv("c")]large-struct IR probeclang_bridge.oprobe againststdlib.handmalloc/_malloc.hmallocc_import repro with an empty cacheSeparate follow-up for cache invalidation: #79.