Skip to content

Commit 84dbaea

Browse files
committed
(c2rust-analyze) Restrict const_tys => const_ref_tys to just ty::Ref, as non-refs work fine on their own.
1 parent 009c65b commit 84dbaea

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

c2rust-analyze/src/context.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ pub struct AnalysisCtxt<'a, 'tcx> {
9898
/// those `PointerId`s consistent, the `Rvalue`'s type must be stored rather than recomputed on
9999
/// the fly.
100100
pub rvalue_tys: HashMap<Location, LTy<'tcx>>,
101-
pub const_tys: HashMap<ConstantKind<'tcx>, LTy<'tcx>>,
101+
pub const_ref_tys: HashMap<ConstantKind<'tcx>, LTy<'tcx>>,
102102
next_ptr_id: NextLocalPointerId,
103103
}
104104

105105
pub struct AnalysisCtxtData<'tcx> {
106106
local_tys: IndexVec<Local, LTy<'tcx>>,
107107
addr_of_local: IndexVec<Local, PointerId>,
108108
rvalue_tys: HashMap<Location, LTy<'tcx>>,
109-
const_tys: HashMap<ConstantKind<'tcx>, LTy<'tcx>>,
109+
const_ref_tys: HashMap<ConstantKind<'tcx>, LTy<'tcx>>,
110110
next_ptr_id: NextLocalPointerId,
111111
}
112112

@@ -199,7 +199,7 @@ impl<'a, 'tcx> AnalysisCtxt<'a, 'tcx> {
199199
c_void_casts: CVoidCasts::new(mir, tcx),
200200
addr_of_local: IndexVec::new(),
201201
rvalue_tys: HashMap::new(),
202-
const_tys: HashMap::new(),
202+
const_ref_tys: HashMap::new(),
203203
next_ptr_id: NextLocalPointerId::new(),
204204
}
205205
}
@@ -213,7 +213,7 @@ impl<'a, 'tcx> AnalysisCtxt<'a, 'tcx> {
213213
local_tys,
214214
addr_of_local,
215215
rvalue_tys,
216-
const_tys,
216+
const_ref_tys,
217217
next_ptr_id,
218218
} = data;
219219
AnalysisCtxt {
@@ -223,7 +223,7 @@ impl<'a, 'tcx> AnalysisCtxt<'a, 'tcx> {
223223
c_void_casts: CVoidCasts::default(),
224224
addr_of_local,
225225
rvalue_tys,
226-
const_tys,
226+
const_ref_tys,
227227
next_ptr_id,
228228
}
229229
}
@@ -233,7 +233,7 @@ impl<'a, 'tcx> AnalysisCtxt<'a, 'tcx> {
233233
local_tys: self.local_tys,
234234
addr_of_local: self.addr_of_local,
235235
rvalue_tys: self.rvalue_tys,
236-
const_tys: self.const_tys,
236+
const_ref_tys: self.const_ref_tys,
237237
next_ptr_id: self.next_ptr_id,
238238
}
239239
}
@@ -426,7 +426,7 @@ impl<'tcx> AnalysisCtxtData<'tcx> {
426426
ref mut local_tys,
427427
ref mut addr_of_local,
428428
ref mut rvalue_tys,
429-
ref mut const_tys,
429+
ref mut const_ref_tys,
430430
ref mut next_ptr_id,
431431
} = *self;
432432

@@ -444,7 +444,7 @@ impl<'tcx> AnalysisCtxtData<'tcx> {
444444
*lty = remap_lty_pointers(lcx, &map, lty);
445445
}
446446

447-
for lty in const_tys.values_mut() {
447+
for lty in const_ref_tys.values_mut() {
448448
*lty = remap_lty_pointers(lcx, &map, lty);
449449
}
450450

@@ -515,7 +515,7 @@ impl<'tcx> TypeOf<'tcx> for Operand<'tcx> {
515515
Operand::Move(pl) | Operand::Copy(pl) => acx.type_of(pl),
516516
Operand::Constant(ref c) => {
517517
let c = &**c;
518-
match acx.const_tys.get(&c.literal) {
518+
match acx.const_ref_tys.get(&c.literal) {
519519
Some(lty) => lty,
520520
None => label_no_pointers(acx, c.ty()),
521521
}

c2rust-analyze/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ fn run(tcx: TyCtxt) {
454454
assert_eq!(local, l);
455455
}
456456

457-
let mut const_tys = HashMap::new();
457+
let mut const_ref_tys = HashMap::new();
458458
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {
459459
for (i, stmt) in bb_data.statements.iter().enumerate() {
460460
let (_, rv) = match &stmt.kind {
@@ -492,11 +492,11 @@ fn run(tcx: TyCtxt) {
492492
}
493493
Rvalue::Use(Operand::Constant(c)) => {
494494
// Constants can include, for example, `""` and `b""` string literals.
495-
if let ConstantKind::Val(_, ty) = c.literal {
495+
if let ConstantKind::Val(_, ty) = c.literal && ty.is_ref() {
496496
// The [`Constant`] is an inline value and thus local to this function,
497497
// as opposed to a global, named `const`s, for example.
498498
// This might miss local, named `const`s,
499-
const_tys
499+
const_ref_tys
500500
.entry(c.literal)
501501
.or_insert_with(|| acx.assign_pointer_ids(ty));
502502
} else {
@@ -513,8 +513,8 @@ fn run(tcx: TyCtxt) {
513513
acx.rvalue_tys.insert(loc, lty);
514514
}
515515
}
516-
assert!(acx.const_tys.is_empty());
517-
acx.const_tys = const_tys;
516+
assert!(acx.const_ref_tys.is_empty());
517+
acx.const_ref_tys = const_ref_tys;
518518

519519
// Compute local equivalence classes and dataflow constraints.
520520
let (dataflow, equiv_constraints) = dataflow::generate_constraints(&acx, &mir);

0 commit comments

Comments
 (0)