Skip to content

Commit a67bafe

Browse files
committed
Auto merge of rust-lang#129658 - saethlin:spare-a-crumb, r=<try>
Add some track_caller info to precondition panics r? `@ghost` Thought of this while looking at rust-lang#129642 (comment)
2 parents 4ac7bcb + d0c6fc5 commit a67bafe

File tree

7 files changed

+20
-5
lines changed

7 files changed

+20
-5
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -790,13 +790,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
790790
let (fn_abi, llfn, instance) =
791791
common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind);
792792

793+
let location = self.get_caller_location(bx, source_info).immediate();
794+
793795
// Codegen the actual panic invoke/call.
794796
helper.do_call(
795797
self,
796798
bx,
797799
fn_abi,
798800
llfn,
799-
&[msg.0, msg.1],
801+
&[msg.0, msg.1, location],
800802
target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
801803
unwind,
802804
&[],

compiler/rustc_codegen_ssa/src/size_of_val.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,20 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
7272
// (But we are in good company, this code is duplicated plenty of times.)
7373
let fn_ty = bx.fn_decl_backend_type(fn_abi);
7474

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

library/core/src/panicking.rs

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ panic_const! {
212212

213213
/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller.
214214
/// If you want `#[track_caller]` for nicer errors, call `panic_nounwind_fmt` directly.
215+
#[track_caller]
215216
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
216217
#[cfg_attr(feature = "panic_immediate_abort", inline)]
217218
#[lang = "panic_nounwind"] // needed by codegen for non-unwinding panics
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
thread 'main' panicked at core/src/panicking.rs:$LINE:$COL:
1+
thread 'main' panicked at $DIR/extern-types-field-offset.rs:1:1:
22
attempted to compute the size or alignment of extern type `Opaque`
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
44
thread caused non-unwinding panic. aborting.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
thread 'main' panicked at core/src/panicking.rs:$LINE:$COL:
1+
thread 'main' panicked at $DIR/extern-types-size_of_val.rs:1:1:
22
attempted to compute the size or alignment of extern type `A`
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
44
thread caused non-unwinding panic. aborting.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
thread 'main' panicked at core/src/panicking.rs:$LINE:$COL:
1+
thread 'main' panicked at $DIR/extern-types-size_of_val.rs:1:1:
22
attempted to compute the size or alignment of extern type `A`
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
44
thread caused non-unwinding panic. aborting.

tests/ui/print_type_sizes/niche-filling.stdout

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
print-type-size type: `std::panic::Location<'_>`: 24 bytes, alignment: 8 bytes
2+
print-type-size field `.file`: 16 bytes
3+
print-type-size field `.line`: 4 bytes
4+
print-type-size field `.col`: 4 bytes
15
print-type-size type: `IndirectNonZero`: 12 bytes, alignment: 4 bytes
26
print-type-size field `.nested`: 8 bytes
37
print-type-size field `.post`: 2 bytes

0 commit comments

Comments
 (0)