Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
| mir::StatementKind::Intrinsic(..)
| mir::StatementKind::ConstEvalCounter
| mir::StatementKind::BackwardIncompatibleDropHint { .. }
| mir::StatementKind::Nop => {}
| mir::StatementKind::Nop(_) => {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
state,
);
}
StatementKind::Nop
StatementKind::Nop(_)
| StatementKind::Retag { .. }
| StatementKind::Deinit(..)
| StatementKind::SetDiscriminant { .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
);
}
StatementKind::ConstEvalCounter
| StatementKind::Nop
| StatementKind::Nop(_)
| StatementKind::Retag { .. }
| StatementKind::Deinit(..)
| StatementKind::BackwardIncompatibleDropHint { .. }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
| StatementKind::ConstEvalCounter
| StatementKind::PlaceMention(..)
| StatementKind::BackwardIncompatibleDropHint { .. }
| StatementKind::Nop => {}
| StatementKind::Nop(_) => {}
StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(..))
| StatementKind::Deinit(..)
| StatementKind::SetDiscriminant { .. } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ fn codegen_stmt<'tcx>(
| StatementKind::StorageDead(_)
| StatementKind::Deinit(_)
| StatementKind::ConstEvalCounter
| StatementKind::Nop
| StatementKind::Nop(_)
| StatementKind::FakeRead(..)
| StatementKind::Retag { .. }
| StatementKind::PlaceMention(..)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
| StatementKind::Coverage(_)
| StatementKind::ConstEvalCounter
| StatementKind::BackwardIncompatibleDropHint { .. }
| StatementKind::Nop => {}
| StatementKind::Nop(_) => {}
}
}
match &bb_data.terminator().kind {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_gcc/src/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
&mut self,
_dbg_var: Self::DIVariable,
_dbg_loc: Self::DILocation,
_variable_alloca: Self::Value,
_is_declared: bool,
_val: Self::Value,
_direct_offset: Size,
_indirect_offsets: &[Size],
_fragment: Option<Range<Size>>,
Expand Down
38 changes: 26 additions & 12 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
&mut self,
dbg_var: &'ll DIVariable,
dbg_loc: &'ll DILocation,
variable_alloca: Self::Value,
is_declared: bool,
val: Self::Value,
direct_offset: Size,
indirect_offsets: &[Size],
fragment: Option<Range<Size>>,
Expand Down Expand Up @@ -183,17 +184,30 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
addr_ops.push((fragment.end - fragment.start).bits() as u64);
}

unsafe {
// FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
DIB(self.cx()),
variable_alloca,
dbg_var,
addr_ops.as_ptr(),
addr_ops.len() as c_uint,
dbg_loc,
self.llbb(),
);
if is_declared {
unsafe {
llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
DIB(self.cx()),
val,
dbg_var,
addr_ops.as_ptr(),
addr_ops.len() as c_uint,
dbg_loc,
self.llbb(),
);
}
} else {
unsafe {
llvm::LLVMRustDIBuilderInsertDbgValueAtEnd(
DIB(self.cx()),
val,
dbg_var,
addr_ops.as_ptr(),
addr_ops.len() as c_uint,
dbg_loc,
self.llbb(),
);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,16 @@ unsafe extern "C" {
InsertAtEnd: &'a BasicBlock,
);

pub(crate) fn LLVMRustDIBuilderInsertDbgValueAtEnd<'a>(
Builder: &DIBuilder<'a>,
Val: &'a Value,
VarInfo: &'a DIVariable,
AddrOps: *const u64,
AddrOpsCount: c_uint,
DL: &'a DILocation,
InsertAtEnd: &'a BasicBlock,
);

pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
Builder: &DIBuilder<'a>,
Name: *const c_char,
Expand Down
54 changes: 51 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
_ => {
// Sanity check for `can_use_in_debuginfo`.
assert!(!elem.can_use_in_debuginfo());
bug!("unsupported var debuginfo projection `{:?}`", projection)
// TODO: Temporarily disabled for testing purposes.

Check failure on line 208 in compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

TODO is used for tasks that should be done before merging a PR; If you want to leave a message in the codebase use FIXME
// bug!("unsupported var debuginfo projection `{:?}`", projection)
}
}
}
Expand Down Expand Up @@ -377,6 +378,52 @@
}
}

pub(crate) fn debug_new_value_to_local(
&self,
bx: &mut Bx,
local: mir::Local,
base: PlaceValue<Bx::Value>,
layout: TyAndLayout<'tcx>,
projection: &[mir::PlaceElem<'tcx>],
) {
let full_debug_info = bx.sess().opts.debuginfo == DebugInfo::Full;
if !full_debug_info {
return;
}

let vars = match &self.per_local_var_debug_info {
Some(per_local) => &per_local[local],
None => return,
};

for var in vars.iter().cloned() {
self.debug_new_value_to_local_as_var(bx, base, layout, projection, var);
}
}

fn debug_new_value_to_local_as_var(
&self,
bx: &mut Bx,
base: PlaceValue<Bx::Value>,
layout: TyAndLayout<'tcx>,
projection: &[mir::PlaceElem<'tcx>],
var: PerLocalVarDebugInfo<'tcx, Bx::DIVariable>,
) {
let Some(dbg_var) = var.dbg_var else { return };
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { return };
let DebugInfoOffset { direct_offset, indirect_offsets, result: _ } =
calculate_debuginfo_offset(bx, projection, layout);
bx.dbg_var_addr(
dbg_var,
dbg_loc,
false,
base.llval,
direct_offset,
&indirect_offsets,
var.fragment,
);
}

fn debug_introduce_local_as_var(
&self,
bx: &mut Bx,
Expand All @@ -386,7 +433,6 @@
) {
let Some(dbg_var) = var.dbg_var else { return };
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { return };

let DebugInfoOffset { direct_offset, indirect_offsets, result: _ } =
calculate_debuginfo_offset(bx, var.projection, base.layout);

Expand Down Expand Up @@ -421,6 +467,7 @@
bx.dbg_var_addr(
dbg_var,
dbg_loc,
true,
alloca.val.llval,
Size::ZERO,
&[Size::ZERO],
Expand All @@ -430,6 +477,7 @@
bx.dbg_var_addr(
dbg_var,
dbg_loc,
true,
base.val.llval,
direct_offset,
&indirect_offsets,
Expand All @@ -455,7 +503,7 @@
let base = FunctionCx::spill_operand_to_stack(operand, Some(name), bx);
bx.clear_dbg_loc();

bx.dbg_var_addr(dbg_var, dbg_loc, base.val.llval, Size::ZERO, &[], fragment);
bx.dbg_var_addr(dbg_var, dbg_loc, true, base.val.llval, Size::ZERO, &[], fragment);
}
}
}
Expand Down
69 changes: 66 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/statement.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use rustc_middle::mir::{self, NonDivergingIntrinsic};
use rustc_middle::span_bug;
use rustc_middle::{bug, span_bug};
use tracing::instrument;

use super::{FunctionCx, LocalRef};
use crate::mir::operand::OperandValue;
use crate::mir::place::PlaceRef;
use crate::traits::*;

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
Expand Down Expand Up @@ -92,8 +94,69 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
| mir::StatementKind::AscribeUserType(..)
| mir::StatementKind::ConstEvalCounter
| mir::StatementKind::PlaceMention(..)
| mir::StatementKind::BackwardIncompatibleDropHint { .. }
| mir::StatementKind::Nop => {}
| mir::StatementKind::BackwardIncompatibleDropHint { .. } => {}
mir::StatementKind::Nop(ref stmt) => {
if let Some(box stmt_kind) = stmt {
match stmt_kind {
mir::StatementKind::Assign(box (dest, rvalue)) => {
if let Some(index) = dest.as_local()
&& let mir::Rvalue::Ref(_, _, place) = *rvalue
{
let place_ref = match self.locals[place.local] {
LocalRef::Place(place_ref)
| LocalRef::UnsizedPlace(place_ref) => Some(place_ref),
LocalRef::Operand(operand_ref) => match operand_ref.val {
OperandValue::Ref(_place_value) => {
todo!("OperandValue::Ref")
}
OperandValue::Immediate(v) => {
Some(PlaceRef::new_sized(v, operand_ref.layout))
}
OperandValue::Pair(_, _) => None,
OperandValue::ZeroSized => None,
},
LocalRef::PendingOperand => None,
};
let (val, layout, projection) =
match (place_ref, place.is_indirect_first_projection()) {
(Some(place_ref), false) => (
place_ref.val,
place_ref.layout,
place.projection.as_slice(),
),
(Some(place_ref), true) => {
let projected_ty = place_ref
.layout
.ty
.builtin_deref(true)
.unwrap_or_else(|| {
bug!("deref of non-pointer {:?}", place_ref)
});
let layout = bx.cx().layout_of(projected_ty);
(place_ref.val, layout, &place.projection[1..])
}
_ => {
let ty =
self.monomorphize(self.mir.local_decls[index].ty);
let layout = bx.cx().layout_of(ty);
let to_backend_ty =
bx.cx().immediate_backend_type(layout);
let place_ref = PlaceRef::new_sized(
bx.cx().const_poison(to_backend_ty),
layout,
);
(place_ref.val, layout, [].as_slice())
}
};
self.debug_new_value_to_local(bx, index, val, layout, projection);
} else {
todo!("add debugging information")
}
}
_ => {}
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/traits/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub trait DebugInfoBuilderMethods: BackendTypes {
&mut self,
dbg_var: Self::DIVariable,
dbg_loc: Self::DILocation,
variable_alloca: Self::Value,
is_declared: bool,
val: Self::Value,
direct_offset: Size,
// NB: each offset implies a deref (i.e. they're steps in a pointer chain).
indirect_offsets: &[Size],
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
| StatementKind::Intrinsic(..)
| StatementKind::ConstEvalCounter
| StatementKind::BackwardIncompatibleDropHint { .. }
| StatementKind::Nop => {}
| StatementKind::Nop(_) => {}
}
}

Expand Down
Loading
Loading