Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b45b561

Browse files
committed
Add some track_caller info to precondition panics
1 parent a567209 commit b45b561

File tree

86 files changed

+254
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+254
-366
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
808808
let (fn_abi, llfn, instance) =
809809
common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind);
810810

811+
let location = self.get_caller_location(bx, source_info).immediate();
812+
811813
// Codegen the actual panic invoke/call.
812814
helper.do_call(
813815
self,
814816
bx,
815817
fn_abi,
816818
llfn,
817-
&[msg.0, msg.1],
819+
&[msg.0, msg.1, location],
818820
target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
819821
unwind,
820822
&[],

compiler/rustc_codegen_ssa/src/size_of_val.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,20 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
7474
// duplicated plenty of times.)
7575
let fn_ty = bx.fn_decl_backend_type(fn_abi);
7676

77+
let const_loc = bx.tcx().span_as_caller_location(rustc_span::DUMMY_SP);
78+
let location = crate::mir::operand::OperandRef::from_const(
79+
bx,
80+
const_loc,
81+
bx.tcx().caller_location_ty(),
82+
)
83+
.immediate();
84+
7785
bx.call(
7886
fn_ty,
7987
/* fn_attrs */ None,
8088
Some(fn_abi),
8189
llfn,
82-
&[msg.0, msg.1],
90+
&[msg.0, msg.1, location],
8391
None,
8492
None,
8593
);

library/core/src/alloc/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl Layout {
126126
#[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")]
127127
#[must_use]
128128
#[inline]
129+
#[track_caller]
129130
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
130131
assert_unsafe_precondition!(
131132
check_library_ub,

library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ impl AsciiChar {
503503
/// something useful. It might be tightened before stabilization.)
504504
#[unstable(feature = "ascii_char", issue = "110998")]
505505
#[inline]
506+
#[track_caller]
506507
pub const unsafe fn digit_unchecked(d: u8) -> Self {
507508
assert_unsafe_precondition!(
508509
check_language_ub,

library/core/src/char/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
2121
/// Converts a `u32` to a `char`, ignoring validity. See [`char::from_u32_unchecked`].
2222
#[inline]
2323
#[must_use]
24+
#[track_caller]
2425
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {
2526
// SAFETY: the caller must guarantee that `i` is a valid char value.
2627
unsafe {

library/core/src/hint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ use crate::{intrinsics, ub_checks};
9797
#[inline]
9898
#[stable(feature = "unreachable", since = "1.27.0")]
9999
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
100-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
100+
#[track_caller]
101101
pub const unsafe fn unreachable_unchecked() -> ! {
102102
ub_checks::assert_unsafe_precondition!(
103103
check_language_ub,

library/core/src/intrinsics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,7 +4407,7 @@ pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(_ptr: *cons
44074407
)]
44084408
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
44094409
#[inline(always)]
4410-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4410+
#[track_caller]
44114411
#[rustc_diagnostic_item = "ptr_copy_nonoverlapping"]
44124412
pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
44134413
#[rustc_intrinsic_const_stable_indirect]
@@ -4515,7 +4515,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
45154515
)]
45164516
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
45174517
#[inline(always)]
4518-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4518+
#[track_caller]
45194519
#[rustc_diagnostic_item = "ptr_copy"]
45204520
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
45214521
#[rustc_intrinsic_const_stable_indirect]
@@ -4602,7 +4602,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
46024602
)]
46034603
#[rustc_const_stable(feature = "const_ptr_write", since = "1.83.0")]
46044604
#[inline(always)]
4605-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4605+
#[track_caller]
46064606
#[rustc_diagnostic_item = "ptr_write_bytes"]
46074607
pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
46084608
#[rustc_intrinsic_const_stable_indirect]

library/core/src/num/int_macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ macro_rules! int_impl {
509509
#[must_use = "this returns the result of the operation, \
510510
without modifying the original"]
511511
#[inline(always)]
512-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
512+
#[track_caller]
513513
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
514514
assert_unsafe_precondition!(
515515
check_language_ub,
@@ -659,7 +659,7 @@ macro_rules! int_impl {
659659
#[must_use = "this returns the result of the operation, \
660660
without modifying the original"]
661661
#[inline(always)]
662-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
662+
#[track_caller]
663663
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
664664
assert_unsafe_precondition!(
665665
check_language_ub,
@@ -809,7 +809,7 @@ macro_rules! int_impl {
809809
#[must_use = "this returns the result of the operation, \
810810
without modifying the original"]
811811
#[inline(always)]
812-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
812+
#[track_caller]
813813
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
814814
assert_unsafe_precondition!(
815815
check_language_ub,
@@ -1153,7 +1153,7 @@ macro_rules! int_impl {
11531153
#[must_use = "this returns the result of the operation, \
11541154
without modifying the original"]
11551155
#[inline(always)]
1156-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1156+
#[track_caller]
11571157
pub const unsafe fn unchecked_neg(self) -> Self {
11581158
assert_unsafe_precondition!(
11591159
check_language_ub,
@@ -1281,7 +1281,7 @@ macro_rules! int_impl {
12811281
#[must_use = "this returns the result of the operation, \
12821282
without modifying the original"]
12831283
#[inline(always)]
1284-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1284+
#[track_caller]
12851285
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
12861286
assert_unsafe_precondition!(
12871287
check_language_ub,
@@ -1402,7 +1402,7 @@ macro_rules! int_impl {
14021402
#[must_use = "this returns the result of the operation, \
14031403
without modifying the original"]
14041404
#[inline(always)]
1405-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1405+
#[track_caller]
14061406
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
14071407
assert_unsafe_precondition!(
14081408
check_language_ub,

library/core/src/num/nonzero.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ where
385385
#[rustc_const_stable(feature = "nonzero", since = "1.28.0")]
386386
#[must_use]
387387
#[inline]
388+
#[track_caller]
388389
pub const unsafe fn new_unchecked(n: T) -> Self {
389390
match Self::new(n) {
390391
Some(n) => n,
@@ -425,6 +426,7 @@ where
425426
#[unstable(feature = "nonzero_from_mut", issue = "106290")]
426427
#[must_use]
427428
#[inline]
429+
#[track_caller]
428430
pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self {
429431
match Self::from_mut(n) {
430432
Some(n) => n,

library/core/src/num/uint_macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ macro_rules! uint_impl {
556556
#[must_use = "this returns the result of the operation, \
557557
without modifying the original"]
558558
#[inline(always)]
559-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
559+
#[track_caller]
560560
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
561561
assert_unsafe_precondition!(
562562
check_language_ub,
@@ -746,7 +746,7 @@ macro_rules! uint_impl {
746746
#[must_use = "this returns the result of the operation, \
747747
without modifying the original"]
748748
#[inline(always)]
749-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
749+
#[track_caller]
750750
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
751751
assert_unsafe_precondition!(
752752
check_language_ub,
@@ -929,7 +929,7 @@ macro_rules! uint_impl {
929929
#[must_use = "this returns the result of the operation, \
930930
without modifying the original"]
931931
#[inline(always)]
932-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
932+
#[track_caller]
933933
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
934934
assert_unsafe_precondition!(
935935
check_language_ub,
@@ -1543,7 +1543,7 @@ macro_rules! uint_impl {
15431543
#[must_use = "this returns the result of the operation, \
15441544
without modifying the original"]
15451545
#[inline(always)]
1546-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1546+
#[track_caller]
15471547
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
15481548
assert_unsafe_precondition!(
15491549
check_language_ub,
@@ -1664,7 +1664,7 @@ macro_rules! uint_impl {
16641664
#[must_use = "this returns the result of the operation, \
16651665
without modifying the original"]
16661666
#[inline(always)]
1667-
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1667+
#[track_caller]
16681668
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
16691669
assert_unsafe_precondition!(
16701670
check_language_ub,

0 commit comments

Comments
 (0)