@@ -977,6 +977,21 @@ impl Integrator<'_, '_> {
977
977
trace ! ( "mapping block `{:?}` to `{:?}`" , block, new) ;
978
978
new
979
979
}
980
+
981
+ fn map_unwind ( & self , unwind : Option < BasicBlock > ) -> Option < BasicBlock > {
982
+ if self . in_cleanup_block {
983
+ if unwind. is_some ( ) {
984
+ bug ! ( "cleanup on cleanup block" ) ;
985
+ }
986
+ return unwind;
987
+ }
988
+
989
+ match unwind {
990
+ Some ( target) => Some ( self . map_block ( target) ) ,
991
+ // Add an unwind edge to the original call's cleanup block
992
+ None => self . cleanup_block ,
993
+ }
994
+ }
980
995
}
981
996
982
997
impl < ' tcx > MutVisitor < ' tcx > for Integrator < ' _ , ' tcx > {
@@ -1085,35 +1100,17 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
1085
1100
TerminatorKind :: Drop { ref mut target, ref mut unwind, .. }
1086
1101
| TerminatorKind :: DropAndReplace { ref mut target, ref mut unwind, .. } => {
1087
1102
* target = self . map_block ( * target) ;
1088
- if let Some ( tgt) = * unwind {
1089
- * unwind = Some ( self . map_block ( tgt) ) ;
1090
- } else if !self . in_cleanup_block {
1091
- // Unless this drop is in a cleanup block, add an unwind edge to
1092
- // the original call's cleanup block
1093
- * unwind = self . cleanup_block ;
1094
- }
1103
+ * unwind = self . map_unwind ( * unwind) ;
1095
1104
}
1096
1105
TerminatorKind :: Call { ref mut target, ref mut cleanup, .. } => {
1097
1106
if let Some ( ref mut tgt) = * target {
1098
1107
* tgt = self . map_block ( * tgt) ;
1099
1108
}
1100
- if let Some ( tgt) = * cleanup {
1101
- * cleanup = Some ( self . map_block ( tgt) ) ;
1102
- } else if !self . in_cleanup_block {
1103
- // Unless this call is in a cleanup block, add an unwind edge to
1104
- // the original call's cleanup block
1105
- * cleanup = self . cleanup_block ;
1106
- }
1109
+ * cleanup = self . map_unwind ( * cleanup) ;
1107
1110
}
1108
1111
TerminatorKind :: Assert { ref mut target, ref mut cleanup, .. } => {
1109
1112
* target = self . map_block ( * target) ;
1110
- if let Some ( tgt) = * cleanup {
1111
- * cleanup = Some ( self . map_block ( tgt) ) ;
1112
- } else if !self . in_cleanup_block {
1113
- // Unless this assert is in a cleanup block, add an unwind edge to
1114
- // the original call's cleanup block
1115
- * cleanup = self . cleanup_block ;
1116
- }
1113
+ * cleanup = self . map_unwind ( * cleanup) ;
1117
1114
}
1118
1115
TerminatorKind :: Return => {
1119
1116
terminator. kind = if let Some ( tgt) = self . callsite . target {
@@ -1141,11 +1138,8 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
1141
1138
TerminatorKind :: InlineAsm { ref mut destination, ref mut cleanup, .. } => {
1142
1139
if let Some ( ref mut tgt) = * destination {
1143
1140
* tgt = self . map_block ( * tgt) ;
1144
- } else if !self . in_cleanup_block {
1145
- // Unless this inline asm is in a cleanup block, add an unwind edge to
1146
- // the original call's cleanup block
1147
- * cleanup = self . cleanup_block ;
1148
1141
}
1142
+ * cleanup = self . map_unwind ( * cleanup) ;
1149
1143
}
1150
1144
}
1151
1145
}
0 commit comments