Repository navigation
Description
Problem
Global const and static declarations accept character and string literal initializers during check, but fail LLVM constant evaluation during build. Equivalent local literals compile and execute correctly.
The literal evaluator in llvm/src/codegen/consts.rs handles bool, integer, and float literals but lacks the corresponding character/string paths.
Reproduction
Save as repro.wave:
const letter: char = 'A';
fun main() -> i32 { return letter as i32 - 65; }
target/release/wavec check repro.wave
target/release/wavec build repro.wave -O0 --emit=ir,obj --out-dir /tmp/wave-audit-reproRepeat with -O2. Tested on master 5002a93a4a233032553aa6c6e3639d88e93c53bf with Fedora Linux 43 amd64 and LLVM 21.1.8, using LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --release --jobs 2.
check succeeds. Both O0/O2 builds fail with E9002 and unsupported const expression ... Literal(Char('A')). static letter: char = 'A' fails similarly.
The same mismatch occurs for const message: str = "hi" and static message: str = "hi", when main reads message[0]: E9002 reports Literal(String([104, 105])). Local char/string controls pass.
Scope
Support character values and addressable string data through the existing global literal initialization contract. Preserve char width, exact hex bytes, UTF-8 source characters, automatic trailing NUL, and the existing embedded-NUL rejection. Keep const and static binding rules unchanged; do not add general runtime global initialization.
Completion criteria
- Character/string literal globals accepted by
checkbuild successfully and retain exact values at O0/O2. - Cover const/static, empty and nonempty strings, non-ASCII bytes, and access from another function.
- Emitted data and pointer relocations follow target layout, including 32-bit WebAssembly and native 64-bit targets.
- Unsupported constant expressions still receive actionable diagnostics.
Activity