diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index 6d68eca60afc1..5f1a5fbee4bf2 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -101,10 +101,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t let is_hidden = if is_generic { // This is a monomorphization of a generic function. - if !(cx.tcx.sess.opts.share_generics() - || tcx.codegen_fn_attrs(instance_def_id).inline - == rustc_attr_data_structures::InlineAttr::Never) - { + if !cx.tcx.sess.opts.share_generics() { // When not sharing generics, all instances are in the same // crate and have hidden visibility. true diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 92b9b6e132e74..ac490168f2df6 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -308,7 +308,7 @@ fn exported_symbols_provider_local<'tcx>( )); } - if tcx.local_crate_exports_generics() { + if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() { use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility}; use rustc_middle::ty::InstanceKind; @@ -368,17 +368,6 @@ fn exported_symbols_provider_local<'tcx>( continue; } - if !tcx.sess.opts.share_generics() { - if tcx.codegen_fn_attrs(mono_item.def_id()).inline - == rustc_attr_data_structures::InlineAttr::Never - { - // this is OK, we explicitly allow sharing inline(never) across crates even - // without share-generics. - } else { - continue; - } - } - match *mono_item { MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => { let has_generics = args.non_erasable_generics().next().is_some(); diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 47ba850d50dd4..9bb218c0e375f 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -3,7 +3,6 @@ use std::fmt; use std::hash::Hash; use rustc_ast::expand::autodiff_attrs::AutoDiffItem; -use rustc_attr_data_structures::InlineAttr; use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxIndexMap; @@ -211,20 +210,6 @@ impl<'tcx> MonoItem<'tcx> { return InstantiationMode::LocalCopy; } - // #[inline(never)] functions in general are poor candidates for inlining and thus since - // LocalCopy generally increases code size for the benefit of optimizations from inlining, - // we want to give them GloballyShared codegen. - // The slight problem is that generic functions need to always support cross-crate - // compilation, so all previous stages of the compiler are obligated to treat generic - // functions the same as those that unconditionally get LocalCopy codegen. It's only when - // we get here that we can at least not codegen a #[inline(never)] generic function in all - // of our CGUs. - if let InlineAttr::Never = tcx.codegen_fn_attrs(instance.def_id()).inline - && self.is_generic_fn() - { - return InstantiationMode::GloballyShared { may_conflict: true }; - } - // The fallthrough case is to generate LocalCopy for all optimized builds, and // GloballyShared with conflict prevention when optimizations are disabled. match tcx.sess.opts.optimize { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index cb132ae5573d7..731921db231a4 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2151,6 +2151,8 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn local_crate_exports_generics(self) -> bool { + debug_assert!(self.sess.opts.share_generics()); + self.crate_types().iter().any(|crate_type| { match crate_type { CrateType::Executable diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 5ba4e5446e9d4..6fa1a94ac48d2 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -209,11 +209,7 @@ impl<'tcx> Instance<'tcx> { // If we are not in share generics mode, we don't link to upstream // monomorphizations but always instantiate our own internal versions // instead. - if !tcx.sess.opts.share_generics() - // However, if the def_id is marked inline(never), then it's fine to just reuse the - // upstream monomorphization. - && tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_data_structures::InlineAttr::Never - { + if !tcx.sess.opts.share_generics() { return None; } diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 49025673bbd2f..650cfb69ef44f 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -100,7 +100,6 @@ use std::fs::{self, File}; use std::io::Write; use std::path::{Path, PathBuf}; -use rustc_attr_data_structures::InlineAttr; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sync; use rustc_data_structures::unord::{UnordMap, UnordSet}; @@ -210,8 +209,8 @@ where // available to downstream crates. This depends on whether we are in // share-generics mode and whether the current crate can even have // downstream crates. - let can_export_generics = cx.tcx.local_crate_exports_generics(); - let always_export_generics = can_export_generics && cx.tcx.sess.opts.share_generics(); + let export_generics = + cx.tcx.sess.opts.share_generics() && cx.tcx.local_crate_exports_generics(); let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx); let cgu_name_cache = &mut UnordMap::default(); @@ -251,8 +250,7 @@ where cx.tcx, &mono_item, &mut can_be_internalized, - can_export_generics, - always_export_generics, + export_generics, ); // We can't differentiate a function that got inlined. @@ -747,19 +745,12 @@ fn mono_item_linkage_and_visibility<'tcx>( tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>, can_be_internalized: &mut bool, - can_export_generics: bool, - always_export_generics: bool, + export_generics: bool, ) -> (Linkage, Visibility) { if let Some(explicit_linkage) = mono_item.explicit_linkage(tcx) { return (explicit_linkage, Visibility::Default); } - let vis = mono_item_visibility( - tcx, - mono_item, - can_be_internalized, - can_export_generics, - always_export_generics, - ); + let vis = mono_item_visibility(tcx, mono_item, can_be_internalized, export_generics); (Linkage::External, vis) } @@ -782,8 +773,7 @@ fn mono_item_visibility<'tcx>( tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>, can_be_internalized: &mut bool, - can_export_generics: bool, - always_export_generics: bool, + export_generics: bool, ) -> Visibility { let instance = match mono_item { // This is pretty complicated; see below. @@ -843,11 +833,7 @@ fn mono_item_visibility<'tcx>( // Upstream `DefId` instances get different handling than local ones. let Some(def_id) = def_id.as_local() else { - return if is_generic - && (always_export_generics - || (can_export_generics - && tcx.codegen_fn_attrs(def_id).inline == InlineAttr::Never)) - { + return if export_generics && is_generic { // If it is an upstream monomorphization and we export generics, we must make // it available to downstream crates. *can_be_internalized = false; @@ -858,9 +844,7 @@ fn mono_item_visibility<'tcx>( }; if is_generic { - if always_export_generics - || (can_export_generics && tcx.codegen_fn_attrs(def_id).inline == InlineAttr::Never) - { + if export_generics { if tcx.is_unreachable_local_definition(def_id) { // This instance cannot be used from another crate. Visibility::Hidden diff --git a/library/alloc/src/raw_vec/mod.rs b/library/alloc/src/raw_vec/mod.rs index 3e006a2d1bdf1..ba5d965d2ee9a 100644 --- a/library/alloc/src/raw_vec/mod.rs +++ b/library/alloc/src/raw_vec/mod.rs @@ -760,9 +760,7 @@ impl RawVecInner { } } -// not marked inline(never) since we want optimizers to be able to observe the specifics of this -// function, see tests/codegen/vec-reserve-extend.rs. -#[cold] +#[inline(never)] fn finish_grow( new_layout: Layout, current_memory: Option<(NonNull, Layout)>, diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 2bb7a63772d68..0a70ebccec881 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -368,7 +368,6 @@ #![feature(sync_unsafe_cell)] #![feature(temporary_niche_types)] #![feature(ub_checks)] -#![feature(used_with_arg)] // tidy-alphabetical-end // // Library features (alloc): diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 7873049d20bfd..46aff27585746 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -27,22 +27,6 @@ use crate::sys::backtrace; use crate::sys::stdio::panic_output; use crate::{fmt, intrinsics, process, thread}; -// This forces codegen of the function called by panic!() inside the std crate, rather than in -// downstream crates. Primarily this is useful for rustc's codegen tests, which rely on noticing -// complete removal of panic from generated IR. Since begin_panic is inline(never), it's only -// codegen'd once per crate-graph so this pushes that to std rather than our codegen test crates. -// -// (See https://github.com/rust-lang/rust/pull/123244 for more info on why). -// -// If this is causing problems we can also modify those codegen tests to use a crate type like -// cdylib which doesn't export "Rust" symbols to downstream linkage units. -#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] -#[doc(hidden)] -#[allow(dead_code)] -#[used(compiler)] -pub static EMPTY_PANIC: fn(&'static str) -> ! = - begin_panic::<&'static str> as fn(&'static str) -> !; - // Binary interface to the panic runtime that the standard library depends on. // // The standard library is tagged with `#![needs_panic_runtime]` (introduced in diff --git a/src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile b/src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile index d5027589e0bd6..82468dad8641c 100644 --- a/src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile +++ b/src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile @@ -27,5 +27,4 @@ ENV RUST_CONFIGURE_ARGS \ --enable-profiler \ --enable-compiler-docs # FIXME: Skipping cargo panic_abort_doc_tests due to https://github.com/rust-lang/rust/issues/123733 -ENV SCRIPT python3 ../x.py --stage 2 test && \ - python3 ../x.py --stage 2 test src/tools/cargo --test-args \"--skip panic_abort_doc_tests\" +ENV SCRIPT python3 ../x.py --stage 2 test tests/ui/panics diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 43c77d1ddf7f5..df37d5b241e9a 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -122,35 +122,8 @@ jobs: # These jobs automatically inherit envs.pr, to avoid repeating # it in each job definition. pr: - - name: mingw-check-1 - <<: *job-linux-4c - - name: mingw-check-2 - <<: *job-linux-4c - - name: mingw-check-tidy - continue_on_error: true - free_disk: false - env: - # This submodule is expensive to checkout, and it should not be needed for - # tidy. This speeds up the PR CI job by ~1 minute. - SKIP_SUBMODULES: src/gcc - <<: *job-linux-4c - - name: x86_64-gnu-llvm-19 - env: - ENABLE_GCC_CODEGEN: "1" - DOCKER_SCRIPT: x86_64-gnu-llvm.sh - <<: *job-linux-4c - - name: aarch64-gnu-llvm-19-1 - env: - IMAGE: aarch64-gnu-llvm-19 - DOCKER_SCRIPT: stage_2_test_set1.sh - <<: *job-aarch64-linux - - name: aarch64-gnu-llvm-19-2 - env: - IMAGE: aarch64-gnu-llvm-19 - DOCKER_SCRIPT: stage_2_test_set2.sh + - name: aarch64-gnu <<: *job-aarch64-linux - - name: x86_64-gnu-tools - <<: *job-linux-36c-codebuild # Jobs that run when you perform a try build (@bors try) # These jobs automatically inherit envs.try, to avoid repeating diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 3e9d79224fdde..099ae186ac98f 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -3132,7 +3132,6 @@ ui/packed/issue-118537-field-offset.rs ui/packed/issue-27060-2.rs ui/packed/issue-27060.rs ui/packed/issue-46152.rs -ui/panics/issue-47429-short-backtraces.rs ui/parser/issue-116781.rs ui/parser/issue-12187-1.rs ui/parser/issue-12187-2.rs diff --git a/tests/codegen-units/item-collection/cross-crate-generic-functions.rs b/tests/codegen-units/item-collection/cross-crate-generic-functions.rs deleted file mode 100644 index aa27ce3bdb542..0000000000000 --- a/tests/codegen-units/item-collection/cross-crate-generic-functions.rs +++ /dev/null @@ -1,24 +0,0 @@ -//@ compile-flags:-Clink-dead-code - -#![deny(dead_code)] -#![crate_type = "lib"] - -//@ aux-build:cgu_generic_function.rs -extern crate cgu_generic_function; - -//~ MONO_ITEM fn start -#[no_mangle] -pub fn start(_: isize, _: *const *const u8) -> isize { - //~ MONO_ITEM fn cgu_generic_function::bar:: - //~ MONO_ITEM fn cgu_generic_function::foo:: - let _ = cgu_generic_function::foo(1u32); - - //~ MONO_ITEM fn cgu_generic_function::bar:: - //~ MONO_ITEM fn cgu_generic_function::foo:: - let _ = cgu_generic_function::foo(2u64); - - // This should not introduce a codegen item - let _ = cgu_generic_function::exported_but_not_generic(3); - - 0 -} diff --git a/tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs b/tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs deleted file mode 100644 index 8bb78eb788a22..0000000000000 --- a/tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![crate_type = "lib"] - -struct Struct(u32); - -#[inline(never)] -pub fn foo(x: T) -> (T, u32, i8) { - let (x, Struct(y)) = bar(x); - (x, y, 2) -} - -#[inline(never)] -fn bar(x: T) -> (T, Struct) { - let _ = not_exported_and_not_generic(0); - exported_and_generic::(0); - (x, Struct(1)) -} - -pub static F: fn(u32) -> u32 = exported_and_generic::; - -// These should not contribute to the codegen items of other crates. - -// This is generic, but it's only instantiated with a u32 argument and that instantiation is present -// in the local crate (see F above). -#[inline(never)] -pub fn exported_and_generic(x: T) -> T { - x -} - -#[inline(never)] -pub fn exported_but_not_generic(x: i32) -> i64 { - x as i64 -} - -#[inline(never)] -fn not_exported_and_not_generic(x: u32) -> u64 { - x as u64 -} diff --git a/tests/codegen-units/partitioning/extern-generic.rs b/tests/codegen-units/partitioning/extern-generic.rs deleted file mode 100644 index 5c34a768954fd..0000000000000 --- a/tests/codegen-units/partitioning/extern-generic.rs +++ /dev/null @@ -1,36 +0,0 @@ -//@ incremental -//@ compile-flags: -Copt-level=0 - -#![crate_type = "lib"] - -//@ aux-build:cgu_generic_function.rs -extern crate cgu_generic_function; - -// This test checks that, in an unoptimized build, a generic function and its callees are only -// instantiated once in this crate. - -//~ MONO_ITEM fn user @@ extern_generic[External] -pub fn user() { - let _ = cgu_generic_function::foo("abc"); -} - -pub mod mod1 { - use cgu_generic_function; - - //~ MONO_ITEM fn mod1::user @@ extern_generic-mod1[External] - pub fn user() { - let _ = cgu_generic_function::foo("abc"); - } - - pub mod mod1 { - use cgu_generic_function; - - //~ MONO_ITEM fn mod1::mod1::user @@ extern_generic-mod1-mod1[External] - pub fn user() { - let _ = cgu_generic_function::foo("abc"); - } - } -} - -//~ MONO_ITEM fn cgu_generic_function::foo::<&str> @@ cgu_generic_function-in-extern_generic.volatile[External] -//~ MONO_ITEM fn cgu_generic_function::bar::<&str> @@ cgu_generic_function-in-extern_generic.volatile[External] diff --git a/tests/codegen/avr/avr-func-addrspace.rs b/tests/codegen/avr/avr-func-addrspace.rs deleted file mode 100644 index e0192f8b45ab8..0000000000000 --- a/tests/codegen/avr/avr-func-addrspace.rs +++ /dev/null @@ -1,106 +0,0 @@ -//@ add-core-stubs -//@ compile-flags: -Copt-level=3 --target=avr-none -C target-cpu=atmega328p --crate-type=rlib -C panic=abort -//@ needs-llvm-components: avr - -// This test validates that function pointers can be stored in global variables -// and called upon. It ensures that Rust emits function pointers in the correct -// address space to LLVM so that an assertion error relating to casting is -// not triggered. -// -// It also validates that functions can be called through function pointers -// through traits. - -#![feature(no_core, lang_items, intrinsics, unboxed_closures, arbitrary_self_types)] -#![crate_type = "lib"] -#![no_core] - -extern crate minicore; -use minicore::*; - -#[rustc_intrinsic] -pub unsafe fn transmute(src: Src) -> Dst; - -pub static mut STORAGE_FOO: fn(&usize, &mut u32) -> Result<(), ()> = arbitrary_black_box; -pub static mut STORAGE_BAR: u32 = 12; - -fn arbitrary_black_box(ptr: &usize, _: &mut u32) -> Result<(), ()> { - let raw_ptr = ptr as *const usize; - let _v: usize = unsafe { *raw_ptr }; - loop {} -} - -#[inline(never)] -#[no_mangle] -fn call_through_fn_trait(a: &mut impl Fn<(), Output = ()>) { - (*a)() -} - -#[inline(never)] -fn update_bar_value() { - unsafe { - STORAGE_BAR = 88; - } -} - -// CHECK: define dso_local void @test(){{.+}}addrspace(1) -#[no_mangle] -pub extern "C" fn test() { - let mut buf = 7; - - // A call through the Fn trait must use address space 1. - // - // CHECK: call{{.+}}addrspace(1) void @call_through_fn_trait({{.*}}) - call_through_fn_trait(&mut update_bar_value); - - // A call through a global variable must use address space 1. - // CHECK: load {{.*}}addrspace(1){{.+}}FOO - unsafe { - STORAGE_FOO(&1, &mut buf); - } -} - -// Validate that we can codegen transmutes between data ptrs and fn ptrs. - -// CHECK: define{{.+}}ptr addrspace(1) @transmute_data_ptr_to_fn(ptr{{.*}} %x) -#[no_mangle] -pub unsafe fn transmute_data_ptr_to_fn(x: *const ()) -> fn() { - // It doesn't matter precisely how this is codegenned (through memory or an addrspacecast), - // as long as it doesn't cause a verifier error by using `bitcast`. - transmute(x) -} - -// CHECK: define{{.+}}ptr @transmute_fn_ptr_to_data(ptr addrspace(1){{.*}} %x) -#[no_mangle] -pub unsafe fn transmute_fn_ptr_to_data(x: fn()) -> *const () { - // It doesn't matter precisely how this is codegenned (through memory or an addrspacecast), - // as long as it doesn't cause a verifier error by using `bitcast`. - transmute(x) -} - -pub enum Either { - A(T), - B(U), -} - -// Previously, we would codegen this as passing/returning a scalar pair of `{ i8, ptr }`, -// with the `ptr` field representing both `&i32` and `fn()` depending on the variant. -// This is incorrect, because `fn()` should be `ptr addrspace(1)`, not `ptr`. - -// CHECK: define{{.+}}void @should_not_combine_addrspace(ptr{{.+}}sret{{.+}}%_0, ptr{{.+}}%x) -#[no_mangle] -#[inline(never)] -pub fn should_not_combine_addrspace(x: Either<&i32, fn()>) -> Either<&i32, fn()> { - x -} - -// The incorrectness described above would result in us producing (after optimizations) -// a `ptrtoint`/`inttoptr` roundtrip to convert from `ptr` to `ptr addrspace(1)`. - -// CHECK-LABEL: @call_with_fn_ptr -#[no_mangle] -pub fn call_with_fn_ptr<'a>(f: fn()) -> Either<&'a i32, fn()> { - // CHECK-NOT: ptrtoint - // CHECK-NOT: inttoptr - // CHECK: call addrspace(1) void @should_not_combine_addrspace - should_not_combine_addrspace(Either::B(f)) -} diff --git a/tests/codegen/issues/issue-13018.rs b/tests/codegen/issues/issue-13018.rs deleted file mode 100644 index 8040018b93106..0000000000000 --- a/tests/codegen/issues/issue-13018.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ compile-flags: -Copt-level=3 - -// A drop([...].clone()) sequence on an Rc should be a no-op -// In particular, no call to __rust_dealloc should be emitted -// -// We use a cdylib since it's a leaf unit for Rust purposes, so doesn't codegen -Zshare-generics -// code. -#![crate_type = "cdylib"] -use std::rc::Rc; - -pub fn foo(t: &Rc>) { - // CHECK-NOT: __rust_dealloc - drop(t.clone()); -} diff --git a/tests/run-make/naked-symbol-visibility/a_rust_dylib.rs b/tests/run-make/naked-symbol-visibility/a_rust_dylib.rs deleted file mode 100644 index ce787f83ade6d..0000000000000 --- a/tests/run-make/naked-symbol-visibility/a_rust_dylib.rs +++ /dev/null @@ -1,89 +0,0 @@ -#![feature(linkage)] -#![crate_type = "dylib"] - -use std::arch::naked_asm; - -pub trait TraitWithConst { - const COUNT: u32; -} - -struct Test; - -impl TraitWithConst for Test { - const COUNT: u32 = 1; -} - -#[no_mangle] -fn entry() { - private_vanilla(); - private_naked(); - - public_vanilla_generic::(); - public_naked_generic::(); -} - -extern "C" fn private_vanilla() -> u32 { - 42 -} - -#[unsafe(naked)] -extern "C" fn private_naked() -> u32 { - naked_asm!("mov rax, 42", "ret") -} - -#[no_mangle] -pub extern "C" fn public_vanilla() -> u32 { - 42 -} - -#[unsafe(naked)] -#[no_mangle] -pub extern "C" fn public_naked_nongeneric() -> u32 { - naked_asm!("mov rax, 42", "ret") -} - -pub extern "C" fn public_vanilla_generic() -> u32 { - T::COUNT -} - -#[unsafe(naked)] -pub extern "C" fn public_naked_generic() -> u32 { - naked_asm!("mov rax, {}", "ret", const T::COUNT) -} - -#[linkage = "external"] -extern "C" fn vanilla_external_linkage() -> u32 { - 42 -} - -#[unsafe(naked)] -#[linkage = "external"] -extern "C" fn naked_external_linkage() -> u32 { - naked_asm!("mov rax, 42", "ret") -} - -#[cfg(not(windows))] -#[linkage = "weak"] -extern "C" fn vanilla_weak_linkage() -> u32 { - 42 -} - -#[unsafe(naked)] -#[cfg(not(windows))] -#[linkage = "weak"] -extern "C" fn naked_weak_linkage() -> u32 { - naked_asm!("mov rax, 42", "ret") -} - -// functions that are declared in an `extern "C"` block are currently not exported -// this maybe should change in the future, this is just tracking the current behavior -// reported in https://github.com/rust-lang/rust/issues/128071 -std::arch::global_asm! { - ".globl function_defined_in_global_asm", - "function_defined_in_global_asm:", - "ret", -} - -extern "C" { - pub fn function_defined_in_global_asm(); -} diff --git a/tests/run-make/naked-symbol-visibility/rmake.rs b/tests/run-make/naked-symbol-visibility/rmake.rs deleted file mode 100644 index c69a9ef9eeb01..0000000000000 --- a/tests/run-make/naked-symbol-visibility/rmake.rs +++ /dev/null @@ -1,100 +0,0 @@ -//@ ignore-windows -//@ only-x86_64 -use run_make_support::object::ObjectSymbol; -use run_make_support::object::read::{File, Object, Symbol}; -use run_make_support::targets::is_windows; -use run_make_support::{dynamic_lib_name, rfs, rustc}; - -fn main() { - let rdylib_name = dynamic_lib_name("a_rust_dylib"); - rustc().arg("-Zshare-generics=no").input("a_rust_dylib.rs").run(); - - let binary_data = rfs::read(&rdylib_name); - let rdylib = File::parse(&*binary_data).unwrap(); - - // naked should mirror vanilla - not_exported(&rdylib, "private_vanilla"); - not_exported(&rdylib, "private_naked"); - - global_function(&rdylib, "public_vanilla"); - global_function(&rdylib, "public_naked_nongeneric"); - - not_exported(&rdylib, "public_vanilla_generic"); - // #[naked] functions are implicitly #[inline(never)], so they get shared regardless of - // -Zshare-generics. - global_function(&rdylib, "public_naked_generic"); - - global_function(&rdylib, "vanilla_external_linkage"); - global_function(&rdylib, "naked_external_linkage"); - - // FIXME: make this work on windows (gnu and msvc). See the PR - // https://github.com/rust-lang/rust/pull/128362 for some approaches - // that don't work - // - // #[linkage = "weak"] does not work well on windows, we get - // - // lib.def : error LNK2001: unresolved external symbol naked_weak_linkageā - // lib.def : error LNK2001: unresolved external symbol vanilla_weak_linkage - // - // so just skip weak symbols on windows (for now) - if !is_windows() { - weak_function(&rdylib, "vanilla_weak_linkage"); - weak_function(&rdylib, "naked_weak_linkage"); - } - - // functions that are declared in an `extern "C"` block are currently not exported - // this maybe should change in the future, this is just tracking the current behavior - // reported in https://github.com/rust-lang/rust/issues/128071 - not_exported(&rdylib, "function_defined_in_global_asm"); - - // share generics should expose the generic functions - rustc().arg("-Zshare-generics=yes").input("a_rust_dylib.rs").run(); - let binary_data = rfs::read(&rdylib_name); - let rdylib = File::parse(&*binary_data).unwrap(); - - global_function(&rdylib, "public_vanilla_generic"); - global_function(&rdylib, "public_naked_generic"); -} - -#[track_caller] -fn global_function(file: &File, symbol_name: &str) { - let symbols = find_dynamic_symbol(file, symbol_name); - let [symbol] = symbols.as_slice() else { - panic!("symbol {symbol_name} occurs {} times", symbols.len()) - }; - - assert!(symbol.is_definition(), "`{symbol_name}` is not a function"); - assert!(symbol.is_global(), "`{symbol_name}` is not marked as global"); -} - -#[track_caller] -fn weak_function(file: &File, symbol_name: &str) { - let symbols = find_dynamic_symbol(file, symbol_name); - let [symbol] = symbols.as_slice() else { - panic!("symbol {symbol_name} occurs {} times", symbols.len()) - }; - - assert!(symbol.is_definition(), "`{symbol_name}` is not a function"); - assert!(symbol.is_weak(), "`{symbol_name}` is not marked as weak"); -} - -#[track_caller] -fn not_exported(file: &File, symbol_name: &str) { - assert_eq!(find_dynamic_symbol(file, symbol_name).len(), 0) -} - -fn find_subsequence(haystack: &[u8], needle: &[u8]) -> bool { - haystack.windows(needle.len()).any(|window| window == needle) -} - -fn find_dynamic_symbol<'file, 'data>( - file: &'file File<'data>, - expected: &str, -) -> Vec> { - file.exports() - .unwrap() - .into_iter() - .filter(|e| find_subsequence(e.name(), expected.as_bytes())) - .filter_map(|e| file.symbol_by_name_bytes(e.name())) - .collect() -} diff --git a/tests/ui/panics/issue-47429-short-backtraces.rs b/tests/ui/panics/issue-47429-short-backtraces.rs deleted file mode 100644 index 378ade67bfd08..0000000000000 --- a/tests/ui/panics/issue-47429-short-backtraces.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Regression test for #47429: short backtraces were not terminating correctly - -//@ compile-flags: -O -//@ compile-flags:-Cstrip=none -//@ run-fail -//@ check-run-results -//@ exec-env:RUST_BACKTRACE=1 - -// This is needed to avoid test output differences across std being built with v0 symbols vs legacy -// symbols. -//@ normalize-stderr: "begin_panic::<&str>" -> "begin_panic" -// This variant occurs on macOS with `rust.debuginfo-level = "line-tables-only"` (#133997) -//@ normalize-stderr: " begin_panic<&str>" -> " std::panicking::begin_panic" -// And this is for differences between std with and without debuginfo. -//@ normalize-stderr: "\n +at [^\n]+" -> "" - -//@ ignore-msvc see #62897 and `backtrace-debuginfo.rs` test -//@ ignore-android FIXME #17520 -//@ ignore-openbsd no support for libbacktrace without filename -//@ ignore-fuchsia Backtraces not symbolized -//@ needs-subprocess - -fn main() { - panic!() -} diff --git a/tests/ui/panics/issue-47429-short-backtraces.run.stderr b/tests/ui/panics/issue-47429-short-backtraces.run.stderr deleted file mode 100644 index 32dc6592271de..0000000000000 --- a/tests/ui/panics/issue-47429-short-backtraces.run.stderr +++ /dev/null @@ -1,7 +0,0 @@ - -thread 'main' panicked at $DIR/issue-47429-short-backtraces.rs:24:5: -explicit panic -stack backtrace: - 0: std::panicking::begin_panic - 1: issue_47429_short_backtraces::main -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. diff --git a/tests/ui/panics/panic-main.rs b/tests/ui/panics/panic-main.rs index 3876dbb37c37d..539742369516a 100644 --- a/tests/ui/panics/panic-main.rs +++ b/tests/ui/panics/panic-main.rs @@ -1,4 +1,28 @@ +//@ revisions: default abort-zero abort-one abort-full unwind-zero unwind-one unwind-full + +//@[abort-zero] compile-flags: -Cpanic=abort +//@[abort-zero] no-prefer-dynamic +//@[abort-zero] exec-env: RUST_BACKTRACE=0 + +//@[abort-one] compile-flags: -Cpanic=abort +//@[abort-one] no-prefer-dynamic +//@[abort-one] exec-env: RUST_BACKTRACE=1 + +//@[abort-full] compile-flags: -Cpanic=abort +//@[abort-full] no-prefer-dynamic +//@[abort-full] exec-env: RUST_BACKTRACE=full + +//@[unwind-zero] compile-flags: -Cpanic=unwind +//@[unwind-zero] exec-env: RUST_BACKTRACE=0 + +//@[unwind-one] compile-flags: -Cpanic=unwind +//@[unwind-one] exec-env: RUST_BACKTRACE=1 + +//@[unwind-full] compile-flags: -Cpanic=unwind +//@[unwind-full] exec-env: RUST_BACKTRACE=full + //@ run-fail +//@ failure-status: 101 //@ error-pattern:moop //@ needs-subprocess diff --git a/tests/ui/panics/runtime-switch.rs b/tests/ui/panics/runtime-switch.rs deleted file mode 100644 index 7d5b416934078..0000000000000 --- a/tests/ui/panics/runtime-switch.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Test for std::panic::set_backtrace_style. - -//@ compile-flags: -O -//@ compile-flags:-Cstrip=none -//@ run-fail -//@ check-run-results -//@ exec-env:RUST_BACKTRACE=0 - -// This is needed to avoid test output differences across std being built with v0 symbols vs legacy -// symbols. -//@ normalize-stderr: "begin_panic::<&str>" -> "begin_panic" -// This variant occurs on macOS with `rust.debuginfo-level = "line-tables-only"` (#133997) -//@ normalize-stderr: " begin_panic<&str>" -> " std::panicking::begin_panic" -// And this is for differences between std with and without debuginfo. -//@ normalize-stderr: "\n +at [^\n]+" -> "" - -//@ ignore-msvc see #62897 and `backtrace-debuginfo.rs` test -//@ ignore-android FIXME #17520 -//@ ignore-openbsd no support for libbacktrace without filename -//@ ignore-wasm no backtrace support -//@ ignore-fuchsia Backtrace not symbolized -//@ needs-subprocess - -#![feature(panic_backtrace_config)] - -fn main() { - std::panic::set_backtrace_style(std::panic::BacktraceStyle::Short); - panic!() -} diff --git a/tests/ui/panics/runtime-switch.run.stderr b/tests/ui/panics/runtime-switch.run.stderr deleted file mode 100644 index 70ed127af8643..0000000000000 --- a/tests/ui/panics/runtime-switch.run.stderr +++ /dev/null @@ -1,7 +0,0 @@ - -thread 'main' panicked at $DIR/runtime-switch.rs:28:5: -explicit panic -stack backtrace: - 0: std::panicking::begin_panic - 1: runtime_switch::main -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. diff --git a/tests/ui/panics/short-ice-remove-middle-frames-2.rs b/tests/ui/panics/short-ice-remove-middle-frames-2.rs deleted file mode 100644 index 660530f0eada8..0000000000000 --- a/tests/ui/panics/short-ice-remove-middle-frames-2.rs +++ /dev/null @@ -1,67 +0,0 @@ -//@ compile-flags:-Cstrip=none -//@ run-fail -//@ check-run-results -//@ exec-env:RUST_BACKTRACE=1 -//@ needs-unwind -//@ ignore-android FIXME #17520 -//@ ignore-openbsd no support for libbacktrace without filename -//@ ignore-sgx Backtraces not symbolized -//@ ignore-fuchsia Backtraces not symbolized -//@ ignore-msvc the `__rust_{begin,end}_short_backtrace` symbols aren't reliable. -// This is needed to avoid test output differences across std being built with v0 symbols vs legacy -// symbols. -//@ normalize-stderr: "begin_panic::<&str>" -> "begin_panic" -// This variant occurs on macOS with `rust.debuginfo-level = "line-tables-only"` (#133997) -//@ normalize-stderr: " begin_panic<&str>" -> " std::panicking::begin_panic" -// And this is for differences between std with and without debuginfo. -//@ normalize-stderr: "\n +at [^\n]+" -> "" - -/// This test case make sure that we can have multiple pairs of `__rust_{begin,end}_short_backtrace` - -#[inline(never)] -fn __rust_begin_short_backtrace T>(f: F) -> T { - let result = f(); - std::hint::black_box(result) -} - -#[inline(never)] -fn __rust_end_short_backtrace T>(f: F) -> T { - let result = f(); - std::hint::black_box(result) -} - -fn first() { - __rust_end_short_backtrace(|| second()); -} - -fn second() { - third(); // won't show up -} - -fn third() { - fourth(); // won't show up -} - -fn fourth() { - __rust_begin_short_backtrace(|| fifth()); -} - -fn fifth() { - __rust_end_short_backtrace(|| sixth()); -} - -fn sixth() { - seven(); // won't show up -} - -fn seven() { - __rust_begin_short_backtrace(|| eight()); -} - -fn eight() { - panic!("debug!!!"); -} - -fn main() { - first(); -} diff --git a/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr b/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr deleted file mode 100644 index 664d51e185dd5..0000000000000 --- a/tests/ui/panics/short-ice-remove-middle-frames-2.run.stderr +++ /dev/null @@ -1,15 +0,0 @@ - -thread 'main' panicked at $DIR/short-ice-remove-middle-frames-2.rs:62:5: -debug!!! -stack backtrace: - 0: std::panicking::begin_panic - 1: short_ice_remove_middle_frames_2::eight - 2: short_ice_remove_middle_frames_2::seven::{{closure}} - [... omitted 3 frames ...] - 3: short_ice_remove_middle_frames_2::fifth - 4: short_ice_remove_middle_frames_2::fourth::{{closure}} - [... omitted 4 frames ...] - 5: short_ice_remove_middle_frames_2::first - 6: short_ice_remove_middle_frames_2::main - 7: core::ops::function::FnOnce::call_once -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. diff --git a/tests/ui/panics/short-ice-remove-middle-frames.rs b/tests/ui/panics/short-ice-remove-middle-frames.rs deleted file mode 100644 index 41fb6e9950e6c..0000000000000 --- a/tests/ui/panics/short-ice-remove-middle-frames.rs +++ /dev/null @@ -1,63 +0,0 @@ -//@ compile-flags:-Cstrip=none -//@ run-fail -//@ check-run-results -//@ exec-env:RUST_BACKTRACE=1 -//@ needs-unwind -//@ ignore-android FIXME #17520 -//@ ignore-openbsd no support for libbacktrace without filename -//@ ignore-sgx Backtraces not symbolized -//@ ignore-fuchsia Backtraces not symbolized -//@ ignore-msvc the `__rust_{begin,end}_short_backtrace` symbols aren't reliable. - -// This is needed to avoid test output differences across std being built with v0 symbols vs legacy -// symbols. -//@ normalize-stderr: "begin_panic::<&str>" -> "begin_panic" -// This variant occurs on macOS with `rust.debuginfo-level = "line-tables-only"` (#133997) -//@ normalize-stderr: " begin_panic<&str>" -> " std::panicking::begin_panic" -// And this is for differences between std with and without debuginfo. -//@ normalize-stderr: "\n +at [^\n]+" -> "" - -#[inline(never)] -fn __rust_begin_short_backtrace T>(f: F) -> T { - let result = f(); - std::hint::black_box(result) -} - -#[inline(never)] -fn __rust_end_short_backtrace T>(f: F) -> T { - let result = f(); - std::hint::black_box(result) -} - -fn first() { - __rust_end_short_backtrace(|| second()); - // do not take effect since we already has a inner call of __rust_end_short_backtrace -} - -fn second() { - __rust_end_short_backtrace(|| third()); -} - -fn third() { - fourth(); // won't show up in backtrace -} - -fn fourth() { - fifth(); // won't show up in backtrace -} - -fn fifth() { - __rust_begin_short_backtrace(|| sixth()); -} - -fn sixth() { - seven(); -} - -fn seven() { - panic!("debug!!!"); -} - -fn main() { - first(); -} diff --git a/tests/ui/panics/short-ice-remove-middle-frames.run.stderr b/tests/ui/panics/short-ice-remove-middle-frames.run.stderr deleted file mode 100644 index e966462331fcf..0000000000000 --- a/tests/ui/panics/short-ice-remove-middle-frames.run.stderr +++ /dev/null @@ -1,15 +0,0 @@ - -thread 'main' panicked at $DIR/short-ice-remove-middle-frames.rs:58:5: -debug!!! -stack backtrace: - 0: std::panicking::begin_panic - 1: short_ice_remove_middle_frames::seven - 2: short_ice_remove_middle_frames::sixth - 3: short_ice_remove_middle_frames::fifth::{{closure}} - [... omitted 4 frames ...] - 4: short_ice_remove_middle_frames::second - 5: short_ice_remove_middle_frames::first::{{closure}} - 6: short_ice_remove_middle_frames::first - 7: short_ice_remove_middle_frames::main - 8: core::ops::function::FnOnce::call_once -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.