Skip to content

Empty target_features confuses Miri #1438

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

Closed
y21 opened this issue Dec 22, 2023 · 2 comments
Closed

Empty target_features confuses Miri #1438

y21 opened this issue Dec 22, 2023 · 2 comments
Labels
A-core-arch Area: Necessary for full core::arch support

Comments

@y21
Copy link
Member

y21 commented Dec 22, 2023

Running RUSTFLAGS="-Zcodegen-backend=cranelift" cargo miri test on the following test trips up Miri.

#[test]
fn f() {
    std::hint::spin_loop();
}
$ RUSTFLAGS="-Zcodegen-backend=cranelift" cargo miri test
test f ... error: Undefined Behavior: attempted to call intrinsic `llvm.x86.sse2.pause` that requires missing target feature sse2
  --> /home/timo/.rustup/toolchains/nightly-2023-12-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs:25:5
   |
25 |     pause()
   |     ^^^^^^^ attempted to call intrinsic `llvm.x86.sse2.pause` that requires missing target feature sse2

I'm guessing the problem is this FIXME here?

fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
vec![] // FIXME necessary for #[cfg(target_feature]
}

spin_loop has a #[cfg(target_arch = "x86_64")] (which evaluates to true) in which it executes an sse2 instruction

@bjorn3
Copy link
Member

bjorn3 commented Dec 22, 2023

I'm guessing the problem is this FIXME here?

Indeed. Fixing this is non-trivial as the logic to determine the final set of target features is split out between rustc and the LLVM in case of the LLVM backend. Getting everything to match with Cranelift is not that easy. I do intend to do it eventually and likely do some refactorings to rustc to simplify this, but other things have taken priority.

spin_loop has a #[cfg(target_arch = "x86_64")] (which evaluates to true) in which it executes an sse2 instruction

As it happens this intrinsic is not actually UB to execute without sse2. On x86 processors without sse2 support it decodes as a nop instruction. For many intrinsics it is indeed a problem to execute them when the cpu doesn't support it though.

@bjorn3 bjorn3 closed this as completed in 45d8c12 Jan 2, 2024
@bjorn3
Copy link
Member

bjorn3 commented Jan 2, 2024

Should be fixed now by unconditionally returning SSE2 as supported.

@bjorn3 bjorn3 added the A-core-arch Area: Necessary for full core::arch support label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core-arch Area: Necessary for full core::arch support
Projects
None yet
Development

No branches or pull requests

2 participants