Skip to content

Commit 8ec5639

Browse files
committedSep 23, 2023
Reuse calculate_debuginfo_offset for fragments.
1 parent 3050938 commit 8ec5639

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed
 

‎compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+10-33
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,15 @@ fn calculate_debuginfo_offset<
158158
L: DebugInfoOffsetLocation<'tcx, Bx>,
159159
>(
160160
bx: &mut Bx,
161-
local: mir::Local,
162-
var: &PerLocalVarDebugInfo<'tcx, Bx::DIVariable>,
161+
projection: &[mir::PlaceElem<'tcx>],
163162
base: L,
164163
) -> DebugInfoOffset<L> {
165164
let mut direct_offset = Size::ZERO;
166165
// FIXME(eddyb) use smallvec here.
167166
let mut indirect_offsets = vec![];
168167
let mut place = base;
169168

170-
for elem in &var.projection[..] {
169+
for elem in projection {
171170
match *elem {
172171
mir::ProjectionElem::Deref => {
173172
indirect_offsets.push(Size::ZERO);
@@ -188,23 +187,15 @@ fn calculate_debuginfo_offset<
188187
} => {
189188
let offset = indirect_offsets.last_mut().unwrap_or(&mut direct_offset);
190189
let FieldsShape::Array { stride, count: _ } = place.layout().fields else {
191-
span_bug!(
192-
var.source_info.span,
193-
"ConstantIndex on non-array type {:?}",
194-
place.layout()
195-
)
190+
bug!("ConstantIndex on non-array type {:?}", place.layout())
196191
};
197192
*offset += stride * index;
198193
place = place.project_constant_index(bx, index);
199194
}
200195
_ => {
201196
// Sanity check for `can_use_in_debuginfo`.
202197
debug_assert!(!elem.can_use_in_debuginfo());
203-
span_bug!(
204-
var.source_info.span,
205-
"unsupported var debuginfo place `{:?}`",
206-
mir::Place { local, projection: var.projection },
207-
)
198+
bug!("unsupported var debuginfo projection `{:?}`", projection)
208199
}
209200
}
210201
}
@@ -407,7 +398,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
407398
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { return };
408399

409400
let DebugInfoOffset { direct_offset, indirect_offsets, result: _ } =
410-
calculate_debuginfo_offset(bx, local, &var, base.layout);
401+
calculate_debuginfo_offset(bx, &var.projection, base.layout);
411402

412403
// When targeting MSVC, create extra allocas for arguments instead of pointing multiple
413404
// dbg_var_addr() calls into the same alloca with offsets. MSVC uses CodeView records
@@ -425,7 +416,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
425416

426417
if should_create_individual_allocas {
427418
let DebugInfoOffset { direct_offset: _, indirect_offsets: _, result: place } =
428-
calculate_debuginfo_offset(bx, local, &var, base);
419+
calculate_debuginfo_offset(bx, &var.projection, base);
429420

430421
// Create a variable which will be a pointer to the actual value
431422
let ptr_ty = Ty::new_ptr(
@@ -532,23 +523,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
532523
let fragment = if let Some(ref fragment) = var.composite {
533524
let var_layout = self.cx.layout_of(var_ty);
534525

535-
let mut fragment_start = Size::ZERO;
536-
let mut fragment_layout = var_layout;
537-
538-
for elem in &fragment.projection {
539-
match *elem {
540-
mir::ProjectionElem::Field(field, _) => {
541-
let i = field.index();
542-
fragment_start += fragment_layout.fields.offset(i);
543-
fragment_layout = fragment_layout.field(self.cx, i);
544-
}
545-
_ => span_bug!(
546-
var.source_info.span,
547-
"unsupported fragment projection `{:?}`",
548-
elem,
549-
),
550-
}
551-
}
526+
let DebugInfoOffset { direct_offset, indirect_offsets, result: fragment_layout } =
527+
calculate_debuginfo_offset(bx, &fragment.projection, var_layout);
528+
debug_assert!(indirect_offsets.is_empty());
552529

553530
if fragment_layout.size == Size::ZERO {
554531
// Fragment is a ZST, so does not represent anything. Avoid generating anything
@@ -559,7 +536,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
559536
// DWARF is concerned, it's not really a fragment.
560537
None
561538
} else {
562-
Some(fragment_start..fragment_start + fragment_layout.size)
539+
Some(direct_offset..direct_offset + fragment_layout.size)
563540
}
564541
} else {
565542
None

0 commit comments

Comments
 (0)