Skip to content

Commit 7de9aac

Browse files
committed
Support ConstantIndex in debuginfo.
1 parent 2ec0071 commit 7de9aac

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
88
use rustc_session::config::DebugInfo;
99
use rustc_span::symbol::{kw, Symbol};
1010
use rustc_span::{BytePos, Span};
11-
use rustc_target::abi::{Abi, FieldIdx, Size, VariantIdx};
11+
use rustc_target::abi::{Abi, FieldIdx, FieldsShape, Size, VariantIdx};
1212

1313
use super::operand::{OperandRef, OperandValue};
1414
use super::place::PlaceRef;
@@ -83,6 +83,7 @@ trait DebugInfoOffsetLocation<'tcx, Bx> {
8383
fn deref(&self, bx: &mut Bx) -> Self;
8484
fn layout(&self) -> TyAndLayout<'tcx>;
8585
fn project_field(&self, bx: &mut Bx, field: FieldIdx) -> Self;
86+
fn project_constant_index(&self, bx: &mut Bx, offset: u64) -> Self;
8687
fn downcast(&self, bx: &mut Bx, variant: VariantIdx) -> Self;
8788
}
8889

@@ -101,6 +102,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> DebugInfoOffsetLocation<'tcx, Bx>
101102
PlaceRef::project_field(*self, bx, field.index())
102103
}
103104

105+
fn project_constant_index(&self, bx: &mut Bx, offset: u64) -> Self {
106+
let lloffset = bx.cx().const_usize(offset);
107+
self.project_index(bx, lloffset)
108+
}
109+
104110
fn downcast(&self, bx: &mut Bx, variant: VariantIdx) -> Self {
105111
self.project_downcast(bx, variant)
106112
}
@@ -123,6 +129,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> DebugInfoOffsetLocation<'tcx, Bx>
123129
self.field(bx.cx(), field.index())
124130
}
125131

132+
fn project_constant_index(&self, bx: &mut Bx, index: u64) -> Self {
133+
self.field(bx.cx(), index as usize)
134+
}
135+
126136
fn downcast(&self, bx: &mut Bx, variant: VariantIdx) -> Self {
127137
self.for_variant(bx.cx(), variant)
128138
}
@@ -168,6 +178,18 @@ fn calculate_debuginfo_offset<
168178
mir::ProjectionElem::Downcast(_, variant) => {
169179
place = place.downcast(bx, variant);
170180
}
181+
mir::ProjectionElem::ConstantIndex {
182+
offset: index,
183+
min_length: _,
184+
from_end: false,
185+
} => {
186+
let offset = indirect_offsets.last_mut().unwrap_or(&mut direct_offset);
187+
let FieldsShape::Array { stride, count: _ } = place.layout().fields else {
188+
span_bug!(var.source_info.span, "ConstantIndex on non-array type {:?}", place.layout())
189+
};
190+
*offset += stride * index;
191+
place = place.project_constant_index(bx, index);
192+
}
171193
_ => {
172194
// Sanity check for `can_use_in_debuginfo`.
173195
debug_assert!(!elem.can_use_in_debuginfo());

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,11 @@ impl<V, T> ProjectionElem<V, T> {
15541554
/// Returns `true` if this is accepted inside `VarDebugInfoContents::Place`.
15551555
pub fn can_use_in_debuginfo(&self) -> bool {
15561556
match self {
1557-
Self::Deref | Self::Downcast(_, _) | Self::Field(_, _) => true,
1558-
Self::ConstantIndex { .. }
1557+
Self::ConstantIndex { from_end: false, .. }
1558+
| Self::Deref
1559+
| Self::Downcast(_, _)
1560+
| Self::Field(_, _) => true,
1561+
Self::ConstantIndex { from_end: true, .. }
15591562
| Self::Index(_)
15601563
| Self::OpaqueCast(_)
15611564
| Self::Subslice { .. } => false,

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
let _13: &T; // in scope 1 at $DIR/issue_76432.rs:+3:18: +3:24
2222
let _14: &T; // in scope 1 at $DIR/issue_76432.rs:+3:26: +3:32
2323
scope 2 {
24-
debug v1 => _12; // in scope 2 at $DIR/issue_76432.rs:+3:10: +3:16
25-
debug v2 => _13; // in scope 2 at $DIR/issue_76432.rs:+3:18: +3:24
26-
debug v3 => _14; // in scope 2 at $DIR/issue_76432.rs:+3:26: +3:32
24+
debug v1 => &(*_2)[0 of 3]; // in scope 2 at $DIR/issue_76432.rs:+3:10: +3:16
25+
debug v2 => &(*_2)[1 of 3]; // in scope 2 at $DIR/issue_76432.rs:+3:18: +3:24
26+
debug v3 => &(*_2)[2 of 3]; // in scope 2 at $DIR/issue_76432.rs:+3:26: +3:32
2727
}
2828
}
2929

@@ -52,15 +52,6 @@
5252
}
5353

5454
bb2: {
55-
StorageLive(_12); // scope 1 at $DIR/issue_76432.rs:+3:10: +3:16
56-
_12 = &(*_2)[0 of 3]; // scope 1 at $DIR/issue_76432.rs:+3:10: +3:16
57-
StorageLive(_13); // scope 1 at $DIR/issue_76432.rs:+3:18: +3:24
58-
_13 = &(*_2)[1 of 3]; // scope 1 at $DIR/issue_76432.rs:+3:18: +3:24
59-
StorageLive(_14); // scope 1 at $DIR/issue_76432.rs:+3:26: +3:32
60-
_14 = &(*_2)[2 of 3]; // scope 1 at $DIR/issue_76432.rs:+3:26: +3:32
61-
StorageDead(_14); // scope 1 at $DIR/issue_76432.rs:+3:84: +3:85
62-
StorageDead(_13); // scope 1 at $DIR/issue_76432.rs:+3:84: +3:85
63-
StorageDead(_12); // scope 1 at $DIR/issue_76432.rs:+3:84: +3:85
6455
StorageDead(_5); // scope 0 at $DIR/issue_76432.rs:+6:1: +6:2
6556
StorageDead(_2); // scope 0 at $DIR/issue_76432.rs:+6:1: +6:2
6657
return; // scope 0 at $DIR/issue_76432.rs:+6:2: +6:2

0 commit comments

Comments
 (0)