Skip to content

Allow pointers in inline assembly const expressions #132012

Closed
@dingxiangfei2009

Description

Quoting from tests/ui/asm/const-refs-to-static.rs @ 31e102c

I tried this code:

use std::arch::{asm, global_asm};
use std::ptr::addr_of;

static FOO: u8 = 42;

#[no_mangle]
fn inline() {
    unsafe { asm!("{}", const addr_of!(FOO)) };
}

I expected to see this happen: it should compiles

Instead, this happened: *const u8 is not allowed as an operand to inline assembly.

This would be coming useful and brings us feature-parity with asm(" /* assembly */ " ::"i"(ptr)) from C, where ptr can be pointer to statics and constants.

cc @Amanieu @nbdd0121

Meta

rustc --version --verbose:

<version>
Backtrace

<backtrace>

Metadata

Labels

A-inline-assemblyArea: Inline assembly (`asm!(…)`)A-rust-for-linuxRelevant for the Rust-for-Linux projectC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions