wcc: reject module-scope alloc/call let initializers at check time
A module-scope let whose rhs runs code (alloc, call — peeled through
cast/?/! wrappers) emitted no DATAW slot: emit_lets' fold-fail
silently skipped the definition and every reference died at LINK
time with 'undefined reference', the one unacceptable failure mode
(rule 7). Hare's model rejects at check time (ref/harec/src/
check.c:4360 'Unable to evaluate initializer at compile time') and
routes runtime init through @init, which ww does not have — so both
frontends now reject at the declaration with identical wording.
alias_infptr_global flips compile->error as the alloc pin (its
letvartnode N_TPTR-over-N_TSTRUCT coverage lives on in the local
alias_infptr_{nest,slicecap} siblings); callinit_global_reject pins
the call shape. Corpus pin 1741/345/21/209/1166/3482.
This commit is contained in:
@@ -3126,6 +3126,26 @@ check_file(Checker *c, Node *file)
|
||||
if (t)
|
||||
require_sized(c, t, d->pos, "a variable");
|
||||
d->type = t;
|
||||
/* A module-scope initializer must be link-time data:
|
||||
* an alloc/call rhs runs code, emit_lets' fold-fail
|
||||
* skipped the DATAW slot silently, and every
|
||||
* reference died at LINK time ("undefined reference")
|
||||
* — reject at the declaration instead (rule 7).
|
||||
* Hare rejects at check time too (ref/harec/src/
|
||||
* check.c:4360 "Unable to evaluate initializer at
|
||||
* compile time"); ww has no @init path. */
|
||||
{
|
||||
Node *r = d->rhs;
|
||||
while (r != NULL && (r->kind == N_CAST
|
||||
|| r->kind == N_TRYPROP
|
||||
|| r->kind == N_TRYUNW))
|
||||
r = r->lhs;
|
||||
if (r != NULL && (r->kind == N_ALLOC
|
||||
|| r->kind == N_CALL))
|
||||
err(c, d->pos, "module-scope let %s: "
|
||||
"runtime initializer unsupported "
|
||||
"(alloc/call; rule 7)", d->str);
|
||||
}
|
||||
if (d->str && d->str[0]) {
|
||||
Sym *prev = scope_lookup_local(c->cur, d->str);
|
||||
const char *mod = decl_mod(file, d);
|
||||
|
||||
Reference in New Issue
Block a user