Skip to content

Support NonNull pointers as asm! input operands - #165008

Open
hsanzg wants to merge 1 commit into
rust-lang:mainfrom
hsanzg:rich-asm-ptr-inputs
Open

hsanzg wants to merge 1 commit into
rust-lang:mainfrom
hsanzg:rich-asm-ptr-inputs

Conversation

@hsanzg

@hsanzg hsanzg commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Currently the asm! macro supports raw (thin) pointers as operands, and references as input operands. As discussed in Zulip, it seems reasonable to extend support to fundamental types with the same ABI as raw pointers. This commit adds support for (thin) NonNull pointer inputs. The reason for not allowing NonNull outputs is that the asm! code has no way to explicitly assert that the safety invariant of NonNull is preserved.

Support for Box<T> and Optional<NonNull<T>> seems a bit more debatable, so that's left as future work (which might require more than a FCP).

I'll make the existing error messages dependent on whether the operand is allowed specifically as an input in a subsequent PR (because it also affects references). Right now the message is a bit too general.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 26, 2026
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 22 candidates

Currently the `asm!` macro supports raw (thin) pointers as operands,
and references as input operands. As discussed in Zulip
(https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/.60NonNull.60s.20as.20register.20operand.20values.20of.20asm.21/with/629100221),
it would be acceptable to extend support to fundamental types with the
same ABI as raw pointers. This commit adds support for (thin) `NonNull`
pointer inputs. The reason for not allowing `NonNull` outputs is that
the `asm!` code has no way to explicitly assert that the safety invariant
of `NonNull` is preserved.
@hsanzg
hsanzg force-pushed the rich-asm-ptr-inputs branch from efa94c9 to 61b2e57 Compare October 26, 2026 22:23
@workingjubilee

Copy link
Copy Markdown
Member

re: that Zulip discussion, Amanieu was critical of this idea in its unqualified form and as our de facto expert in inline asm! for "wrote the code" reasons, I think the specifically input-operand-only version seems... plausible? but should first get a look from

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned davidtwco Oct 27, 2026
@Amanieu

Amanieu commented Oct 29, 2026

Copy link
Copy Markdown
Member

LGTM, but this needs a positive codegen test. The current tests all fail and never reach codegen.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants