Skip to content

Codegen: monomorphizing a generic function inside an async: block leaks async_block_rbuf (LLVM verification failure) #3038

Closed

Description

@ehartford

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

  1. added
    spec-gap
    on Nov 5, 2026
  2. added a commit that references this issue on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    spec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions