Skip to content

Commit 526a2c7

Browse files
committed
ICE when checking LocalInfo on runtime MIR.
1 parent 50d0959 commit 526a2c7

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
242242
let full_debug_info = bx.sess().opts.debuginfo == DebugInfo::Full;
243243

244244
// FIXME(eddyb) maybe name the return place as `_0` or `return`?
245-
if local == mir::RETURN_PLACE && !self.mir.local_decls[mir::RETURN_PLACE].is_user_variable()
246-
{
245+
if local == mir::RETURN_PLACE {
247246
return;
248247
}
249248

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -919,15 +919,15 @@ impl<'tcx> LocalDecl<'tcx> {
919919
/// - or `match ... { C(x) => ... }`
920920
pub fn can_be_made_mutable(&self) -> bool {
921921
matches!(
922-
self.local_info,
923-
ClearCrossCrate::Set(box LocalInfo::User(
922+
self.local_info(),
923+
LocalInfo::User(
924924
BindingForm::Var(VarBindingForm {
925925
binding_mode: ty::BindingMode::BindByValue(_),
926926
opt_ty_info: _,
927927
opt_match_place: _,
928928
pat_span: _,
929929
}) | BindingForm::ImplicitSelf(ImplicitSelfKind::Imm),
930-
))
930+
)
931931
)
932932
}
933933

@@ -936,56 +936,51 @@ impl<'tcx> LocalDecl<'tcx> {
936936
/// mutable bindings, but the inverse does not necessarily hold).
937937
pub fn is_nonref_binding(&self) -> bool {
938938
matches!(
939-
self.local_info,
940-
ClearCrossCrate::Set(box LocalInfo::User(
939+
self.local_info(),
940+
LocalInfo::User(
941941
BindingForm::Var(VarBindingForm {
942942
binding_mode: ty::BindingMode::BindByValue(_),
943943
opt_ty_info: _,
944944
opt_match_place: _,
945945
pat_span: _,
946946
}) | BindingForm::ImplicitSelf(_),
947-
))
947+
)
948948
)
949949
}
950950

951951
/// Returns `true` if this variable is a named variable or function
952952
/// parameter declared by the user.
953953
#[inline]
954954
pub fn is_user_variable(&self) -> bool {
955-
matches!(self.local_info, ClearCrossCrate::Set(box LocalInfo::User(_)))
955+
matches!(self.local_info(), LocalInfo::User(_))
956956
}
957957

958958
/// Returns `true` if this is a reference to a variable bound in a `match`
959959
/// expression that is used to access said variable for the guard of the
960960
/// match arm.
961961
pub fn is_ref_for_guard(&self) -> bool {
962-
matches!(
963-
self.local_info,
964-
ClearCrossCrate::Set(box LocalInfo::User(BindingForm::RefForGuard))
965-
)
962+
matches!(self.local_info(), LocalInfo::User(BindingForm::RefForGuard))
966963
}
967964

968965
/// Returns `Some` if this is a reference to a static item that is used to
969966
/// access that static.
970967
pub fn is_ref_to_static(&self) -> bool {
971-
matches!(self.local_info, ClearCrossCrate::Set(box LocalInfo::StaticRef { .. }))
968+
matches!(self.local_info(), LocalInfo::StaticRef { .. })
972969
}
973970

974971
/// Returns `Some` if this is a reference to a thread-local static item that is used to
975972
/// access that static.
976973
pub fn is_ref_to_thread_local(&self) -> bool {
977-
match self.local_info {
978-
ClearCrossCrate::Set(box LocalInfo::StaticRef { is_thread_local, .. }) => {
979-
is_thread_local
980-
}
974+
match self.local_info() {
975+
LocalInfo::StaticRef { is_thread_local, .. } => *is_thread_local,
981976
_ => false,
982977
}
983978
}
984979

985980
/// Returns `true` if this is a DerefTemp
986981
pub fn is_deref_temp(&self) -> bool {
987-
match self.local_info {
988-
ClearCrossCrate::Set(box LocalInfo::DerefTemp) => return true,
982+
match self.local_info() {
983+
LocalInfo::DerefTemp => return true,
989984
_ => (),
990985
}
991986
return false;

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use rustc_hir::intravisit::{self, Visitor};
2929
use rustc_index::vec::IndexVec;
3030
use rustc_middle::mir::visit::Visitor as _;
3131
use rustc_middle::mir::{
32-
traversal, AnalysisPhase, Body, ConstQualifs, Constant, LocalDecl, MirPass, MirPhase, Operand,
33-
Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo, Statement, StatementKind,
34-
TerminatorKind,
32+
traversal, AnalysisPhase, Body, ClearCrossCrate, ConstQualifs, Constant, LocalDecl, MirPass,
33+
MirPhase, Operand, Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo,
34+
Statement, StatementKind, TerminatorKind,
3535
};
3636
use rustc_middle::ty::query::Providers;
3737
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
@@ -532,6 +532,12 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
532532
&[&lower_intrinsics::LowerIntrinsics, &simplify::SimplifyCfg::new("elaborate-drops")];
533533

534534
pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup)));
535+
536+
// Clear this by anticipation. Optimizations and runtime MIR have no reason to look
537+
// into this information, which is meant for borrowck diagnostics.
538+
for decl in &mut body.local_decls {
539+
decl.local_info = ClearCrossCrate::Clear;
540+
}
535541
}
536542

537543
fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

tests/codegen/fewer-names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub fn sum(x: u32, y: u32) -> u32 {
1313

1414
// NO-LABEL: define{{.*}}i32 @sum(i32 noundef %x, i32 noundef %y)
1515
// NO-NEXT: start:
16-
// NO-NEXT: %z = add i32 %y, %x
17-
// NO-NEXT: ret i32 %z
16+
// NO-NEXT: %0 = add i32 %y, %x
17+
// NO-NEXT: ret i32 %0
1818
let z = x + y;
1919
z
2020
}

tests/codegen/var-names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn test(a: u32, b: u32) -> u32 {
99
// CHECK: %c = add i32 %a, %b
1010
let d = c;
1111
let e = d * a;
12-
// CHECK-NEXT: %e = mul i32 %c, %a
12+
// CHECK-NEXT: %0 = mul i32 %c, %a
1313
e
14-
// CHECK-NEXT: ret i32 %e
14+
// CHECK-NEXT: ret i32 %0
1515
}

0 commit comments

Comments
 (0)