Skip to content

Commit 3412f01

Browse files
committed
Auto merge of #123949 - scottmcm:debug-no-means-no-debug-info-when-inlined, r=oli-obk,onur-ozkan
At debuginfo=0, don't inline debuginfo when inlining See #123949 (comment) for info.
2 parents 0e15f5e + 20cf595 commit 3412f01

File tree

108 files changed

+825
-1192
lines changed

Some content is hidden

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

108 files changed

+825
-1192
lines changed

compiler/rustc_mir_transform/src/inline.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::visit::*;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::TypeVisitableExt;
1313
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
14-
use rustc_session::config::OptLevel;
14+
use rustc_session::config::{DebugInfo, OptLevel};
1515
use rustc_span::source_map::Spanned;
1616
use rustc_span::sym;
1717
use rustc_target::abi::FieldIdx;
@@ -699,7 +699,19 @@ impl<'tcx> Inliner<'tcx> {
699699
// Insert all of the (mapped) parts of the callee body into the caller.
700700
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
701701
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
702-
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
702+
if self
703+
.tcx
704+
.sess
705+
.opts
706+
.unstable_opts
707+
.inline_mir_preserve_debug
708+
.unwrap_or(self.tcx.sess.opts.debuginfo != DebugInfo::None)
709+
{
710+
// Note that we need to preserve these in the standard library so that
711+
// people working on rust can build with or without debuginfo while
712+
// still getting consistent results from the mir-opt tests.
713+
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
714+
}
703715
caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));
704716

705717
caller_body[callsite.block].terminator = Some(Terminator {

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,9 @@ options! {
17171717
"enable MIR inlining (default: no)"),
17181718
inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
17191719
"inlining threshold for functions with inline hint (default: 100)"),
1720+
inline_mir_preserve_debug: Option<bool> = (None, parse_opt_bool, [TRACKED],
1721+
"when MIR inlining, whether to preserve debug info for callee variables \
1722+
(default: preserve for debuginfo != None, otherwise remove)"),
17201723
inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
17211724
"a default MIR inlining threshold (default: 50)"),
17221725
input_stats: bool = (false, parse_bool, [UNTRACKED],

src/bootstrap/src/core/builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,14 @@ impl<'a> Builder<'a> {
21022102
// break when incremental compilation is enabled. So this overrides the "no inlining
21032103
// during incremental builds" heuristic for the standard library.
21042104
rustflags.arg("-Zinline-mir");
2105+
2106+
// FIXME: always pass this after the next `#[cfg(bootstrap)]` update.
2107+
if compiler.stage != 0 {
2108+
// Similarly, we need to keep debug info for functions inlined into other std functions,
2109+
// even if we're not going to output debuginfo for the crate we're currently building,
2110+
// so that it'll be available when downstream consumers of std try to use it.
2111+
rustflags.arg("-Zinline-mir-preserve-debug");
2112+
}
21052113
}
21062114

21072115
if self.config.rustc_parallel

tests/codegen/mem-replace-simple-type.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,20 @@ pub fn replace_ref_str<'a>(r: &mut &'a str, v: &'a str) -> &'a str {
3434

3535
#[no_mangle]
3636
// CHECK-LABEL: @replace_short_array_3(
37+
// CHECK-SAME: ptr{{.+}}sret{{.+}}%[[RET:.+]], ptr{{.+}}%r, ptr{{.+}}%v
3738
pub fn replace_short_array_3(r: &mut [u32; 3], v: [u32; 3]) -> [u32; 3] {
3839
// CHECK-NOT: alloca
39-
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %result, ptr align 4 %r, i64 12, i1 false)
40+
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[RET]], ptr align 4 %r, i64 12, i1 false)
4041
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %r, ptr align 4 %v, i64 12, i1 false)
4142
std::mem::replace(r, v)
4243
}
4344

4445
#[no_mangle]
4546
// CHECK-LABEL: @replace_short_array_4(
47+
// CHECK-SAME: ptr{{.+}}sret{{.+}}%[[RET:.+]], ptr{{.+}}%r, ptr{{.+}}%v
4648
pub fn replace_short_array_4(r: &mut [u32; 4], v: [u32; 4]) -> [u32; 4] {
4749
// CHECK-NOT: alloca
48-
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %result, ptr align 4 %r, i64 16, i1 false)
50+
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[RET]], ptr align 4 %r, i64 16, i1 false)
4951
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %r, ptr align 4 %v, i64 16, i1 false)
5052
std::mem::replace(r, v)
5153
}

tests/codegen/slice-ref-equality.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,48 @@ pub fn is_zero_array(data: &[u8; 4]) -> bool {
4343
// equality for non-byte types also just emit a `bcmp`, not a loop.
4444

4545
// CHECK-LABEL: @eq_slice_of_nested_u8(
46-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
47-
// CHECK-SAME: [[USIZE]] noundef %3
46+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
47+
// CHECK-SAME: [[USIZE]] noundef %y.1
4848
#[no_mangle]
4949
fn eq_slice_of_nested_u8(x: &[[u8; 3]], y: &[[u8; 3]]) -> bool {
50-
// CHECK: icmp eq [[USIZE]] %1, %3
51-
// CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] %1, 3
50+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
51+
// CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] {{%x.1|%y.1}}, 3
5252
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
5353
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
5454
x == y
5555
}
5656

5757
// CHECK-LABEL: @eq_slice_of_i32(
58-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
59-
// CHECK-SAME: [[USIZE]] noundef %3
58+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
59+
// CHECK-SAME: [[USIZE]] noundef %y.1
6060
#[no_mangle]
6161
fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool {
62-
// CHECK: icmp eq [[USIZE]] %1, %3
63-
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
62+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
63+
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] {{%x.1|%y.1}}, 2
6464
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
6565
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
6666
x == y
6767
}
6868

6969
// CHECK-LABEL: @eq_slice_of_nonzero(
70-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
71-
// CHECK-SAME: [[USIZE]] noundef %3
70+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
71+
// CHECK-SAME: [[USIZE]] noundef %y.1
7272
#[no_mangle]
7373
fn eq_slice_of_nonzero(x: &[NonZero<i32>], y: &[NonZero<i32>]) -> bool {
74-
// CHECK: icmp eq [[USIZE]] %1, %3
75-
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
74+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
75+
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] {{%x.1|%y.1}}, 2
7676
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
7777
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
7878
x == y
7979
}
8080

8181
// CHECK-LABEL: @eq_slice_of_option_of_nonzero(
82-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
83-
// CHECK-SAME: [[USIZE]] noundef %3
82+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
83+
// CHECK-SAME: [[USIZE]] noundef %y.1
8484
#[no_mangle]
8585
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZero<i16>>], y: &[Option<NonZero<i16>>]) -> bool {
86-
// CHECK: icmp eq [[USIZE]] %1, %3
87-
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1
86+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
87+
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] {{%x.1|%y.1}}, 1
8888
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
8989
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
9090
x == y

tests/crashes/121127.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ known-bug: #121127
2-
//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes
2+
//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes -C debuginfo=2
3+
// Note that as of PR#123949 this only crashes with debuginfo enabled
34

45
#![feature(specialization)]
56

tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-abort.diff

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
scope 1 {
1010
}
1111
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
12-
debug self => _2;
13-
debug other => _3;
1412
let mut _4: (u8, bool);
1513
}
1614

tests/mir-opt/const_prop/inherit_overflow.main.GVN.panic-unwind.diff

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
scope 1 {
1010
}
1111
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
12-
debug self => _2;
13-
debug other => _3;
1412
let mut _4: (u8, bool);
1513
}
1614

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff

-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
let _3: std::ptr::Unique<[bool]>;
1313
let mut _4: std::ptr::Unique<[bool; 0]>;
1414
scope 3 {
15-
debug ptr => _3;
1615
}
1716
scope 4 (inlined Unique::<[bool; 0]>::dangling) {
1817
let mut _5: std::ptr::NonNull<[bool; 0]>;
1918
scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
2019
let _6: *mut [bool; 0];
2120
scope 6 {
22-
debug ptr => _6;
2321
scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) {
24-
debug ptr => _6;
2522
let mut _8: bool;
2623
let _9: ();
2724
let mut _10: *mut ();
@@ -37,7 +34,6 @@
3734
scope 8 (inlined align_of::<[bool; 0]>) {
3835
}
3936
scope 9 (inlined without_provenance_mut::<[bool; 0]>) {
40-
debug addr => _7;
4137
}
4238
}
4339
}

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.panic-abort.diff

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
scope 1 {
1010
}
1111
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
12-
debug self => _2;
13-
debug other => _3;
1412
let mut _4: (u8, bool);
1513
}
1614

tests/mir-opt/dataflow-const-prop/inherit_overflow.main.DataflowConstProp.panic-unwind.diff

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
scope 1 {
1010
}
1111
scope 2 (inlined #[track_caller] <u8 as Add>::add) {
12-
debug self => _2;
13-
debug other => _3;
1412
let mut _4: (u8, bool);
1513
}
1614

tests/mir-opt/dest-prop/union.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// skip-filecheck
22
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
33
//! Tests that we can propagate into places that are projections into unions
4-
//@ compile-flags: -Zunsound-mir-opts
4+
//@ compile-flags: -Zunsound-mir-opts -C debuginfo=full
55
fn val() -> u32 {
66
1
77
}

0 commit comments

Comments
 (0)