From 6dcf6218b1e0e70e60afe8d1a9f336adad060362 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Apr 2011 15:09:45 -0700 Subject: rustc: Pointer cast when autodereferencing boxed tag types --- src/comp/middle/trans.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/comp') diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 877b68e2..a8e75176 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2934,7 +2934,19 @@ fn autoderef(@block_ctxt cx, ValueRef v, @ty.t t) -> result { vec(C_int(0), C_int(abi.box_rc_field_body))); t1 = mt.ty; - v1 = load_scalar_or_boxed(cx, body, t1); + + // Since we're changing levels of box indirection, we may have + // to cast this pointer, since statically-sized tag types have + // different types depending on whether they're behind a box + // or not. + if (!ty.type_has_dynamic_size(mt.ty)) { + auto llty = type_of(cx.fcx.ccx, mt.ty); + v1 = cx.build.PointerCast(body, T_ptr(llty)); + } else { + v1 = body; + } + + v1 = load_scalar_or_boxed(cx, v1, t1); } case (_) { ret res(cx, v1); -- cgit v1.2.3