Skip to content
Closed
7 changes: 5 additions & 2 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if fn_abi.can_unwind { unwind } else { mir::UnwindAction::Unreachable },
)?;
// Sanity-check that `eval_fn_call` either pushed a new frame or
// did a jump to another block.
if self.frame_idx() == old_stack && self.frame().loc == old_loc {
// did a jump to another block. We disable the sanity check for functions that
// can't return, since Miri sometimes does have to keep the location the same
// for those (which is fine since execution will continue on a different thread).
if target.is_some() && self.frame_idx() == old_stack && self.frame().loc == old_loc
{
span_bug!(terminator.source_info.span, "evaluating this call made no progress");
}
}
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2956,11 +2956,6 @@ impl Target {
matches!(self.linker_flavor, LinkerFlavor::Bpf),
"`linker_flavor` must be `bpf` if and only if `arch` is `bpf`"
);
check_eq!(
self.arch == Arch::Nvptx64,
matches!(self.linker_flavor, LinkerFlavor::Ptx),
"`linker_flavor` must be `ptc` if and only if `arch` is `nvptx64`"
);

for args in [
&self.pre_link_args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub(crate) fn target() -> Target {
options: TargetOptions {
os: Os::Cuda,
vendor: "nvidia".into(),
linker_flavor: LinkerFlavor::Ptx,
// The linker can be installed from `crates.io`.
linker: Some("rust-ptx-linker".into()),
linker_flavor: LinkerFlavor::Llbc,

// With `ptx-linker` approach, it can be later overridden via link flags.
cpu: "sm_30".into(),
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ impl Step for Miri {
// miri tests need to know about the stage sysroot
cargo.env("MIRI_SYSROOT", &miri_sysroot);
cargo.env("MIRI_HOST_SYSROOT", &host_sysroot);
cargo.env("MIRI", &miri.tool_path);

// Set the target.
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
Expand Down
4 changes: 2 additions & 2 deletions src/doc/rustc/src/platform-support/nvptx64-nvidia-cuda.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ platform.

## Requirements

This target is `no_std` and will typically be built with crate-type `cdylib` and `-C linker-flavor=llbc`, which generates PTX.
This target is `no_std`, and uses the `llvm-bitcode-linker` by default. For PTX output, build with crate-type `cdylib`.
The necessary components for this workflow are:

- `rustup toolchain add nightly`
Expand All @@ -38,7 +38,7 @@ While the compiler accepts `#[target_feature(enable = "ptx80", enable = "sm_89")
A `no_std` crate containing one or more functions with `extern "ptx-kernel"` can be compiled to PTX using a command like the following.

```console
$ RUSTFLAGS='-Ctarget-cpu=sm_89' cargo +nightly rustc --target=nvptx64-nvidia-cuda -Zbuild-std=core --crate-type=cdylib -- -Clinker-flavor=llbc -Zunstable-options
$ RUSTFLAGS='-Ctarget-cpu=sm_89' cargo +nightly rustc --target=nvptx64-nvidia-cuda -Zbuild-std=core --crate-type=cdylib
```

Intrinsics in `core::arch::nvptx` may use `#[cfg(target_feature = "...")]`, thus it's necessary to use `-Zbuild-std=core` with appropriate `RUSTFLAGS`. The following components are needed for this workflow:
Expand Down
17 changes: 11 additions & 6 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::{BytePos, FileName, Symbol};
use rustc_span::{BytePos, FileName, RemapPathScopeComponents, Symbol};
use tracing::info;

use super::print_item::{full_path, print_item, print_item_path};
Expand Down Expand Up @@ -365,7 +365,10 @@ impl<'tcx> Context<'tcx> {

// We can safely ignore synthetic `SourceFile`s.
let file = match span.filename(self.sess()) {
FileName::Real(ref path) => path.local_path()?.to_path_buf(),
FileName::Real(ref path) => path
.local_path()
.unwrap_or(path.path(RemapPathScopeComponents::MACRO))
.to_path_buf(),
_ => return None,
};
let file = &file;
Expand Down Expand Up @@ -499,10 +502,12 @@ impl<'tcx> Context<'tcx> {
} = options;

let src_root = match krate.src(tcx) {
FileName::Real(ref p) => match p.local_path().map(|p| p.parent()).flatten() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
},
FileName::Real(ref p) => {
match p.local_path().unwrap_or(p.path(RemapPathScopeComponents::MACRO)).parent() {
Some(p) => p.to_path_buf(),
None => PathBuf::new(),
}
}
_ => PathBuf::new(),
};
// If user passed in `--playground-url` arg, we fill in crate name here
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
code,
crate::concurrency::ExitType::ExitCalled,
)?;
todo!(); // FIXME(genmc): Add a way to return here that is allowed to not do progress (can't use existing EmulateItemResult variants).
return interp_ok(EmulateItemResult::AlreadyJumped);
}
throw_machine_stop!(TerminationInfo::Exit { code, leak_check: false });
}
Expand Down
9 changes: 9 additions & 0 deletions src/tools/miri/tests/genmc/fail/shims/exit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ compile-flags: -Zmiri-genmc -Zmiri-disable-stacked-borrows

fn main() {
std::thread::spawn(|| {
unsafe { std::hint::unreachable_unchecked() }; //~ERROR: entering unreachable code
});
// If we exit immediately, we might entirely miss the UB in the other thread.
std::process::exit(0);
}
126 changes: 126 additions & 0 deletions src/tools/miri/tests/genmc/fail/shims/exit.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
Running GenMC Verification...
warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures.
--> RUSTLIB/std/src/thread/mod.rs:LL:CC
|
LL | match COUNTER.compare_exchange_weak(last, id, Ordering::Relaxed, Ordering::Relaxed) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code
|
= note: BACKTRACE:
= note: inside `std::thread::ThreadId::new` at RUSTLIB/std/src/thread/mod.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/thread/current.rs:LL:CC
= note: inside `std::thread::current::id::get_or_init` at RUSTLIB/std/src/thread/current.rs:LL:CC
= note: inside `std::thread::current_id` at RUSTLIB/std/src/thread/current.rs:LL:CC
= note: inside `std::rt::init` at RUSTLIB/std/src/rt.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/rt.rs:LL:CC
= note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at RUSTLIB/std/src/panic.rs:LL:CC
= note: inside `std::rt::lang_start_internal` at RUSTLIB/std/src/rt.rs:LL:CC
= note: inside `std::rt::lang_start::<()>` at RUSTLIB/std/src/rt.rs:LL:CC

warning: GenMC currently does not model the failure ordering for `compare_exchange`. Due to success ordering 'Acquire', the failure ordering 'Relaxed' is treated like 'Acquire'. Miri with GenMC might miss bugs related to this memory access.
--> RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC
|
LL | || self
| ________________^
LL | | .state
LL | | .compare_exchange_weak(state, state + READ_LOCKED, Acquire, Relaxed)
| |____________________________________________________________________________________^ GenMC might miss possible behaviors of this code
|
= note: BACKTRACE:
= note: inside `std::sys::sync::PLATFORM::futex::RwLock::read` at RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC
= note: inside `std::sync::RwLock::<()>::read` at RUSTLIB/std/src/sync/poison/rwlock.rs:LL:CC
= note: inside `std::sys::env::PLATFORM::env_read_lock` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr_stack::<std::option::Option<std::ffi::OsString>>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr::<std::option::Option<std::ffi::OsString>>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
= note: inside `std::sys::env::PLATFORM::getenv` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC
= note: inside `std::env::_var_os` at RUSTLIB/std/src/env.rs:LL:CC
= note: inside `std::env::var_os::<&str>` at RUSTLIB/std/src/env.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/thread/mod.rs:LL:CC
note: inside `main`
--> tests/genmc/fail/shims/exit.rs:LL:CC
|
LL | / std::thread::spawn(|| {
LL | | unsafe { std::hint::unreachable_unchecked() };
LL | | });
| |______^

warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures.
--> RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC
|
LL | || self
| ________________^
LL | | .state
LL | | .compare_exchange_weak(state, state + READ_LOCKED, Acquire, Relaxed)
| |____________________________________________________________________________________^ GenMC might miss possible behaviors of this code
|
= note: BACKTRACE:
= note: inside `std::sys::sync::PLATFORM::futex::RwLock::read` at RUSTLIB/std/src/sys/sync/PLATFORM/futex.rs:LL:CC
= note: inside `std::sync::RwLock::<()>::read` at RUSTLIB/std/src/sync/poison/rwlock.rs:LL:CC
= note: inside `std::sys::env::PLATFORM::env_read_lock` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr_stack::<std::option::Option<std::ffi::OsString>>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
= note: inside `std::sys::pal::PLATFORM::small_c_string::run_with_cstr::<std::option::Option<std::ffi::OsString>>` at RUSTLIB/std/src/sys/pal/PLATFORM/small_c_string.rs:LL:CC
= note: inside `std::sys::env::PLATFORM::getenv` at RUSTLIB/std/src/sys/env/PLATFORM.rs:LL:CC
= note: inside `std::env::_var_os` at RUSTLIB/std/src/env.rs:LL:CC
= note: inside `std::env::var_os::<&str>` at RUSTLIB/std/src/env.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/thread/mod.rs:LL:CC
note: inside `main`
--> tests/genmc/fail/shims/exit.rs:LL:CC
|
LL | / std::thread::spawn(|| {
LL | | unsafe { std::hint::unreachable_unchecked() };
LL | | });
| |______^

warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures.
--> RUSTLIB/std/src/rt.rs:LL:CC
|
LL | / CLEANUP.call_once(|| unsafe {
LL | | // Flush stdout and disable buffering.
LL | | crate::io::cleanup();
... |
LL | | });
| |______^ GenMC might miss possible behaviors of this code
|
= note: BACKTRACE:
= note: inside `std::rt::cleanup` at RUSTLIB/std/src/rt.rs:LL:CC
= note: inside `std::process::exit` at RUSTLIB/std/src/process.rs:LL:CC
note: inside `main`
--> tests/genmc/fail/shims/exit.rs:LL:CC
|
LL | std::process::exit(0);
| ^^^^^^^^^^^^^^^^^^^^^

warning: GenMC currently does not model the failure ordering for `compare_exchange`. Due to success ordering 'Acquire', the failure ordering 'Relaxed' is treated like 'Acquire'. Miri with GenMC might miss bugs related to this memory access.
--> RUSTLIB/std/src/sys/exit_guard.rs:LL:CC
|
LL | match EXITING_THREAD_ID.compare_exchange(ptr::null_mut(), this_thread_id, Acquire, Relaxed) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code
|
= note: BACKTRACE:
= note: inside `std::sys::exit_guard::unique_thread_exit` at RUSTLIB/std/src/sys/exit_guard.rs:LL:CC
= note: inside `std::sys::pal::PLATFORM::os::exit` at RUSTLIB/std/src/sys/pal/PLATFORM/os.rs:LL:CC
= note: inside `std::process::exit` at RUSTLIB/std/src/process.rs:LL:CC
note: inside `main`
--> tests/genmc/fail/shims/exit.rs:LL:CC
|
LL | std::process::exit(0);
| ^^^^^^^^^^^^^^^^^^^^^

error: Undefined Behavior: entering unreachable code
--> tests/genmc/fail/shims/exit.rs:LL:CC
|
LL | unsafe { std::hint::unreachable_unchecked() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

note: add `-Zmiri-genmc-print-genmc-output` to MIRIFLAGS to see the detailed GenMC error report

error: aborting due to 1 previous error; 5 warnings emitted

2 changes: 1 addition & 1 deletion src/tools/miri/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum Mode {
}

fn miri_path() -> PathBuf {
PathBuf::from(env::var("MIRI").unwrap_or_else(|_| env!("CARGO_BIN_EXE_miri").into()))
env!("CARGO_BIN_EXE_miri").into()
}

// Build the shared object file for testing native function calls.
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/nvptx-arch-default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -Z unstable-options -Clinker-flavor=llbc
//@ compile-flags: --crate-type cdylib
//@ only-nvptx64

#![no_std]
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/nvptx-arch-target-cpu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_50 -Z unstable-options -Clinker-flavor=llbc
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_50
//@ only-nvptx64

#![no_std]
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/nvptx-c-abi-arg-v7.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86
//@ only-nvptx64

// The PTX ABI stability is tied to major versions of the PTX ISA
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/nvptx-c-abi-ret-v7.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86
//@ only-nvptx64

// The PTX ABI stability is tied to major versions of the PTX ISA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86
//@ only-nvptx64

// The following ABI tests are made with nvcc 11.6 does.
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly-llvm/nvptx-safe-naming.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -Z unstable-options -Clinker-flavor=llbc
//@ compile-flags: --crate-type cdylib
//@ only-nvptx64
//@ revisions: LLVM20 LLVM21
//@ [LLVM21] min-llvm-version: 21
Expand Down
11 changes: 11 additions & 0 deletions tests/rustdoc/auxiliary/remapped-paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ compile-flags:-Zunstable-options --remap-path-prefix={{src-base}}=

pub struct MyStruct {
field: u32,
}

impl MyStruct {
pub fn new() -> MyStruct {
MyStruct { field: 3 }
}
}
19 changes: 19 additions & 0 deletions tests/rustdoc/import-remapped-paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This is a regression for `--remap-path-prefix` in an auxiliary dependency.
//
// We want to make sure that we can still have the "Source" links to the dependency
// even if its paths are remapped.
//
// See also rust-lang/rust#150100

//@ aux-build:remapped-paths.rs
//@ build-aux-docs

#![crate_name = "foo"]

extern crate remapped_paths;

//@ has foo/struct.MyStruct.html
//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#3"]' 'Source'
//@ has - '//a[@href="../src/remapped_paths/remapped-paths.rs.html#8"]' 'Source'

pub use remapped_paths::MyStruct;
Loading