From 8c68c4a52cc98608793bdab8188d76ce02649d68 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 21 May 2013 13:15:48 -0700 Subject: [PATCH] rustc: Don't generate code for unreachable expressions The way we deal with unreachable expressions in trans is pretty ad hoc, but this at least doesn't make it worse, and eliminates the LLVM assertion failure reported in #5741. --- src/librustc/middle/trans/expr.rs | 4 ++++ src/test/run-pass/issue-5741.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/run-pass/issue-5741.rs diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index f457cc80da8..9349c2bcd26 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -499,6 +499,10 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block { let mut bcx = bcx; let _icx = bcx.insn_ctxt("trans_rvalue_stmt"); + if bcx.unreachable { + return bcx; + } + trace_span!(bcx, expr.span, @shorten(bcx.expr_to_str(expr))); match expr.node { diff --git a/src/test/run-pass/issue-5741.rs b/src/test/run-pass/issue-5741.rs new file mode 100644 index 00000000000..b80e37a425b --- /dev/null +++ b/src/test/run-pass/issue-5741.rs @@ -0,0 +1,14 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + return; + while io::stdin().read_line() != ~"quit" { }; +}