Repository navigation
Description
Summary
A libc function whose name collides with the With prelude (write, read,
print, ...) called from a goto-containing function migrates to a call
that references the renamed spelling (write_) with no binding for it,
and without the use std.libc the older migrator injected. The output does
not compile: error: undefined variable ... write_.
This is distinct from #882 (the macro-session SIGSEGV, fixed by 33a14ef). It
surfaced while re-migrating zlib for #880: with the segfault fixed, gz_comp
reached the goto-CFG value lowerer.
Repro
#include <unistd.h>
struct S { int fd; const void *next_in; unsigned avail_in; };
int gz_comp(struct S *state, unsigned put) {
int writ = 0;
loop:
if (state->avail_in == 0) goto done;
writ = (int)write(state->fd, state->next_in, put); // <-- goto path
if (writ < 0) goto done;
state->avail_in -= (unsigned)writ;
goto loop;
done:
return writ;
}
What happens today (at HEAD, 33a14ef)
The goto-CFG call lowerer's final branch calls
ci_note_filtered_system_symbol_ref_at(session, callee_cursor, callee_text, FN)
with callee_text == "write_" — the renamed spelling. The allowlist
(ci_libc_symbol_kind_mask) keys on the original name write, so write_
is treated as an unhandled filtered system symbol and the whole function bails
loudly: unsupported assignment rhs in goto CFG (kind=117). Honest, but
gz_comp is untranslatable, so zlib-migrate stops at gzwrite.c.
The two-part fix (a partial one is worse — see below)
-
Filter on the original name. The normal DECL_REF path
(CImport.w:8618) filters onwith_ci_cursor_spelling(the original). The
goto path should recover the original callee name
(ci_call_callee_name(callee_cursor)) and filter on that, sowriteis
allowed and noted (ci_migrate_note_libc_symbol), which drives the
use std.libcinjection (ci_migrate_insert_libc_use). -
Emit a resolvable callee. Even with (1), the emitted call still names
write_, which nothing defines —std.libcexportswrite
(lib/std/libc.w:89), notwrite_. The pre-c-migrate: designated inits over payload-enum carriers (tag + anonymous union) are untranslatable #749 migrator emitted the
originalwrite(...)and relied onuse std.libc(see the old committed
lib/std/zlib/gzwrite.wgz_comp:write((unsafe *__param_state).fd, ...)
withuse std.libc). So the goto call to an allowed libc function must
emit the original name (resolving throughstd.libc), not the
ci_migrate_c_function_name-renamedwrite_.
Do not land (1) without (2). I tried (1) alone: it makes the migrator
"succeed" and emit write_(...) with no binding and no use std.libc, i.e.
silently-uncompilable output — a no-silent-fallbacks regression strictly worse
than the current loud bail. (That attempt was reverted; only the #882 segfault
fix is at HEAD.)
Blocks
#880's zlib re-migration. With both parts, all 15/15 zlib units migrate and
:zlib-test passes (verified during the reverted attempt — the emission was
the last gap, and the use std.libc + original-name form is what the working
old output uses). pcre2 is independently blocked by #883.
Activity
ehartford commentedon Aug 21, 2026
Broader than goto — the normal path fails too, and it's a #749 regression
A one-function non-goto repro fails migration at HEAD:
So this is NOT specific to the goto-CFG lowerer — the migrator cannot migrate
any call to a prelude-collision libc function (
write,read,print,eprint,ewrite, and theassert/check/... family) regardless of controlflow. The error here fires while processing the declaration of
write(unistd.h:508), i.e. a filter site is handed the renamed
write_and rejectsit because the allowlist keys on
write.The committed
lib/std/zlibworks only because it was migrated before#749 added the
write -> write_prelude-collision rename (ci_escape_reserved,CImport.w:5257-5260). The old output calls
write(...)withuse std.libc;the current migrator produces
write_and bails.Corrected fix scope
Every place that passes a name to
ci_note_filtered_system_symbol_ref/_ref_at(and any decl-emission filter for these symbols) must key on theoriginal C name, and the emitted call must name the original (resolving
through
std.libc, which exportswrite/etc.), not thewrite_rename. Thisneeds a sweep of the filter/emission sites in both the normal and goto paths,
plus a c-migrator-tests case (
write/readcall → compiles + runs), then thezlib re-migration.
Not goto-CFG-local; retitling in spirit to "migrator cannot migrate calls to
prelude-collision libc functions (write/read/print/...)".
ehartford commentedon Aug 22, 2026
Fixed (d3c1df7 + 18c22226, battery in flight)
Root cause was the CALL emission, not just the filter:
ci_escape_reserved(#749) renames a prelude-collision name to
write_for definitions, and thecall emission used the same renamed spelling — so the allowlist (keyed on the
original) rejected
write_, and any emittedwrite_(...)referenced a namenothing defines. Both the normal and goto paths were affected (the value-IR
lowerer routes its callee through the same DECL_REF emission at CImport.w:8610).
Fix:
ci_migrate_call_callee_namereturns the original name for an allowedlibc function (else
ci_migrate_c_function_name); the DECL_REF emission usesit. A CALL then resolves through
std.libc(auto-imported byci_migrate_insert_libc_use), whosewrite(fd, buf, count)is selected overthe prelude's
write(&str)by arity.writeis in fact the only name that isboth a prelude-collision and a libc function, so the change is tightly scoped.
Verified before committing (the lesson from the earlier reverted attempt — a
migrator fix isn't done until the output compiles + the library's suite
passes):
writemigrate towrite(...)+use std.libcandcheckclean;c-migrator-coretestprelude_collision_libc_callasserts theoriginal name, no
write_, the import, and a clean check;:zlib-testpasses, andbehav_zlib_std.wpasses against the promoted library.
lib/std/zlibis re-promoted;tools/rt_decl_audit.wdrops 13 -> 7 (zlibcleared). Closing once the battery + reseed lands. The remaining 7 audit rows
are pcre2 (
#883).ehartford commentedon Aug 22, 2026
Split: migrator fix lands; the zlib re-migration is blocked by an -O1 bug
The migrator fix + c-migrator test (d3c1df7) is kept and batterying now — it's
validated independently (both repros migrate to
write(...)+use std.libcand check clean; the new
prelude_collision_libc_calltest asserts it).The zlib re-promotion (18c22226) was reverted: the re-migrated zlib is
correct at -O0 but decompresses wrong at -O1 (Z_DATA_ERROR through the
std.zlibinflate path), while the committed/old zlib is fine at -O1. That's aseparate compiler/-O1 miscompile filed as #885.
:zlib-test(example/minigzip) passed at -O1, so it's specific to the inflate modules the
wrapper exercises.
So this issue (the migrator can't emit prelude-collision libc calls) is fixed
by d3c1df7. #880's zlib re-migration now needs #885 (the -O1 inflate bug), and
pcre2 needs #883.
migrate: calls to prelude-collision libc functions keep the original …
ehartford commentedon Aug 31, 2026
Triage 2026-08-31: CLOSE (overcome by events). Fixed by d3c1df7 "migrate: calls to prelude-collision libc functions keep the original name (#884)" — re-migrated lib/std/zlib/gzwrite.w has
use std.libc, callswrite(...)by its original name (zerowrite_occurrences), and the zlib re-migration this blocked landed (ca91e09).