Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust-for-Linux: Allow pointers acceptable in const expression in inline assembly #132012

Open
dingxiangfei2009 opened this issue Oct 21, 2024 · 3 comments
Assignees
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-rust-for-linux Relevant for the Rust-for-Linux project C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dingxiangfei2009
Copy link
Contributor

dingxiangfei2009 commented Oct 21, 2024

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>

@dingxiangfei2009 dingxiangfei2009 added the C-bug Category: This is a bug. label Oct 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 21, 2024
@dingxiangfei2009
Copy link
Contributor Author

I am trying a quick implementation on it.

@rustbot claim

@workingjubilee workingjubilee added A-inline-assembly Area: Inline assembly (`asm!(…)`) A-rust-for-linux Relevant for the Rust-for-Linux project T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 21, 2024
@nbdd0121
Copy link
Contributor

This was tracked by #128464 and I have been working on it for a couple of days now. While the codegen change needed was simple, the typeck/borrowck aspect of this was really non-trivial.

@dingxiangfei2009
Copy link
Contributor Author

Thanks for pointing that out @nbdd0121 ! Is there a tracking issue for the string interpolating constraint in asm!? If not yet, I can create it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-rust-for-linux Relevant for the Rust-for-Linux project C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants