Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

spirv-std inline asm! should use MaybeUninit<T> instead of let mut result = T::default();. #1007

@eddyb

Description

@eddyb

We have a few different ways to extract results from asm!:

  • old unsound approach (UB because of OpReturnValue, so it's getting replaced)
asm! {
    "%result = ...",
    "OpReturnValue %result",
    options(noreturn),
}
  • old approach (sound, but requires T: Default)
let mut result = T::default();
asm!(
    "%result = ...",
    "OpStore {result} %result",
    result = in(reg) &mut result,
);
result
let mut result_slot = core::mem::MaybeUninit::uninit();
asm! {
    "%result = ...",
    "OpStore {result_slot} %result",
    result_slot = in(reg) result_slot.as_mut_ptr(),
}
result_slot.assume_init()

In #1006 only the unsound uses of asm!("OpReturnValue") were fixed (i.e. when dealing with opaque handles or &T/&mut T, neither of which implement Default).

However, it might be a good to transition everything uniformly, and maybe even provide a wrapper macro that allows uniformly using asm! with the result slot automatically handled (and even by-ref inputs as well?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: asmIssues related to inline assembly.t: enhancementA new feature or improvement to an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions