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
Bug: string literals over 4095 bytes are silently corrupted at LLVM emission #557
wl_build_global_string_ptr (src/compiler/LlvmBridge.w:853) routes string constant data through to_cstr, which copies into a fixed thread-local 4096-byte slot and truncates at 4095 (LlvmBridge.w:425). Any single string literal longer than 4095 bytes is silently corrupted: the emitted str keeps the correct length but the constant data past 4095 bytes is whatever lives in adjacent cstr slots.
Repro (current shipped compiler)
fn main:
let s = "AAAA...5000 A's..."
print(f"{s.len()}") // 5000 — length is right
if s.byte_at(4500) == 65: print("content ok")
else: print("content CORRUPT") // prints content CORRUPT
Embedded-null literals have the same shape of problem: LLVMBuildGlobalStringPtr takes a C string, so a literal containing \x00 truncates at the null.
Why it went unnoticed
src/InitTemplates.w (the only >4KB string payload in the tree) is generated pre-chunked into <4096-byte ++ pieces — the generator was implicitly working around this. Discovered while implementing #556, whose literal-chain fold merged those chunks back into one constant and produced a corrupted with init AGENTS.md (caught by cli-selfhost-project-tests).
Fix
Emit string constant data length-aware: LLVMConstStringInContext + a private constant global, bypassing to_cstr for the data (names still go through to_cstr; they are short). Blocks #556.
Fixed in 1a42dbf. wl_build_global_string_ptr now emits string constant data via LLVMConstStringInContext with an explicit length and a private constant global — data never touches to_cstr's 4096-byte slot, and embedded nulls survive. Regression test: test/behavior/behav_str_large_literal.w (5000-byte single literal, content verified past the old truncation point). Verified: the previously-corrupted 26KB folded init template now emits byte-identical to docs/with_for_ai.md.
Activity
Emit string constants length-aware in the LLVM bridge
ehartford commentedon Jun 12, 2026
Fixed in 1a42dbf.
wl_build_global_string_ptrnow emits string constant data viaLLVMConstStringInContextwith an explicit length and a private constant global — data never touchesto_cstr's 4096-byte slot, and embedded nulls survive. Regression test:test/behavior/behav_str_large_literal.w(5000-byte single literal, content verified past the old truncation point). Verified: the previously-corrupted 26KB folded init template now emits byte-identical to docs/with_for_ai.md.