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
CCodegen: a global whose initializer is not a literal is emitted zero-initialized (1 << 3, [7u16, 9u16], Some(3) all become 0) #1484
Found while fixing #1429 (the same file's global_decl_tid fallback). Stage1 of main (base of #1429's branch), --emit-c:
let SHIFTED = 1 << 3
let TABLE = [7u16, 9u16]
let MAYBE = Some(3)
fn main:
print(f"{SHIFTED} {TABLE[1]} {MAYBE.unwrap()}")
The LLVM backend prints 8 9 3. The emitted C initializes all three globals to zero and nothing assigns them later (no init function; main reads them directly):
CCodegen.global_init_text (src/CCodegen.w) renders int/bool/float/string/c-string/null literals and falls through to zero_value_text(tid) — or {0} for an array — for every other initializer: a binary expression, an array literal, a variant constructor, a call. That is a silent fallback (AGENTS.md No Silent Fallbacks): the program compiles and reads different values.
Expected: every initializer the C backend cannot express as a C constant initializer is either lowered (e.g. through the MIR const-init body the LLVM backend runs) or refused with self.fail(...) naming the global and the initializer.
Activity
CCodegen: a global whose type cannot be recovered fails loudly instea…
CCodegen: a global whose type cannot be recovered fails loudly instea…
emit-c: an array of arrays built from its rows copies each row (#1771)
C backend and modeled-C fixes: map loops, generic structs, view compa…
C migrator: an enumeration constant is `int` (C11 6.7.2.2p3), not the…
std.re: re-migrated with `int` enumerators, so pcre2's escapes table …
emit-c: a function returning an array takes the destination as an out…
emit-c: a global whose initializer is not a C constant runs before main
C migrator: an enumeration constant is `int` (C11 6.7.2.2p3), not the…
std.re: re-migrated with `int` enumerators, so pcre2's escapes table …
emit-c: a function returning an array takes the destination as an out…
emit-c: a global whose initializer is not a C constant runs before main