Skip to content

Validate callable operand representation after reference projection #1133

Closed

Description

@ehartford

check --validate-all --dump-mir accepts a call whose callee operand is &fn, while codegen invokes that pointer as if it were the stored function value. An indexed C callback array exposes it directly.

use std.libc.atoi
var callbacks: [2]extern "C" fn(*const i8) -> i32 = [atoi, null]
fn main: assert(callbacks[0](c"21".ptr) == 21)

Stage 1 built from e7ddf11 plus the borrowed-binding fix produces:

_15 = ref(shared, _7[_14]);
call copy _15(...) -> ...;

The call needs to project through _15 to read the callable. Native LLDB stopped at the data symbol callbacks (0x10000c000) with EXC_BAD_ACCESS/code=2. x9 held the array-slot address used as the branch target, while x8 already contained libc's valid atoi address. The caller was verify, the migrated callback-array fixture.

Root producer: MirBuilder.lower_call passed lower_expr(fn_expr) directly; D27 indexing correctly produced an exact &fn view, but the call did not load through that view. The Phase 1 change normalizes callable reference places in shared MIR call lowering and continues to consume FnAbi for arguments/results.

Track the validator gap separately: validate that indirect-call operands have an invocable physical value after reference projections, including raw C function pointers, With closure pairs, reference parameters and collection element views. A matching FnAbi signature alone does not establish that the operand holds a callable value.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce. null is no longer a value of a non-optional fn pointer (§16.6), so the array holds two callables; calling through the indexed element works:

    $ cat main2.w
    use std.libc.atoi
    var callbacks: [2]extern "C" fn(*const i8) -> i32 = [atoi, atoi]
    fn main:
        assert(callbacks[0](c"21".ptr) == 21)
        print("ok")
    $ with run main2.w
    ok
    
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions