@@ -88,6 +88,7 @@ resource icx_popper(ccx: @crate_ctxt) {
88
88
89
89
impl ccx_icx for @crate_ctxt {
90
90
fn insn_ctxt ( s : str ) -> icx_popper {
91
+ #debug ( "new insn_ctxt: %s" , s) ;
91
92
if ( self . sess . opts . count_llvm_insns ) {
92
93
* self . stats . llvm_insn_ctxt += [ s] ;
93
94
}
@@ -356,7 +357,9 @@ fn malloc_boxed(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
356
357
let _icx = bcx. insn_ctxt ( "trans_malloc_boxed" ) ;
357
358
let mut ti = none;
358
359
let box = malloc_boxed_raw ( bcx, t, ti) ;
359
- let body = GEPi ( bcx, box, [ 0 u, abi:: box_field_body] ) ;
360
+ let box_no_addrspace = non_gc_box_cast (
361
+ bcx, box, ty:: mk_imm_box ( bcx. tcx ( ) , t) ) ;
362
+ let body = GEPi ( bcx, box_no_addrspace, [ 0 u, abi:: box_field_body] ) ;
360
363
ret { box : box, body : body} ;
361
364
}
362
365
@@ -2399,7 +2402,8 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
2399
2402
let t = expr_ty ( cx, base) ;
2400
2403
let val = alt check ty:: get ( t) . struct {
2401
2404
ty:: ty_box ( _) {
2402
- GEPi ( sub. bcx , sub. val , [ 0 u, abi:: box_field_body] )
2405
+ let non_gc_val = non_gc_box_cast ( sub. bcx , sub. val , t) ;
2406
+ GEPi ( sub. bcx , non_gc_val, [ 0 u, abi:: box_field_body] )
2403
2407
}
2404
2408
ty:: ty_res ( _, _, _) {
2405
2409
GEPi ( sub. bcx , sub. val , [ 0 u, 1 u] )
@@ -2417,6 +2421,21 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
2417
2421
}
2418
2422
}
2419
2423
2424
+ #[ doc = "
2425
+ Get the type of a box in the default address space.
2426
+
2427
+ Shared box pointers live in address space 1 so the GC strategy can find them.
2428
+ Before taking a pointer to the inside of a box it should be cast into address
2429
+ space 0. Otherwise the resulting (non-box) pointer will be in the wrong
2430
+ address space and thus be the wrong type.
2431
+ " ]
2432
+ fn non_gc_box_cast ( cx : block , val : ValueRef , t : ty:: t ) -> ValueRef {
2433
+ #debug ( "non_gc_box_cast" ) ;
2434
+ add_comment ( cx, "non_gc_box_cast" ) ;
2435
+ let non_gc_t = type_of_non_gc_box ( cx. ccx ( ) , t) ;
2436
+ PointerCast ( cx, val, non_gc_t)
2437
+ }
2438
+
2420
2439
fn lval_maybe_callee_to_lval ( c : lval_maybe_callee , ty : ty:: t ) -> lval_result {
2421
2440
let must_bind = alt c. env { self_env ( _, _, _) { true } _ { false } } ;
2422
2441
if must_bind {
0 commit comments