Skip to content

add multi-arch asm! label operand test #143227

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/ui/asm/label-operand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//@ run-pass
//@ needs-asm-support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to fail on targets that aren't x86, arm or risc-v. Either add a fallback or split this into separate tests that are only enabled for that particular architecture.

//@ reference: asm.operand-type.supported-operands.label

use std::arch::asm;

#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "arm64ec"))]
fn make_true(value: &mut bool) {
unsafe {
asm!(
"b {}",
label {
*value = true;
}
);
}
}

#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
fn make_true(value: &mut bool) {
unsafe {
asm!(
"j {}",
label {
*value = true;
}
);
}
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn make_true(value: &mut bool) {
unsafe {
asm!(
"jmp {}",
label {
*value = true;
}
);
}
}

fn main() {
let mut value = false;
make_true(&mut value);
assert!(value);
}
Loading