rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.22k stars 12.7k forks source link

This compiles and shouldn't. #700

Closed eholk closed 13 years ago

eholk commented 13 years ago
fn trans_send(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs,
              ast::node_id id) -> result {
    auto bcx = cx;
    auto chn = trans_expr(bcx, lhs);
    bcx = chn.bcx;
    auto data = trans_lval(bcx, rhs);
    bcx = data.res.bcx;
    auto chan_ty = node_id_type(cx.fcx.lcx.ccx, id);
    auto unit_ty;
    alt (ty::struct(cx.fcx.lcx.ccx.tcx, chan_ty)) {
        case (ty::ty_chan(?t)) { unit_ty = t; }
        case (_) { bcx.fcx.lcx.ccx.sess.bug("non-chan type in trans_send"); }
    }

    auto target = bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.chan_target_task,
                                 ~[bcx.fcx.lltaskptr, llchanval]);

    auto data_tmp = deep_copy(bcx, data.res.val, unit_ty, target);

    bcx = data_tmp.bcx;
    auto llchanval = bcx.build.PointerCast(chn.val, T_opaque_chan_ptr());
    auto lldataptr = bcx.build.PointerCast(data_tmp.val, T_ptr(T_i8()));
    bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.send,
                   ~[bcx.fcx.lltaskptr, llchanval, lldataptr]);
    ret rslt(bcx, chn.val);
}

Sorry it's so long, it wasn't obvious how to reduce it. This is code copied out of trans_comm.rs, but with some as-yet uncommitted changes. It's causing an LLVM assert because I'm passing llchanval to Build in the auto target = ... line. I'm using llchanval before it's even declared, let along initialized.

catamorphism commented 13 years ago

This is probably a dup of #481.

eholk commented 13 years ago

Partially. There's the design question of whether it's legal to refer to a variable before it's declared. In this example, however, llchanval was definitely not initialized when I first tried to read from it, which seems like it's a typestate error.