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

Rollup of 10 pull requests #137796

Merged
merged 27 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7061551
Add FileCheck annotations to mir-opt/issues
Shunpoco Dec 30, 2024
736ef0a
Don't error when adding a staticlib with bitcode files compiled by ne…
bjorn3 Feb 14, 2025
9147b6d
Add test
bjorn3 Feb 14, 2025
3a3aede
Update some comparison tests now that they pass in LLVM20
scottmcm Feb 18, 2025
ec45166
Tell llvm-ar to not create a symbol table
bjorn3 Feb 21, 2025
92eb445
tests: use minicore more
davidtwco Feb 24, 2025
9f190d7
Restore usage of io::Error
bjorn3 Feb 26, 2025
4fcebee
Fix Windows `Command` search path bug
ChrisDenton Feb 26, 2025
9a2362a
linker: Fix escaping style for response files on Windows
petrochenkov Feb 26, 2025
e28500d
Re-enable `--generate-link-to-defintion` for tools internal rustdoc
aDotInTheVoid Feb 26, 2025
d8a067b
remove most `simd_` intrinsic declaration in tests
folkertdev Feb 24, 2025
a837e99
simplify some imports with `simd::*`
folkertdev Feb 24, 2025
4e961dc
make `simd_insert` and `simd_extract` `const fn`s
folkertdev Feb 24, 2025
038f4e2
use the right feature in codegen tests
folkertdev Feb 24, 2025
660241d
Fix test directives that were accidentally ignored
yotamofek Feb 24, 2025
0881dba
Move "unused_exter_crate" test from rustdoc-ui to rustdoc
yotamofek Feb 27, 2025
b67b6c0
Fix sized constraint for unsafe binder
compiler-errors Feb 28, 2025
d9c34a7
Rollup merge of #134943 - Shunpoco:116971-mir-opt-issues, r=DianQK
jieyouxu Feb 28, 2025
61e9004
Rollup merge of #137017 - bjorn3:ignore_invalid_bitcode, r=oli-obk
jieyouxu Feb 28, 2025
87cac9f
Rollup merge of #137197 - scottmcm:cmp-20, r=ibraheemdev
jieyouxu Feb 28, 2025
d09523d
Rollup merge of #137540 - yotamofek:pr/more-deprecated-test-directive…
jieyouxu Feb 28, 2025
50ef985
Rollup merge of #137551 - folkertdev:import-simd-intrinsics, r=RalfJung
jieyouxu Feb 28, 2025
50ed7f9
Rollup merge of #137599 - davidtwco:use-minicore-more, r=jieyouxu
jieyouxu Feb 28, 2025
4606610
Rollup merge of #137673 - ChrisDenton:search-path-bug, r=dtolnay
jieyouxu Feb 28, 2025
f1cdd3b
Rollup merge of #137676 - petrochenkov:winresp, r=Kobzol
jieyouxu Feb 28, 2025
9e1ead6
Rollup merge of #137693 - aDotInTheVoid:gaming, r=onur-ozkan,Guillaum…
jieyouxu Feb 28, 2025
0cb9827
Rollup merge of #137770 - compiler-errors:unsafe-binder-sized-crit, r…
jieyouxu Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,33 @@ fn get_llvm_object_symbols(
if err.is_null() {
return Ok(true);
} else {
return Err(unsafe { *Box::from_raw(err as *mut io::Error) });
let error = unsafe { *Box::from_raw(err as *mut io::Error) };
// These are the magic constants for LLVM bitcode files:
// https://github.com/llvm/llvm-project/blob/7eadc1960d199676f04add402bb0aa6f65b7b234/llvm/lib/BinaryFormat/Magic.cpp#L90-L97
if buf.starts_with(&[0xDE, 0xCE, 0x17, 0x0B]) || buf.starts_with(&[b'B', b'C', 0xC0, 0xDE])
{
// For LLVM bitcode, failure to read the symbols is not fatal. The bitcode may have been
// produced by a newer LLVM version that the one linked to rustc. This is fine provided
// that the linker does use said newer LLVM version. We skip writing the symbols for the
// bitcode to the symbol table of the archive. Traditional linkers don't like this, but
// newer linkers like lld, mold and wild ignore the symbol table anyway, so if they link
// against a new enough LLVM it will work out in the end.
// LLVM's archive writer also has this same behavior of only warning about invalid
// bitcode since https://github.com/llvm/llvm-project/pull/96848

// We don't have access to the DiagCtxt here to produce a nice warning in the correct format.
eprintln!("warning: Failed to read symbol table from LLVM bitcode: {}", error);
return Ok(true);
} else {
return Err(error);
}
}

unsafe extern "C" fn callback(state: *mut c_void, symbol_name: *const c_char) -> *mut c_void {
let f = unsafe { &mut *(state as *mut &mut dyn FnMut(&[u8]) -> io::Result<()>) };
match f(unsafe { CStr::from_ptr(symbol_name) }.to_bytes()) {
Ok(()) => std::ptr::null_mut(),
Err(err) => Box::into_raw(Box::new(err)) as *mut c_void,
Err(err) => Box::into_raw(Box::new(err) as Box<io::Error>) as *mut c_void,
}
}

Expand All @@ -148,7 +167,7 @@ fn get_llvm_object_symbols(
Box::into_raw(Box::new(io::Error::new(
io::ErrorKind::Other,
format!("LLVM error: {}", error.to_string_lossy()),
))) as *mut c_void
)) as Box<io::Error>) as *mut c_void
}
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,12 @@ fn exec_linker(
args.push_str(
&Escape {
arg: arg.to_str().unwrap(),
// LLD also uses MSVC-like parsing for @-files by default when running on windows hosts
is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()),
// Windows-style escaping for @-files is used by
// - all linkers targeting MSVC-like targets, including LLD
// - all LLD flavors running on Windows hosts
// С/С++ compilers use Posix-style escaping (except clang-cl, which we do not use).
is_like_msvc: sess.target.is_like_msvc
|| (cfg!(windows) && flavor.uses_lld() && !flavor.uses_cc()),
}
.to_string(),
);
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
| Never
| Dynamic(_, _, ty::DynStar) => None,

UnsafeBinder(_) => todo!(),

// these are never sized
Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty),

Expand All @@ -52,9 +50,14 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
sized_constraint_for_ty(tcx, ty)
}),

// these can be sized or unsized
// these can be sized or unsized.
Param(..) | Alias(..) | Error(_) => Some(ty),

// We cannot instantiate the binder, so just return the *original* type back,
// but only if the inner type has a sized constraint. Thus we skip the binder,
// but don't actually use the result from `sized_constraint_for_ty`.
UnsafeBinder(inner_ty) => sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty),

Placeholder(..) | Bound(..) | Infer(..) => {
bug!("unexpected type `{ty:?}` in sized_constraint_for_ty")
}
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "cmp_partialord_lt"]
fn lt(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Less))
self.partial_cmp(other).is_some_and(Ordering::is_lt)
}

/// Tests less than or equal to (for `self` and `other`) and is used by the
Expand All @@ -1387,7 +1387,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "cmp_partialord_le"]
fn le(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Less | Equal))
self.partial_cmp(other).is_some_and(Ordering::is_le)
}

/// Tests greater than (for `self` and `other`) and is used by the `>`
Expand All @@ -1405,7 +1405,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "cmp_partialord_gt"]
fn gt(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Greater))
self.partial_cmp(other).is_some_and(Ordering::is_gt)
}

/// Tests greater than or equal to (for `self` and `other`) and is used by
Expand All @@ -1423,7 +1423,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "cmp_partialord_ge"]
fn ge(&self, other: &Rhs) -> bool {
matches!(self.partial_cmp(other), Some(Greater | Equal))
self.partial_cmp(other).is_some_and(Ordering::is_ge)
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// `idx` must be in-bounds of the vector.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
pub const unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;

/// Extracts an element from a vector.
///
Expand All @@ -22,7 +22,7 @@ pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
/// `idx` must be in-bounds of the vector.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
pub const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;

/// Adds two simd vectors elementwise.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/pal/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ impl Command {
needs_stdin: bool,
proc_thread_attribute_list: Option<&ProcThreadAttributeList<'_>>,
) -> io::Result<(Process, StdioPipes)> {
let env_saw_path = self.env.have_changed_path();
let maybe_env = self.env.capture_if_changed();

let child_paths = if let Some(env) = maybe_env.as_ref() {
let child_paths = if env_saw_path && let Some(env) = maybe_env.as_ref() {
env.get(&EnvKey::new("PATH")).map(|s| s.as_os_str())
} else {
None
Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,7 @@ macro_rules! tool_doc {
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");
cargo.rustdocflag("--enable-index-page");
cargo.rustdocflag("--show-type-layout");
// FIXME: `--generate-link-to-definition` tries to resolve cfged out code
// see https://github.com/rust-lang/rust/pull/122066#issuecomment-1983049222
// cargo.rustdocflag("--generate-link-to-definition");
cargo.rustdocflag("--generate-link-to-definition");

let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");
$(for krate in $crates {
Expand Down
20 changes: 16 additions & 4 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ impl Step for Cargotest {
.args(builder.config.test_args())
.env("RUSTC", builder.rustc(compiler))
.env("RUSTDOC", builder.rustdoc(compiler));
add_rustdoc_cargo_linker_args(&mut cmd, builder, compiler.host, LldThreads::No);
add_rustdoc_cargo_linker_args(
&mut cmd,
builder,
compiler.host,
LldThreads::No,
compiler.stage,
);
cmd.delay_failure().run(builder);
}
}
Expand Down Expand Up @@ -847,7 +853,7 @@ impl Step for RustdocTheme {
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
.env("RUSTC_BOOTSTRAP", "1");
cmd.args(linker_args(builder, self.compiler.host, LldThreads::No));
cmd.args(linker_args(builder, self.compiler.host, LldThreads::No, self.compiler.stage));

cmd.delay_failure().run(builder);
}
Expand Down Expand Up @@ -1023,7 +1029,13 @@ impl Step for RustdocGUI {
cmd.env("RUSTDOC", builder.rustdoc(self.compiler))
.env("RUSTC", builder.rustc(self.compiler));

add_rustdoc_cargo_linker_args(&mut cmd, builder, self.compiler.host, LldThreads::No);
add_rustdoc_cargo_linker_args(
&mut cmd,
builder,
self.compiler.host,
LldThreads::No,
self.compiler.stage,
);

for path in &builder.paths {
if let Some(p) = helpers::is_valid_test_suite_arg(path, "tests/rustdoc-gui", builder) {
Expand Down Expand Up @@ -1887,7 +1899,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the

let mut hostflags = flags.clone();
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
hostflags.extend(linker_flags(builder, compiler.host, LldThreads::No));
hostflags.extend(linker_flags(builder, compiler.host, LldThreads::No, compiler.stage));

let mut targetflags = flags;
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Cargo {
}
}

for arg in linker_args(builder, compiler.host, LldThreads::Yes) {
for arg in linker_args(builder, compiler.host, LldThreads::Yes, 0) {
self.hostflags.arg(&arg);
}

Expand All @@ -270,10 +270,10 @@ impl Cargo {
}
// We want to set -Clinker using Cargo, therefore we only call `linker_flags` and not
// `linker_args` here.
for flag in linker_flags(builder, target, LldThreads::Yes) {
for flag in linker_flags(builder, target, LldThreads::Yes, compiler.stage) {
self.rustflags.arg(&flag);
}
for arg in linker_args(builder, target, LldThreads::Yes) {
for arg in linker_args(builder, target, LldThreads::Yes, compiler.stage) {
self.rustdocflags.arg(&arg);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ impl<'a> Builder<'a> {
cmd.arg("-Dwarnings");
}
cmd.arg("-Znormalize-docs");
cmd.args(linker_args(self, compiler.host, LldThreads::Yes));
cmd.args(linker_args(self, compiler.host, LldThreads::Yes, compiler.stage));
cmd
}

Expand Down
14 changes: 11 additions & 3 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ pub fn linker_args(
builder: &Builder<'_>,
target: TargetSelection,
lld_threads: LldThreads,
stage: u32,
) -> Vec<String> {
let mut args = linker_flags(builder, target, lld_threads);
let mut args = linker_flags(builder, target, lld_threads, stage);

if let Some(linker) = builder.linker(target) {
args.push(format!("-Clinker={}", linker.display()));
Expand All @@ -446,12 +447,18 @@ pub fn linker_flags(
builder: &Builder<'_>,
target: TargetSelection,
lld_threads: LldThreads,
stage: u32,
) -> Vec<String> {
let mut args = vec![];
if !builder.is_lld_direct_linker(target) && builder.config.lld_mode.is_used() {
match builder.config.lld_mode {
LldMode::External => {
args.push("-Clinker-flavor=gnu-lld-cc".to_string());
// cfg(bootstrap) - remove after updating bootstrap compiler (#137498)
if stage == 0 && target.is_windows() {
args.push("-Clink-arg=-fuse-ld=lld".to_string());
} else {
args.push("-Clinker-flavor=gnu-lld-cc".to_string());
}
// FIXME(kobzol): remove this flag once MCP510 gets stabilized
args.push("-Zunstable-options".to_string());
}
Expand Down Expand Up @@ -479,8 +486,9 @@ pub fn add_rustdoc_cargo_linker_args(
builder: &Builder<'_>,
target: TargetSelection,
lld_threads: LldThreads,
stage: u32,
) {
let args = linker_args(builder, target, lld_threads);
let args = linker_args(builder, target, lld_threads, stage);
let mut flags = cmd
.get_envs()
.find_map(|(k, v)| if k == OsStr::new("RUSTDOCFLAGS") { v } else { None })
Expand Down
5 changes: 3 additions & 2 deletions tests/assembly/aarch64-pointer-auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Test that PAC instructions are emitted when branch-protection is specified.

//@ add-core-stubs
//@ revisions: PACRET PAUTHLR_NOP PAUTHLR
//@ assembly-output: emit-asm
//@ needs-llvm-components: aarch64
Expand All @@ -14,8 +15,8 @@
#![no_core]
#![crate_type = "lib"]

#[lang = "sized"]
trait Sized {}
extern crate minicore;
use minicore::*;

// PACRET: hint #25
// PACRET: hint #29
Expand Down
8 changes: 4 additions & 4 deletions tests/assembly/cmse.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ add-core-stubs
//@ revisions: hard soft
//@ assembly-output: emit-asm
//@ [hard] compile-flags: --target thumbv8m.main-none-eabihf --crate-type lib -Copt-level=1
Expand All @@ -7,10 +8,9 @@
#![crate_type = "lib"]
#![feature(abi_c_cmse_nonsecure_call, cmse_nonsecure_entry, no_core, lang_items)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}

extern crate minicore;
use minicore::*;

// CHECK-LABEL: __acle_se_entry_point:
// CHECK-NEXT: entry_point:
Expand Down
7 changes: 3 additions & 4 deletions tests/assembly/dwarf4.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Makes sure that `-Z dwarf-version=4` causes `rustc` to emit DWARF version 4.
//@ assembly-output: emit-asm
//@ add-core-stubs
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=4 -Copt-level=0
//@ needs-llvm-components: x86

#![feature(no_core, lang_items)]
#![crate_type = "rlib"]
#![no_core]

#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
extern crate minicore;
use minicore::*;

pub fn wibble() {}

Expand Down
7 changes: 3 additions & 4 deletions tests/assembly/dwarf5.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Makes sure that `-Z dwarf-version=5` causes `rustc` to emit DWARF version 5.
//@ add-core-stubs
//@ assembly-output: emit-asm
//@ compile-flags: -g --target x86_64-unknown-linux-gnu -Z dwarf-version=5 -Copt-level=0
//@ needs-llvm-components: x86
Expand All @@ -7,10 +8,8 @@
#![crate_type = "rlib"]
#![no_core]

#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
extern crate minicore;
use minicore::*;

pub fn wibble() {}

Expand Down
7 changes: 3 additions & 4 deletions tests/assembly/pic-relocation-model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ add-core-stubs
//@ revisions: x64
//@ assembly-output: emit-asm
//@ [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pic
Expand All @@ -7,10 +8,8 @@
#![no_core]
#![crate_type = "rlib"]

#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
extern crate minicore;
use minicore::*;

// CHECK-LABEL: call_other_fn:
// CHECK: {{(jmpq|callq)}} *other_fn@GOTPCREL(%rip)
Expand Down
7 changes: 3 additions & 4 deletions tests/assembly/pie-relocation-model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ add-core-stubs
//@ revisions: x64
//@ assembly-output: emit-asm
//@ [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pie
Expand All @@ -7,10 +8,8 @@
#![no_core]
#![crate_type = "rlib"]

#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
extern crate minicore;
use minicore::*;

// CHECK-LABEL: call_other_fn:
// With PIE local functions are called "directly".
Expand Down
Loading
Loading