Skip to content

Commit 34ce376

Browse files
committed
Rollup merge of #23365 - dotdash:array_loop_panic, r=eddyb
[expr; 0] currently exhibits inconsistent behaviour and [expr; n] with n > 1 triggers an LLVM assertion in case that \"expr\" diverges.
2 parents 911f7fe + 9eed8ea commit 34ce376

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/librustc_trans/trans/tvec.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
293293
}
294294
SaveIn(lldest) => {
295295
match ty::eval_repeat_count(bcx.tcx(), &**count_expr) {
296-
0 => bcx,
296+
0 => expr::trans_into(bcx, &**element, Ignore),
297297
1 => expr::trans_into(bcx, &**element, SaveIn(lldest)),
298298
count => {
299299
let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));
@@ -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+
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
let x = [panic!("panic evaluated"); 0];
16+
}

0 commit comments

Comments
 (0)