Skip to content

Commit 6dcf621

Browse files
committed
rustc: Pointer cast when autodereferencing boxed tag types
1 parent 9b35051 commit 6dcf621

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2934,7 +2934,19 @@ fn autoderef(@block_ctxt cx, ValueRef v, @ty.t t) -> result {
29342934
vec(C_int(0),
29352935
C_int(abi.box_rc_field_body)));
29362936
t1 = mt.ty;
2937-
v1 = load_scalar_or_boxed(cx, body, t1);
2937+
2938+
// Since we're changing levels of box indirection, we may have
2939+
// to cast this pointer, since statically-sized tag types have
2940+
// different types depending on whether they're behind a box
2941+
// or not.
2942+
if (!ty.type_has_dynamic_size(mt.ty)) {
2943+
auto llty = type_of(cx.fcx.ccx, mt.ty);
2944+
v1 = cx.build.PointerCast(body, T_ptr(llty));
2945+
} else {
2946+
v1 = body;
2947+
}
2948+
2949+
v1 = load_scalar_or_boxed(cx, v1, t1);
29382950
}
29392951
case (_) {
29402952
ret res(cx, v1);

0 commit comments

Comments
 (0)