@@ -579,6 +579,8 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
579
579
580
580
debuginfo:: set_source_location ( bcx. fcx , expr. id , expr. span ) ;
581
581
582
+ let ty = expr_ty ( bcx, expr) ;
583
+
582
584
return match expr_kind ( bcx, expr) {
583
585
ty:: LvalueExpr | ty:: RvalueDatumExpr => {
584
586
let datum = unpack_datum ! ( bcx, {
@@ -590,11 +592,10 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
590
592
591
593
ty:: RvalueStmtExpr => {
592
594
bcx = trans_rvalue_stmt_unadjusted ( bcx, expr) ;
593
- nil ( bcx, expr_ty ( bcx , expr ) )
595
+ nil ( bcx, ty )
594
596
}
595
597
596
598
ty:: RvalueDpsExpr => {
597
- let ty = expr_ty ( bcx, expr) ;
598
599
if type_is_zero_size ( bcx. ccx ( ) , ty) {
599
600
bcx = trans_rvalue_dps_unadjusted ( bcx, expr, Ignore ) ;
600
601
nil ( bcx, ty)
@@ -631,6 +632,7 @@ fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
631
632
// Get the appropriate expression kind for the expression. Most of the time this just uses
632
633
// ty::expr_kind, but `ExprCall`s can be treated as `RvalueDatumExpr`s in some cases.
633
634
fn expr_kind < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , expr : & ast:: Expr ) -> ty:: ExprKind {
635
+ let ty = expr_ty ( bcx, expr) ;
634
636
match expr. node {
635
637
ast:: ExprCall ( ref f, _) if !bcx. tcx ( ) . is_method_call ( expr. id ) => {
636
638
if let ast:: ExprPath ( ..) = f. node {
@@ -655,6 +657,21 @@ fn expr_kind<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) -> ty::ExprKi
655
657
}
656
658
}
657
659
}
660
+ ast:: ExprBlock ( ref b) if !bcx. fcx . type_needs_drop ( ty) => {
661
+ // Only consider the final expression if it's reachable
662
+ let reachable = if let Some ( ref cfg) = bcx. fcx . cfg {
663
+ cfg. node_is_reachable ( expr. id )
664
+ } else {
665
+ true
666
+ } ;
667
+ // Use the kind of the last expression in the block, since
668
+ // it's the only one that actually matters
669
+ if let Some ( ref expr) = b. expr {
670
+ if reachable {
671
+ return expr_kind ( bcx, expr) ;
672
+ }
673
+ }
674
+ }
658
675
_ => ( )
659
676
}
660
677
@@ -757,6 +774,9 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
757
774
DatumBlock :: new ( bcx, datum. to_expr_datum ( ) )
758
775
}
759
776
}
777
+ ast:: ExprBlock ( ref b) => {
778
+ controlflow:: trans_block_datum ( bcx, b)
779
+ }
760
780
_ => {
761
781
bcx. tcx ( ) . sess . span_bug (
762
782
expr. span ,
@@ -1079,6 +1099,9 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
1079
1099
ast:: ExprInlineAsm ( ref a) => {
1080
1100
asm:: trans_inline_asm ( bcx, a)
1081
1101
}
1102
+ ast:: ExprBlock ( ref b) => {
1103
+ controlflow:: trans_block ( bcx, b, Ignore )
1104
+ }
1082
1105
_ => {
1083
1106
bcx. tcx ( ) . sess . span_bug (
1084
1107
expr. span ,
@@ -1097,6 +1120,10 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
1097
1120
let mut bcx = bcx;
1098
1121
let tcx = bcx. tcx ( ) ;
1099
1122
1123
+ if bcx. unreachable . get ( ) {
1124
+ return bcx;
1125
+ }
1126
+
1100
1127
debuginfo:: set_source_location ( bcx. fcx , expr. id , expr. span ) ;
1101
1128
1102
1129
match expr. node {
@@ -2479,13 +2506,10 @@ impl OverflowOpViaIntrinsic {
2479
2506
2480
2507
let val = Call ( bcx, llfn, & [ lhs, rhs] , None , binop_debug_loc) ;
2481
2508
let result = ExtractValue ( bcx, val, 0 ) ; // iN operation result
2482
- let overflow = ExtractValue ( bcx, val, 1 ) ; // i1 "did it overflow?"
2483
-
2484
- let cond = ICmp ( bcx, llvm:: IntEQ , overflow, C_integral ( Type :: i1 ( bcx. ccx ( ) ) , 1 , false ) ,
2485
- binop_debug_loc) ;
2509
+ let cond = ExtractValue ( bcx, val, 1 ) ; // i1 "did it overflow?"
2486
2510
2487
2511
let expect = bcx. ccx ( ) . get_intrinsic ( & "llvm.expect.i1" ) ;
2488
- Call ( bcx, expect, & [ cond, C_integral ( Type :: i1 ( bcx. ccx ( ) ) , 0 , false ) ] ,
2512
+ let cond = Call ( bcx, expect, & [ cond, C_integral ( Type :: i1 ( bcx. ccx ( ) ) , 0 , false ) ] ,
2489
2513
None , binop_debug_loc) ;
2490
2514
2491
2515
let bcx =
0 commit comments