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
Codegen: monomorphizing a generic function inside an async: block leaks async_block_rbuf (LLVM verification failure) #3038
Found during the #2987 manual audit of docs/spec/014_concurrency.md (§14.6, line 289).
Minimal reproduction
use std.channel.chan
fn main:
let (tx, rx) = chan[str](4)
async scope s =>
s.track(async:
tx.send("hello")
drop(tx)
)
s.track(async:
for msg in rx:
print(msg)
)
Actual
with run fails LLVM IR verification when print[str] is monomorphized on demand inside the async: block trampoline:
Referring to an argument in another function!
store i32 undef, ptr %1, align 4
===== INVALID LLVM FUNCTION print__sema__219:2277:128=16 =====
error: LLVM function verification failed after MIR cleanup for print__sema__219:2277:128=16
Root cause
In src/CodegenDispatch.w:19162, gen_async_block sets self.async_block_rbuf = rbuf_arg (parameter %1 of __async_block_N). Closure emission (src/CodegenDispatch.w:17584) saves and clears self.async_block_rbuf = 0, but on-demand monomorphized MIR function emission (gen_mono_function / default trait method emission) does not. When TK_RETURN is lowered for print[str] at src/CodegenDispatch.w:15757, self.async_block_rbuf != 0 triggers the ab.do_store epilogue inside print__sema__..., referencing %1 of __async_block_N.
Pairing async_block_rbuf with async_block_fn (self.current_function == self.async_block_fn) and saving/clearing across nested MIR body emission eliminates the bug across every nested emitter.
Activity
#3038, #3039, #3041, #3042, #2958: five spec-gap fixes from the #2987 …