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

Allow pointers in inline assembly const expressions #132012

Closed
dingxiangfei2009 opened this issue Oct 21, 2024 · 5 comments
Closed

Allow pointers in inline assembly const expressions #132012

dingxiangfei2009 opened this issue Oct 21, 2024 · 5 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.

@tgross35 tgross35 changed the title Rust-for-Linux: Allow pointers acceptable in const expression in inline assembly Allow pointers in inline assembly const expressions Oct 23, 2024
@tgross35
Copy link
Contributor

(adjusted the title since there isn't anything RFL-specific here)

@tgross35
Copy link
Contributor

Ah - actually since #128464 already tracks poointers in asm const, I think this issue can just be closed. Feel free to reopen if that isn't accurate.

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.

I think it would be good to create this, I haven't seen one around.

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

5 participants