Skip to content

Codegen traps (LLVM getTypeSizeInBits on void) on a cast to *const Unit: (u: &Unit) as *const Unit as *mut c_void #1626

Closed

Description

@ehartford

Found by Modeled C stage 12b (#1618): a facade callback method generic in the userdata type U is specialized with U = Unit when the nullable callback is absent, and its body u as *const U as *mut c_void traps the compiler.

Minimal repro (with run):

fn c(u: &Unit) -> *mut c_void: u as *const Unit as *mut c_void
fn main:
    let x = ()
    print(c(x) == null)

Expected: compiles; a pointer cast needs no pointee size. Actual: the compiler exits 133 (SIGTRAP) in llvm::DataLayout::getTypeSizeInBits(llvm::Type*) — brk #0x1 on the void type — with no diagnostic (lldb: EXC_BREAKPOINT in getTypeSizeInBits, called from the cast lowering).

transmute[*mut c_void](u) of the same value compiles and runs, so the rendered facade method uses that (FacadeRender.w facade_render_callback_methods, the nullable branch). Remove that workaround when this is fixed. A silent trap is also a tool that stayed silent: the cast lowering should reject or handle a zero-sized pointee, never reach LLVM's assertion.

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