Repository navigation
Description
A Rust bit intrinsic whose call destination is a dereferenced raw pointer is refused, though the same intrinsic writing to a plain local compiles and runs.
error: [rustc_codegen_cuda] Device codegen failed: PTX generation failed: Lowering failed:
["src/generated_case.rs": line: 21, column: 13] Compilation error: invalid input program.
expected integer type for Rust bit intrinsic
Reproducer
#[custom_mir(dialect = "runtime", phase = "initial")]
fn fn1(mut _1: i32) -> *mut i32 {
mir! {
let _2: ();
{
RET = core::ptr::addr_of_mut!(_1);
Call((*RET) = core::intrinsics::bswap(451059808_i32), ReturnTo(bb1), UnwindUnreachable())
}
bb1 = {
Return()
}
}
}The operand is an i32 literal, so the type the message complains about is not the one the intrinsic was given.
What varies
Four runs on an RTX 5060, compute capability 12.0, CUDA 13.3, changing one thing at a time:
| call destination | callee | result |
|---|---|---|
plain local _3: i32 |
bswap |
compiles, CPU and GPU traces match |
(*_2) where _2: *mut i32 |
ordinary fn |
compiles, CPU and GPU traces match |
(*RET) where RET: *mut i32 |
ordinary fn |
compiles, CPU and GPU traces match |
(*RET) where RET: *mut i32 |
bswap |
rejected |
So neither the deref destination nor the intrinsic is refused on its own. Only their combination is. bitreverse reproduces identically.
Mechanism
cargo oxide pipeline shows the importer giving the intrinsic call a pointer result type:
v327 = mir.constant () [] [value: builtin.integer <451059808: si32>]: <() -> (builtin.integer si32)>;
v328 = mir.call (v327) [] [callee: builtin.string "__cuda_oxide_rust_intrinsic_bswap"]:
<(builtin.integer si32) -> (mir.ptr <builtin.integer si32,mutable:true,addrspace:0>)>;
mir.store (v323, v328) [] []:
<(mir.ptr <mir.ptr <builtin.integer si32,mutable:true,addrspace:0>,mutable:true,addrspace:0>,
mir.ptr <builtin.integer si32,mutable:true,addrspace:0>) -> ()>;
The operand is si32 and the result is mir.ptr<si32>, so the result carries the type of the destination local RET rather than the type of the place (*RET) the call writes. The store that follows then treats the swapped value as a *mut i32 and writes it into RET itself, which models RET = bswap(..) rather than (*RET) = bswap(..).
From there the refusal follows the lowering:
crates/mir-lower/src/convert/ops/call.rs:809reads the result type off the call op.:889casts the LLVM call result to it throughcast_integer_value_to_type.:1474asksinteger_bit_widthfor the width of that target type.:1404reportsexpected integer type for Rust bit intrinsic, the pointer having no width.
Every bit intrinsic runs through the same cast at :889, which is why bitreverse behaves the same way.
The type check is what turns this into a compile error. Given the store the dump shows, an intrinsic result that happened to convert to the destination's type would be written to the pointer rather than through it.
Provenance
Surfaced by seeds 1170, 1202 and 1420 of a rustlantis sweep run with composite_count raised, then reduced to the twelve lines above by hand. Deref destinations are generated in that configuration; the checked-in configuration sets composite_count = 0.
Activity
alejandro-soto-franco commentedon Aug 9, 2026
Minimising a second fuzzer finding, #767, landed on the same root cause as this one, so the two are one fault with two symptoms.
The importer types an intrinsic call from its destination's local rather than from the projected place it writes, at
crates/mir-importer/src/translator/terminator/intrinsics/bitops.rs:107:destination.projectionis dropped, so a deref destination yields the pointer type and a field destination yields the whole aggregate.helpers::emit_function_callthen stores the result withvalue_map.store_local(ctx, destination.local, ..), dropping the projection on the store too, which is the store this issue's dump shows writing intoRETitself.What differs between the two reports is only which check catches it. A deref result is a pointer, which has no width, so it reaches
integer_bit_widthand is refused. A field result on an 8-bitbswaptakes the early bitcast path, which checks nothing, and emits IR that LLVM cannot parse.Ordinary calls escape this because rustc lowers a projected call destination into a call to a temporary followed by a store, so the importer never sees the projection. An intrinsic keeps its projected destination through to codegen.
The same
body.locals()[destination.local].typattern appears at nine further sites undertranslator/terminator/, includingsaturating.rs:66,bigint.rs:72,exact_div.rs:69andfloat_math.rs:626. I have reproducers for the bit intrinsics only, so I have not claimed the others are reachable.#768 refuses the invalid bitcast in
mir-lower, which stops the backend emitting unparseable IR and leaves this fault in place. #769 fixes the fault itself:destination_typetakes the projected place type fromPlace::ty, andstore_result_to_placewrites through the projection, reusing the address helpers intranslator/statement.rsrather than restating them.fix(mir-importer): write through a runtime-index call destination too
fix(mir-importer): write an intrinsic result through its projected de…
feat(fuzzer): fold an aggregate into the trace by its leaves (#792)