Skip to content

Commit 9b69d7a

Browse files
danielsntedinski
authored andcommitted
Correctly track the type of boxed fat pointers when projecting through them (rust-lang#23)
1 parent ecb5622 commit 9b69d7a

File tree

1 file changed

+18
-8
lines changed
  • compiler/rustc_codegen_llvm/src/gotoc

1 file changed

+18
-8
lines changed

compiler/rustc_codegen_llvm/src/gotoc/place.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
use super::cbmc::goto_program::{Expr, Type};
99
use super::metadata::*;
1010
use super::typ::tuple_fld;
11-
use rustc_middle::mir::{Field, Local, Place, ProjectionElem};
11+
use rustc_ast::ast::Mutability;
1212
use rustc_middle::ty::{self, Ty, TyS, VariantDef};
13+
use rustc_middle::{
14+
mir::{Field, Local, Place, ProjectionElem},
15+
ty::layout::HasTyCtxt,
16+
};
1317
use rustc_target::abi::{LayoutOf, TagEncoding, Variants};
1418
use tracing::debug;
1519

@@ -95,13 +99,18 @@ impl<'tcx> ProjectedPlace<'tcx> {
9599
}
96100
// TODO: these assertions fail on a few regressions. Figure out why.
97101
// I think it may have to do with boxed fat pointers.
98-
// assert!(Self::check_expr_typ(&expr, &typ, ctx), "\n{:?}\n{:?}", &expr, &typ);
99102
// assert!(
100-
// Self::check_fat_ptr_typ(&fat_ptr, &fat_ptr_typ, ctx),
103+
// Self::check_expr_typ(&goto_expr, &mir_typ_or_variant, ctx),
101104
// "\n{:?}\n{:?}",
102-
// &fat_ptr,
103-
// &fat_ptr_typ
105+
// &goto_expr,
106+
// &mir_typ_or_variant
104107
// );
108+
assert!(
109+
Self::check_fat_ptr_typ(&fat_ptr_goto_expr, &fat_ptr_mir_typ, ctx),
110+
"\n{:?}\n{:?}",
111+
&fat_ptr_goto_expr,
112+
&fat_ptr_mir_typ
113+
);
105114
ProjectedPlace { goto_expr, mir_typ_or_variant, fat_ptr_goto_expr, fat_ptr_mir_typ }
106115
}
107116
}
@@ -219,12 +228,12 @@ impl<'tcx> GotocCtx<'tcx> {
219228
} else {
220229
before.goto_expr
221230
};
222-
let inner_mir_typ = base_type.builtin_deref(true).unwrap().ty;
223231

232+
let inner_mir_typ_and_mut = base_type.builtin_deref(true).unwrap();
224233
let fat_ptr_mir_typ = if self.is_box_of_unsized(base_type) {
225234
assert!(before.fat_ptr_mir_typ.is_none());
226-
//TODO, not sure this is correct
227-
Some(base_type.boxed_ty())
235+
// If we have a box, its fat pointer typ is a pointer to the boxes inner type.
236+
Some(self.tcx.mk_ptr(inner_mir_typ_and_mut))
228237
} else if self.is_ref_of_unsized(base_type) {
229238
assert!(before.fat_ptr_mir_typ.is_none());
230239
Some(before.mir_typ_or_variant.expect_type())
@@ -240,6 +249,7 @@ impl<'tcx> GotocCtx<'tcx> {
240249
before.fat_ptr_goto_expr
241250
};
242251

252+
let inner_mir_typ = inner_mir_typ_and_mut.ty;
243253
let expr = match inner_mir_typ.kind() {
244254
ty::Slice(_) | ty::Str | ty::Dynamic(..) => {
245255
inner_goto_expr.member("data", &self.symbol_table)

0 commit comments

Comments
 (0)