diff options
| author | The Miri Conjob Bot <miri@cron.bot> | 2023-08-04 05:35:56 +0000 |
|---|---|---|
| committer | The Miri Conjob Bot <miri@cron.bot> | 2023-08-04 05:35:56 +0000 |
| commit | 1a803a0c790ade534dec44c17816eb389d7dd8ed (patch) | |
| tree | 150c1c2779d9b093507486e92ac3ea013bc6409b /src | |
| parent | 325dc9288e1d15a9d25ec040ef8a568f46de505b (diff) | |
| parent | 098c1db7e55e7229a520a2ec8e460e1e300e109b (diff) | |
Merge from rustc
Diffstat (limited to 'src')
21 files changed, 121 insertions, 48 deletions
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 2c51ed5408e..bdefc41c9c7 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -307,6 +307,12 @@ impl Step for CodegenBackend { } fn run(self, builder: &Builder<'_>) { + // FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved + if builder.build.config.vendor && &self.backend == "gcc" { + println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled."); + return; + } + let compiler = builder.compiler(builder.top_stage, builder.config.build); let target = self.target; let backend = self.backend; diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 983442270d2..2c63ec80c3e 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -23,7 +23,7 @@ use crate::builder::crate_description; use crate::builder::Cargo; use crate::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath}; use crate::cache::{Interned, INTERNER}; -use crate::config::{LlvmLibunwind, RustcLto, TargetSelection}; +use crate::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection}; use crate::dist; use crate::llvm; use crate::tool::SourceType; @@ -888,16 +888,37 @@ impl Step for Rustc { compiler.host, target, ); + let stamp = librustc_stamp(builder, compiler, target); run_cargo( builder, cargo, vec![], - &librustc_stamp(builder, compiler, target), + &stamp, vec![], false, true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files. ); + // When building `librustc_driver.so` (like `libLLVM.so`) on linux, it can contain + // unexpected debuginfo from dependencies, for example from the C++ standard library used in + // our LLVM wrapper. Unless we're explicitly requesting `librustc_driver` to be built with + // debuginfo (via the debuginfo level of the executables using it): strip this debuginfo + // away after the fact. + // FIXME: to make things simpler for now, limit this to the host and target where we know + // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not + // cross-compiling. Expand this to other appropriate targets in the future. + if builder.config.rust_debuginfo_level_rustc == DebuginfoLevel::None + && builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None + && target == "x86_64-unknown-linux-gnu" + && target == builder.config.build + { + let target_root_dir = stamp.parent().unwrap(); + let rustc_driver = target_root_dir.join("librustc_driver.so"); + if rustc_driver.exists() { + output(Command::new("strip").arg("--strip-debug").arg(rustc_driver)); + } + } + builder.ensure(RustcLink::from_rustc( self, builder.compiler(compiler.stage, builder.config.build), diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 45bea9608fc..bec0b11acd0 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -50,7 +50,7 @@ pub enum DryRun { UserSelected, } -#[derive(Copy, Clone, Default)] +#[derive(Copy, Clone, Default, PartialEq, Eq)] pub enum DebuginfoLevel { #[default] None, diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index 81b88d5de98..0613b999793 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -485,25 +485,56 @@ impl Step for Llvm { cfg.build(); - // When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned - // libLLVM.dylib will be built. However, llvm-config will still look - // for a versioned path like libLLVM-14.dylib. Manually create a symbolic - // link to make llvm-config happy. - if builder.llvm_link_shared() && target.contains("apple-darwin") { + // Helper to find the name of LLVM's shared library on darwin and linux. + let find_llvm_lib_name = |extension| { let mut cmd = Command::new(&res.llvm_config); let version = output(cmd.arg("--version")); let major = version.split('.').next().unwrap(); - let lib_name = match llvm_version_suffix { - Some(s) => format!("libLLVM-{major}{s}.dylib"), - None => format!("libLLVM-{major}.dylib"), + let lib_name = match &llvm_version_suffix { + Some(version_suffix) => format!("libLLVM-{major}{version_suffix}.{extension}"), + None => format!("libLLVM-{major}.{extension}"), }; + lib_name + }; + // When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned + // libLLVM.dylib will be built. However, llvm-config will still look + // for a versioned path like libLLVM-14.dylib. Manually create a symbolic + // link to make llvm-config happy. + if builder.llvm_link_shared() && target.contains("apple-darwin") { + let lib_name = find_llvm_lib_name("dylib"); let lib_llvm = out_dir.join("build").join("lib").join(lib_name); if !lib_llvm.exists() { t!(builder.symlink_file("libLLVM.dylib", &lib_llvm)); } } + // When building LLVM as a shared library on linux, it can contain unexpected debuginfo: + // some can come from the C++ standard library. Unless we're explicitly requesting LLVM to + // be built with debuginfo, strip it away after the fact, to make dist artifacts smaller. + // FIXME: to make things simpler for now, limit this to the host and target where we know + // `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not + // cross-compiling. Expand this to other appropriate targets in the future. + if builder.llvm_link_shared() + && builder.config.llvm_optimize + && !builder.config.llvm_release_debuginfo + && target == "x86_64-unknown-linux-gnu" + && target == builder.config.build + { + // Find the name of the LLVM shared library that we just built. + let lib_name = find_llvm_lib_name("so"); + + // If the shared library exists in LLVM's `/build/lib/` or `/lib/` folders, strip its + // debuginfo. Note: `output` will propagate any errors here. + let strip_if_possible = |path: PathBuf| { + if path.exists() { + output(Command::new("strip").arg("--strip-debug").arg(path)); + } + }; + strip_if_possible(out_dir.join("lib").join(&lib_name)); + strip_if_possible(out_dir.join("build").join("lib").join(&lib_name)); + } + t!(stamp.write()); res diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 013b93e0129..f69156b7c05 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -200,6 +200,7 @@ To do so, the `#[doc(keyword = "...")]` attribute is used. Example: ```rust #![feature(rustdoc_internals)] +#![allow(internal_features)] /// Some documentation about the keyword. #[doc(keyword = "keyword")] diff --git a/src/doc/unstable-book/src/language-features/intrinsics.md b/src/doc/unstable-book/src/language-features/intrinsics.md index ea9bace6dd4..8fa8f567d7e 100644 --- a/src/doc/unstable-book/src/language-features/intrinsics.md +++ b/src/doc/unstable-book/src/language-features/intrinsics.md @@ -17,6 +17,7 @@ via a declaration like ```rust #![feature(intrinsics)] +#![allow(internal_features)] # fn main() {} extern "rust-intrinsic" { diff --git a/src/doc/unstable-book/src/language-features/lang-items.md b/src/doc/unstable-book/src/language-features/lang-items.md index f4bc18bc7da..1f3d472c3aa 100644 --- a/src/doc/unstable-book/src/language-features/lang-items.md +++ b/src/doc/unstable-book/src/language-features/lang-items.md @@ -17,6 +17,7 @@ sugar for dynamic allocations via `malloc` and `free`: ```rust,ignore (libc-is-finicky) #![feature(lang_items, start, libc, core_intrinsics, rustc_private, rustc_attrs)] +#![allow(internal_features)] #![no_std] use core::intrinsics; use core::panic::PanicInfo; @@ -119,6 +120,7 @@ in the same format as C: ```rust,ignore (libc-is-finicky) #![feature(lang_items, core_intrinsics, rustc_private)] #![feature(start)] +#![allow(internal_features)] #![no_std] use core::intrinsics; use core::panic::PanicInfo; @@ -155,6 +157,7 @@ compiler's name mangling too: ```rust,ignore (libc-is-finicky) #![feature(lang_items, core_intrinsics, rustc_private)] #![feature(start)] +#![allow(internal_features)] #![no_std] #![no_main] use core::intrinsics; diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs index ef38ca3c16c..66d10f2368b 100644 --- a/src/librustdoc/clean/render_macro_matchers.rs +++ b/src/librustdoc/clean/render_macro_matchers.rs @@ -76,17 +76,13 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String }; // Reparse a single token tree. - let mut reparsed_trees = match parser.parse_all_token_trees() { - Ok(reparsed_trees) => reparsed_trees, - Err(diagnostic) => { - diagnostic.cancel(); - return None; - } - }; - if reparsed_trees.len() != 1 { + if parser.token == token::Eof { + return None; + } + let reparsed_tree = parser.parse_token_tree(); + if parser.token != token::Eof { return None; } - let reparsed_tree = reparsed_trees.pop().unwrap(); // Compare against the original tree. if reparsed_tree.eq_unspanned(matcher) { Some(snippet) } else { None } diff --git a/src/tools/cargo b/src/tools/cargo -Subproject 020651c52257052d28f6fd83fbecf5cfa1ed516 +Subproject d78bbf4bde3c6b95caca7512f537c6f9721426f diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs index 49bdc679604..fc1fabcc0ae 100644 --- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs +++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs @@ -43,7 +43,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), ("clippy::forget_copy", "forgetting_copy_types"), ("clippy::forget_ref", "forgetting_references"), - ("clippy::fn_null_check", "incorrect_fn_null_checks"), + ("clippy::fn_null_check", "useless_ptr_null_checks"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs index 385e25ce6b8..e46f8bf6fab 100644 --- a/src/tools/clippy/tests/compile-test.rs +++ b/src/tools/clippy/tests/compile-test.rs @@ -140,6 +140,7 @@ fn base_config(test_dir: &str) -> compiletest::Config { [ "--emit=metadata", "-Aunused", + "-Ainternal_features", "-Zui-testing", "-Dwarnings", &format!("-Ldependency={}", deps_path.display()), diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index 8ec19b120d1..8257bf2947a 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -38,7 +38,7 @@ #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] -#![allow(incorrect_fn_null_checks)] +#![allow(useless_ptr_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -92,7 +92,7 @@ #![warn(for_loops_over_fallibles)] #![warn(forgetting_copy_types)] #![warn(forgetting_references)] -#![warn(incorrect_fn_null_checks)] +#![warn(useless_ptr_null_checks)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 51a5976eb61..6569dad18d4 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -38,7 +38,7 @@ #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] -#![allow(incorrect_fn_null_checks)] +#![allow(useless_ptr_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index e420ea1d2ad..57e991e5695 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -246,11 +246,11 @@ error: lint `clippy::forget_ref` has been renamed to `forgetting_references` LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` -error: lint `clippy::fn_null_check` has been renamed to `incorrect_fn_null_checks` +error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::fn_null_check)] - | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `incorrect_fn_null_checks` + | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` --> $DIR/rename.rs:96:9 diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 45582ddcbaf..07a54cb26d3 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -868,6 +868,8 @@ impl<'test> TestCx<'test> { .args(&["--target", &self.config.target]) .arg("-L") .arg(&aux_dir) + .arg("-A") + .arg("internal_features") .args(&self.props.compile_flags) .envs(self.props.rustc_env.clone()); self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags); @@ -936,7 +938,9 @@ impl<'test> TestCx<'test> { .arg("-L") .arg(&self.config.build_base) .arg("-L") - .arg(aux_dir); + .arg(aux_dir) + .arg("-A") + .arg("internal_features"); self.set_revision_flags(&mut rustc); self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags); rustc.args(&self.props.compile_flags); @@ -1867,6 +1871,8 @@ impl<'test> TestCx<'test> { .arg("--deny") .arg("warnings") .arg(&self.testpaths.file) + .arg("-A") + .arg("internal_features") .args(&self.props.compile_flags); if self.config.mode == RustdocJson { @@ -1933,7 +1939,8 @@ impl<'test> TestCx<'test> { let mut test_client = Command::new(self.config.remote_test_client.as_ref().unwrap()); test_client - .args(&["run", &support_libs.len().to_string(), &prog]) + .args(&["run", &support_libs.len().to_string()]) + .arg(&prog) .args(support_libs) .args(args); @@ -2459,6 +2466,9 @@ impl<'test> TestCx<'test> { rustc.args(&["-A", "unused"]); } + // Allow tests to use internal features. + rustc.args(&["-A", "internal_features"]); + if self.props.force_host { self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags); if !is_rustdoc { @@ -2516,7 +2526,7 @@ impl<'test> TestCx<'test> { // If this is emscripten, then run tests under nodejs if self.config.target.contains("emscripten") { if let Some(ref p) = self.config.nodejs { - args.push(p.clone()); + args.push(p.into()); } else { self.fatal("emscripten target requested and no NodeJS binary found (--nodejs)"); } @@ -2524,7 +2534,7 @@ impl<'test> TestCx<'test> { // shim } else if self.config.target.contains("wasm32") { if let Some(ref p) = self.config.nodejs { - args.push(p.clone()); + args.push(p.into()); } else { self.fatal("wasm32 target requested and no NodeJS binary found (--nodejs)"); } @@ -2536,13 +2546,12 @@ impl<'test> TestCx<'test> { .unwrap() // chop off `ui` .parent() .unwrap(); // chop off `tests` - args.push(src.join("src/etc/wasm32-shim.js").display().to_string()); + args.push(src.join("src/etc/wasm32-shim.js").into_os_string()); } let exe_file = self.make_exe_name(); - // FIXME (#9639): This needs to handle non-utf8 paths - args.push(exe_file.to_str().unwrap().to_owned()); + args.push(exe_file.into_os_string()); // Add the arguments in the run_flags directive args.extend(self.split_maybe_args(&self.props.run_flags)); @@ -2551,12 +2560,16 @@ impl<'test> TestCx<'test> { ProcArgs { prog, args } } - fn split_maybe_args(&self, argstr: &Option<String>) -> Vec<String> { + fn split_maybe_args(&self, argstr: &Option<String>) -> Vec<OsString> { match *argstr { Some(ref s) => s .split(' ') .filter_map(|s| { - if s.chars().all(|c| c.is_whitespace()) { None } else { Some(s.to_owned()) } + if s.chars().all(|c| c.is_whitespace()) { + None + } else { + Some(OsString::from(s)) + } }) .collect(), None => Vec::new(), @@ -4363,8 +4376,8 @@ impl<'test> TestCx<'test> { } struct ProcArgs { - prog: String, - args: Vec<String>, + prog: OsString, + args: Vec<OsString>, } pub struct ProcRes { diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index 8d9901807ec..6bd4be91e51 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -273,6 +273,8 @@ pub fn report_error<'tcx, 'mir>( } else { #[rustfmt::skip] let title = match e.kind() { + UndefinedBehavior(UndefinedBehaviorInfo::ValidationError(e)) if matches!(e.kind, ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer) => + bug!("This validation error should be impossible in Miri: {:?}", e.kind), UndefinedBehavior(_) => "Undefined Behavior", ResourceExhaustion(_) => @@ -377,7 +379,7 @@ pub fn report_error<'tcx, 'mir>( if let Some((alloc_id, access)) = extra { eprintln!( "Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:", - range = access.uninit, + range = access.bad, ); eprintln!("{:?}", ecx.dump_alloc(alloc_id)); } diff --git a/src/tools/miri/tests/compiletest.rs b/src/tools/miri/tests/compiletest.rs index 4006fe139db..8b97c8bb83c 100644 --- a/src/tools/miri/tests/compiletest.rs +++ b/src/tools/miri/tests/compiletest.rs @@ -53,6 +53,7 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> // Add some flags we always want. program.args.push("-Dwarnings".into()); program.args.push("-Dunused".into()); + program.args.push("-Ainternal_features".into()); if let Ok(extra_flags) = env::var("MIRIFLAGS") { for flag in extra_flags.split_whitespace() { program.args.push(flag.into()); diff --git a/src/tools/miri/tests/fail/validity/uninit_float.stderr b/src/tools/miri/tests/fail/validity/uninit_float.stderr index 677a0fc5570..e95e3b18128 100644 --- a/src/tools/miri/tests/fail/validity/uninit_float.stderr +++ b/src/tools/miri/tests/fail/validity/uninit_float.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes +error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized memory, but expected a floating point number --> $DIR/uninit_float.rs:LL:CC | LL | let _val: [f32; 1] = unsafe { std::mem::uninitialized() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized bytes + | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized memory, but expected a floating point number | = 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 diff --git a/src/tools/miri/tests/fail/validity/uninit_integer.stderr b/src/tools/miri/tests/fail/validity/uninit_integer.stderr index a9ac2a6dc67..2156886cd71 100644 --- a/src/tools/miri/tests/fail/validity/uninit_integer.stderr +++ b/src/tools/miri/tests/fail/validity/uninit_integer.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes +error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized memory, but expected an integer --> $DIR/uninit_integer.rs:LL:CC | LL | let _val = unsafe { std::mem::MaybeUninit::<[usize; 1]>::uninit().assume_init() }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized bytes + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized memory, but expected an integer | = 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 diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs index 5b1b4fbd491..739afb4e0ac 100644 --- a/src/tools/rustfmt/src/expr.rs +++ b/src/tools/rustfmt/src/expr.rs @@ -1382,12 +1382,8 @@ pub(crate) fn can_be_overflowed_expr( || (context.use_block_indent() && args_len == 1) } ast::ExprKind::MacCall(ref mac) => { - match ( - rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()), - context.config.overflow_delimited_expr(), - ) { - (Some(ast::MacDelimiter::Bracket), true) - | (Some(ast::MacDelimiter::Brace), true) => true, + match (mac.args.delim, context.config.overflow_delimited_expr()) { + (Delimiter::Bracket, true) | (Delimiter::Brace, true) => true, _ => context.use_block_indent() && args_len == 1, } } diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 7ad8f5c5c05..d900c04c124 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -338,6 +338,7 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) { Some("active") => Status::Unstable, Some("incomplete") => Status::Unstable, + Some("internal") => Status::Unstable, Some("removed") => Status::Removed, Some("accepted") => Status::Stable, _ => continue, |
