From 0763a3afc8f7d71cfe3b62c76fd40912f6a6c9ed Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 26 Aug 2024 20:11:58 -0700 Subject: [PATCH 1/4] Bump backtrace to rust-lang/backtrace@fc37b22 It should be 0.3.74~ish. This should help with backtraces on Android, QNX NTO 7.0, and Windows. --- library/backtrace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/backtrace b/library/backtrace index 72265bea21089..fc37b22dc8a38 160000 --- a/library/backtrace +++ b/library/backtrace @@ -1 +1 @@ -Subproject commit 72265bea210891ae47bbe6d4f17b493ef0606619 +Subproject commit fc37b22dc8a384d93f6b7b4817266eec6433875e From fb200a5f04066275fc3302d206d2743aeb5f349d Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 27 Aug 2024 11:32:42 -0700 Subject: [PATCH 2/4] hack in track-caller to ub-checks --- library/core/src/ub_checks.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs index c1a8c34539e6c..60306389b18dd 100644 --- a/library/core/src/ub_checks.rs +++ b/library/core/src/ub_checks.rs @@ -65,9 +65,10 @@ macro_rules! assert_unsafe_precondition { #[inline] #[rustc_nounwind] #[rustc_const_unstable(feature = "const_ub_checks", issue = "none")] + #[track_caller] const fn precondition_check($($name:$ty),*) { if !$e { - ::core::panicking::panic_nounwind( + ::core::panicking::panic_nounwind_fmt( concat!("unsafe precondition(s) violated: ", $message) ); } @@ -92,8 +93,10 @@ pub use intrinsics::ub_checks as check_library_ub; /// language UB checks which generally produce better errors. #[rustc_const_unstable(feature = "const_ub_checks", issue = "none")] #[inline] +#[track_caller] pub(crate) const fn check_language_ub() -> bool { #[inline] + #[track_caller] fn runtime() -> bool { // Disable UB checks in Miri. !cfg!(miri) @@ -116,11 +119,13 @@ pub(crate) const fn check_language_ub() -> bool { /// for `assert_unsafe_precondition!` with `check_language_ub`, in which case the /// check is anyway not executed in `const`. #[inline] +#[track_caller] pub(crate) const fn is_aligned_and_not_null(ptr: *const (), align: usize) -> bool { !ptr.is_null() && ptr.is_aligned_to(align) } #[inline] +#[track_caller] pub(crate) const fn is_valid_allocation_size(size: usize, len: usize) -> bool { let max_len = if size == 0 { usize::MAX } else { isize::MAX as usize / size }; len <= max_len @@ -132,6 +137,7 @@ pub(crate) const fn is_valid_allocation_size(size: usize, len: usize) -> bool { /// Note that in const-eval this function just returns `true` and therefore must /// only be used with `assert_unsafe_precondition!`, similar to `is_aligned_and_not_null`. #[inline] +#[track_caller] pub(crate) const fn is_nonoverlapping( src: *const (), dst: *const (), @@ -139,11 +145,12 @@ pub(crate) const fn is_nonoverlapping( count: usize, ) -> bool { #[inline] + #[track_caller] fn runtime(src: *const (), dst: *const (), size: usize, count: usize) -> bool { let src_usize = src.addr(); let dst_usize = dst.addr(); let Some(size) = size.checked_mul(count) else { - crate::panicking::panic_nounwind( + crate::panicking::panic_nounwind_fmt( "is_nonoverlapping: `size_of::() * count` overflows a usize", ) }; From 0a0d33ab2213e224d787f066eb252fd57dc4a6a2 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 27 Aug 2024 11:05:45 -0400 Subject: [PATCH 3/4] Add some track_caller info to precondition panics --- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 +++- compiler/rustc_codegen_ssa/src/size_of_val.rs | 10 +++++++++- library/core/src/panicking.rs | 2 ++ tests/ui/extern/extern-types-field-offset.run.stderr | 2 +- .../extern/extern-types-size_of_val.align.run.stderr | 2 +- .../ui/extern/extern-types-size_of_val.size.run.stderr | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 817e2ca72ec12..83b221213ac7f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -790,13 +790,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let (fn_abi, llfn, instance) = common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind); + let location = self.get_caller_location(bx, source_info).immediate(); + // Codegen the actual panic invoke/call. helper.do_call( self, bx, fn_abi, llfn, - &[msg.0, msg.1], + &[msg.0, msg.1, location], target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)), unwind, &[], diff --git a/compiler/rustc_codegen_ssa/src/size_of_val.rs b/compiler/rustc_codegen_ssa/src/size_of_val.rs index 933904f984505..eb48c2181b397 100644 --- a/compiler/rustc_codegen_ssa/src/size_of_val.rs +++ b/compiler/rustc_codegen_ssa/src/size_of_val.rs @@ -72,12 +72,20 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // (But we are in good company, this code is duplicated plenty of times.) let fn_ty = bx.fn_decl_backend_type(fn_abi); + let const_loc = bx.tcx().span_as_caller_location(rustc_span::DUMMY_SP); + let location = crate::mir::operand::OperandRef::from_const( + bx, + const_loc, + bx.tcx().caller_location_ty(), + ) + .immediate(); + bx.call( fn_ty, /* fn_attrs */ None, Some(fn_abi), llfn, - &[msg.0, msg.1], + &[msg.0, msg.1, location], None, None, ); diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 7affe63825719..78995cd0cae40 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -212,6 +212,7 @@ panic_const! { /// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller. /// If you want `#[track_caller]` for nicer errors, call `panic_nounwind_fmt` directly. +#[track_caller] #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[lang = "panic_nounwind"] // needed by codegen for non-unwinding panics @@ -222,6 +223,7 @@ pub const fn panic_nounwind(expr: &'static str) -> ! { } /// Like `panic_nounwind`, but also inhibits showing a backtrace. +#[track_caller] #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[rustc_nounwind] diff --git a/tests/ui/extern/extern-types-field-offset.run.stderr b/tests/ui/extern/extern-types-field-offset.run.stderr index f14073989800b..5121ea7b07e3f 100644 --- a/tests/ui/extern/extern-types-field-offset.run.stderr +++ b/tests/ui/extern/extern-types-field-offset.run.stderr @@ -1,4 +1,4 @@ -thread 'main' panicked at core/src/panicking.rs:$LINE:$COL: +thread 'main' panicked at $DIR/extern-types-field-offset.rs:1:1: attempted to compute the size or alignment of extern type `Opaque` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread caused non-unwinding panic. aborting. diff --git a/tests/ui/extern/extern-types-size_of_val.align.run.stderr b/tests/ui/extern/extern-types-size_of_val.align.run.stderr index faad1aa13faf6..a5740d351205c 100644 --- a/tests/ui/extern/extern-types-size_of_val.align.run.stderr +++ b/tests/ui/extern/extern-types-size_of_val.align.run.stderr @@ -1,4 +1,4 @@ -thread 'main' panicked at core/src/panicking.rs:$LINE:$COL: +thread 'main' panicked at $DIR/extern-types-size_of_val.rs:1:1: attempted to compute the size or alignment of extern type `A` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread caused non-unwinding panic. aborting. diff --git a/tests/ui/extern/extern-types-size_of_val.size.run.stderr b/tests/ui/extern/extern-types-size_of_val.size.run.stderr index faad1aa13faf6..a5740d351205c 100644 --- a/tests/ui/extern/extern-types-size_of_val.size.run.stderr +++ b/tests/ui/extern/extern-types-size_of_val.size.run.stderr @@ -1,4 +1,4 @@ -thread 'main' panicked at core/src/panicking.rs:$LINE:$COL: +thread 'main' panicked at $DIR/extern-types-size_of_val.rs:1:1: attempted to compute the size or alignment of extern type `A` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread caused non-unwinding panic. aborting. From 8919cb49e330d0e68affddc6bf487841f3b8f732 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 27 Aug 2024 11:40:18 -0700 Subject: [PATCH 4/4] oops --- library/core/src/ub_checks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs index 60306389b18dd..159010c611e8b 100644 --- a/library/core/src/ub_checks.rs +++ b/library/core/src/ub_checks.rs @@ -68,7 +68,7 @@ macro_rules! assert_unsafe_precondition { #[track_caller] const fn precondition_check($($name:$ty),*) { if !$e { - ::core::panicking::panic_nounwind_fmt( + ::core::panicking::panic_nounwind( concat!("unsafe precondition(s) violated: ", $message) ); } @@ -150,7 +150,7 @@ pub(crate) const fn is_nonoverlapping( let src_usize = src.addr(); let dst_usize = dst.addr(); let Some(size) = size.checked_mul(count) else { - crate::panicking::panic_nounwind_fmt( + crate::panicking::panic_nounwind( "is_nonoverlapping: `size_of::() * count` overflows a usize", ) };