Skip to content

Commit 9ead7da

Browse files
committed
Implicitly use addr_of for output operands in asm.
1 parent 59dcbd9 commit 9ead7da

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,32 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
561561
clobs, volatile, alignstack) => {
562562
let mut constraints = ~[];
563563
let mut cleanups = ~[];
564+
let mut aoutputs = ~[];
564565

565566
let outputs = do outs.map |&(c, out)| {
566567
constraints.push(copy *c);
567568

568-
let outty = ty::arg {
569+
let aoutty = ty::arg {
569570
mode: ast::expl(ast::by_val),
570571
ty: expr_ty(bcx, out)
571572
};
573+
aoutputs.push(unpack_result!(bcx, {
574+
callee::trans_arg_expr(bcx, aoutty, out, &mut cleanups,
575+
None, callee::DontAutorefArg)
576+
}));
577+
578+
let e = match out.node {
579+
ast::expr_addr_of(_, e) => e,
580+
_ => fail!(~"Expression must be addr of")
581+
};
582+
583+
let outty = ty::arg {
584+
mode: ast::expl(ast::by_val),
585+
ty: expr_ty(bcx, e)
586+
};
572587
573588
unpack_result!(bcx, {
574-
callee::trans_arg_expr(bcx, outty, out, &mut cleanups,
589+
callee::trans_arg_expr(bcx, outty, e, &mut cleanups,
575590
None, callee::DontAutorefArg)
576591
})
577592
@@ -627,7 +642,7 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
627642
};
628643

629644
// TODO: Handle >1 outputs
630-
let op = PointerCast(bcx, output, T_ptr(val_ty(output)));
645+
let op = PointerCast(bcx, aoutputs[0], T_ptr(val_ty(output)));
631646
Store(bcx, r, op);
632647

633648
return bcx;

src/libsyntax/ext/asm.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
7575
let out = p.parse_expr();
7676
p.expect(&token::RPAREN);
7777

78+
let out = @ast::expr {
79+
id: cx.next_id(),
80+
callee_id: cx.next_id(),
81+
span: out.span,
82+
node: ast::expr_addr_of(ast::m_mutbl, out)
83+
};
84+
7885
outputs.push((constraint, out));
7986
}
8087
}

0 commit comments

Comments
 (0)