Skip to content

Commit 593a42c

Browse files
committed
---
yaml --- r: 3991 b: refs/heads/master c: a0ab57b h: refs/heads/master i: 3989: 835ed8a 3987: fa76a39 3983: 55a213b v: v3
1 parent 4a5eeee commit 593a42c

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ce3d6339e0454b6353e863f226ddd2a3900f9e51
2+
refs/heads/master: a0ab57b3f62017c065c6f3ced67e4c35898b51a3

trunk/src/comp/middle/trans_alt.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -382,29 +382,38 @@ fn compile_submatch(@block_ctxt bcx, &match m, ValueRef[] vals, &mk_fail f,
382382
}
383383
}
384384

385-
// FIXME breaks on unreacheable cases
385+
// Returns false for unreachable blocks
386386
fn make_phi_bindings(&@block_ctxt bcx, &exit_node[] map,
387-
&ast::pat_id_map ids) {
388-
fn assoc(str key, &tup(str, ValueRef)[] list) -> ValueRef {
387+
&ast::pat_id_map ids) -> bool {
388+
fn assoc(str key, &tup(str, ValueRef)[] list) -> option::t[ValueRef] {
389389
for (tup(str, ValueRef) elt in list) {
390-
if (str::eq(elt._0, key)) { ret elt._1; }
390+
if (str::eq(elt._0, key)) { ret some(elt._1); }
391391
}
392-
fail;
392+
ret none;
393393
}
394394

395395
auto our_block = bcx.llbb as uint;
396+
auto success = true;
396397
for each (@tup(ast::ident, ast::node_id) item in ids.items()) {
397398
auto llbbs = ~[];
398399
auto vals = ~[];
399400
for (exit_node ex in map) {
400401
if (ex.to as uint == our_block) {
401-
llbbs += ~[ex.from];
402-
vals += ~[assoc(item._0, ex.bound)];
402+
alt (assoc(item._0, ex.bound)) {
403+
some(?val) {
404+
llbbs += ~[ex.from];
405+
vals += ~[val];
406+
}
407+
none {}
408+
}
403409
}
404410
}
405-
auto phi = bcx.build.Phi(val_ty(vals.(0)), vals, llbbs);
406-
bcx.fcx.lllocals.insert(item._1, phi);
411+
if (ivec::len(vals) > 0u) {
412+
auto phi = bcx.build.Phi(val_ty(vals.(0)), vals, llbbs);
413+
bcx.fcx.lllocals.insert(item._1, phi);
414+
} else { success = false; }
407415
}
416+
ret success;
408417
}
409418

410419
fn trans_alt(&@block_ctxt cx, &@ast::expr expr, &ast::arm[] arms,
@@ -444,9 +453,13 @@ fn trans_alt(&@block_ctxt cx, &@ast::expr expr, &ast::arm[] arms,
444453
auto arm_results = ~[];
445454
for (ast::arm a in arms) {
446455
auto body_cx = bodies.(i);
447-
make_phi_bindings(body_cx, exit_map, ast::pat_id_map(a.pats.(0)));
448-
auto block_res = trans::trans_block(body_cx, a.block, output);
449-
arm_results += ~[block_res];
456+
if (make_phi_bindings(body_cx, exit_map,
457+
ast::pat_id_map(a.pats.(0)))) {
458+
auto block_res = trans::trans_block(body_cx, a.block, output);
459+
arm_results += ~[block_res];
460+
} else { // Unreachable
461+
arm_results += ~[rslt(body_cx, C_nil())];
462+
}
450463
i += 1u;
451464
}
452465
ret rslt(trans::join_branches(cx, arm_results), C_nil());

0 commit comments

Comments
 (0)