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
LLVM backend: a global's initializer folds with silent wrapping; the same expression panics at run time #1773
Spec: §4.2.3 (checked arithmetic panics in all builds unless configured), §9.1c (global initializers are ordinary expressions that run before main).
let K: u32 = 1
let T: [2]i16 = [0, (0 - K)]
fn main:
print(T[1])
let t: [2]i16 = [0, (0 - K)]
print(t[1])
with run (base 76cf0bf stage1): prints -1, then panics integer overflow: u32 subtraction wrapped below zero. The global's initializer is folded by the LLVM backend's constant evaluator (CodegenTraits try_eval_const_llvm) with wrapping arithmetic; the identical expression evaluated as an expression panics.
Expected: the global's initializer overflows exactly as the expression does (a compile-time error if the folder evaluates it, or the startup panic).
Found by #1484: the C backend now runs such initializers as ordinary expressions and panics in std.re's escapes table (26 (0 - ESC_*) on c_uint, see the migrator issue filed beside this one), which this folder hides.
Activity
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 …
Sema records an arithmetic node's type; the LLVM constant folder fold…
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 …
Sema records an arithmetic node's type; the LLVM constant folder fold…
emit-c: a global whose initializer is not a C constant runs before main
Sema/Codegen/migrator: unsuffixed literal arithmetic takes its contex…