Skip to content

Commit 9eed8ea

Browse files
committed
Fix broken codegen for [expr; n] where "expr" diverges
1 parent 3a8f989 commit 9eed8ea

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/librustc_trans/trans/tvec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,12 @@ pub fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
410410
F: FnOnce(Block<'blk, 'tcx>, ValueRef, Ty<'tcx>) -> Block<'blk, 'tcx>,
411411
{
412412
let _icx = push_ctxt("tvec::iter_vec_loop");
413-
let fcx = bcx.fcx;
414413

414+
if bcx.unreachable.get() {
415+
return bcx;
416+
}
417+
418+
let fcx = bcx.fcx;
415419
let loop_bcx = fcx.new_temp_block("expr_repeat");
416420
let next_bcx = fcx.new_temp_block("expr_repeat: next");
417421

src/test/run-fail/issue-23354-2.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:panic evaluated
12+
13+
#[allow(unused_variables)]
14+
fn main() {
15+
// This used to trigger an LLVM assertion during compilation
16+
let x = [panic!("panic evaluated"); 2];
17+
}

0 commit comments

Comments
 (0)