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 migrator: cond ? &a->f : &b->f becomes &raw const (if cond: a.f else: b.f), the address of a temporary copy #2314
Spec §15.13: &raw takes the address of a place; an if expression is a value, so &raw const (if c: x.f else: y.f) copies the chosen field into a temporary and points at the copy.
Where.lib/std/re/pcre2_substitute.w:592 and :627 (the migrated pcre2 corpus):
The C is memcpy(&gcontext.memctl, (mcontext == NULL)? &code->memctl : &mcontext->memctl, sizeof(gcontext.memctl));. The migrator moved the & out of the conditional. Here the copy happens to read the same bytes, but if the callee kept the pointer it would dangle; the translation changes meaning.
Repro. Source-check pcre2 (any compiler checking lib/std/re from source instead of its bundle, e.g. a stage1 whose bundles are not built yet): warning: \&raw const` requires a place; this expression is not a place` at both sites.
Expected. The migrator emits if c: &raw const (*code).memctl else: &raw const (*mcontext).memctl. The address of each arm stays in its arm, as C wrote it.
Also. That the compiler only warns here, where &raw mut is an error, is worth a look: a pointer to a temporary is never what the source meant.
Also red on stage1 (not the release binary): behav_c_facade_pending_producer_warns asserts no warning from with check, and a stage1 built from main (3d03845 and the #2366 branch) prints this warning twice from lib/std/re/pcre2_substitute.w:593 and :628 (&raw const (if … : a.memctl else: b.memctl), the migrated cond ? &a->f : &b->f). The release compiler compiled from the same tree does not print it, so with-stage1 test test/behavior shows a red the battery never sees. behav_1944_comptime_snapshot_memory likewise fails only on stage1 (committed=31590464 of the 33554432 limit).
Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce. The migrator now takes the address in each branch, and the re-promoted pcre2 corpus no longer contains &raw const (if.
$ cat input.c
void g(struct S *a, struct S *b, int c, int *out) { memcpy(out, c ? &a->f : &b->f, sizeof(int)); }
$ with migrate input.c -o out.w
… (if __param_c != 0: ((&raw const (*__param_a).f as *const i32) as *mut i32) else: ((&raw const (*__param_b).f as *const i32) as *mut i32)) …
$ grep -c "&raw const (if" lib/std/engines/pcre2/pcre2_substitute.w
0
Activity
ehartford commentedon Oct 14, 2026
Also red on stage1 (not the release binary):
behav_c_facade_pending_producer_warnsasserts no warning fromwith check, and a stage1 built from main (3d03845 and the #2366 branch) prints this warning twice fromlib/std/re/pcre2_substitute.w:593and:628(&raw const (if … : a.memctl else: b.memctl), the migratedcond ? &a->f : &b->f). The release compiler compiled from the same tree does not print it, sowith-stage1 test test/behaviorshows a red the battery never sees.behav_1944_comptime_snapshot_memorylikewise fails only on stage1 (committed=31590464 of the 33554432 limit).ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): does not reproduce. The migrator now takes the address in each branch, and the re-promoted pcre2 corpus no longer contains&raw const (if.