@@ -28,19 +28,19 @@ use std::cmp;
2828// can happen when BB jumps directly to its successor and the successor has no
2929// other predecessors.
3030#[ derive( Debug , PartialEq ) ]
31- enum MergingSucc {
31+ pub ( crate ) enum MergingSucc {
3232 False ,
3333 True ,
3434}
3535
3636/// Used by `FunctionCx::codegen_terminator` for emitting common patterns
3737/// e.g., creating a basic block, calling a function, etc.
38- struct TerminatorCodegenHelper < ' tcx > {
39- bb : mir:: BasicBlock ,
40- terminator : & ' tcx mir:: Terminator < ' tcx > ,
38+ pub ( crate ) struct TerminatorCodegenHelper < ' term , ' tcx > {
39+ pub ( crate ) bb : mir:: BasicBlock ,
40+ pub ( crate ) terminator : & ' term mir:: Terminator < ' tcx > ,
4141}
4242
43- impl < ' a , ' tcx > TerminatorCodegenHelper < ' tcx > {
43+ impl < ' term , ' a , ' tcx > TerminatorCodegenHelper < ' term , ' tcx > {
4444 /// Returns the appropriate `Funclet` for the current funclet, if on MSVC,
4545 /// either already previously cached, or newly created, by `landing_pad_for`.
4646 fn funclet < ' b , Bx : BuilderMethods < ' a , ' tcx > > (
@@ -98,6 +98,10 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
9898 fx : & mut FunctionCx < ' a , ' tcx , Bx > ,
9999 target : mir:: BasicBlock ,
100100 ) -> ( bool , bool ) {
101+ if self . bb > fx. mir . basic_blocks . len ( ) . into ( ) {
102+ return ( false , false ) ;
103+ }
104+
101105 if let Some ( ref cleanup_kinds) = fx. cleanup_kinds {
102106 let funclet_bb = cleanup_kinds[ self . bb ] . funclet_bb ( self . bb ) ;
103107 let target_funclet = cleanup_kinds[ target] . funclet_bb ( target) ;
@@ -226,8 +230,10 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
226230 MergingSucc :: False
227231 } else {
228232 let llret = bx. call ( fn_ty, fn_attrs, Some ( fn_abi) , fn_ptr, llargs, self . funclet ( fx) ) ;
229- if fx. mir [ self . bb ] . is_cleanup {
230- bx. apply_attrs_to_cleanup_callsite ( llret) ;
233+ if let Some ( bb) = fx. mir . basic_blocks . get ( self . bb ) {
234+ if bb. is_cleanup {
235+ bx. apply_attrs_to_cleanup_callsite ( llret) ;
236+ }
231237 }
232238
233239 if let Some ( ( ret_dest, target) ) = destination {
@@ -296,7 +302,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
296302/// Codegen implementations for some terminator variants.
297303impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
298304 /// Generates code for a `Resume` terminator.
299- fn codegen_resume_terminator ( & mut self , helper : TerminatorCodegenHelper < ' tcx > , bx : & mut Bx ) {
305+ fn codegen_resume_terminator (
306+ & mut self ,
307+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
308+ bx : & mut Bx ,
309+ ) {
300310 if let Some ( funclet) = helper. funclet ( self ) {
301311 bx. cleanup_ret ( funclet, None ) ;
302312 } else {
@@ -313,7 +323,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
313323
314324 fn codegen_switchint_terminator (
315325 & mut self ,
316- helper : TerminatorCodegenHelper < ' tcx > ,
326+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
317327 bx : & mut Bx ,
318328 discr : & mir:: Operand < ' tcx > ,
319329 targets : & SwitchTargets ,
@@ -451,7 +461,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
451461 #[ tracing:: instrument( level = "trace" , skip( self , helper, bx) ) ]
452462 fn codegen_drop_terminator (
453463 & mut self ,
454- helper : TerminatorCodegenHelper < ' tcx > ,
464+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
455465 bx : & mut Bx ,
456466 location : mir:: Place < ' tcx > ,
457467 target : mir:: BasicBlock ,
@@ -569,7 +579,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
569579
570580 fn codegen_assert_terminator (
571581 & mut self ,
572- helper : TerminatorCodegenHelper < ' tcx > ,
582+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
573583 bx : & mut Bx ,
574584 terminator : & mir:: Terminator < ' tcx > ,
575585 cond : & mir:: Operand < ' tcx > ,
@@ -649,7 +659,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
649659
650660 fn codegen_terminate_terminator (
651661 & mut self ,
652- helper : TerminatorCodegenHelper < ' tcx > ,
662+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
653663 bx : & mut Bx ,
654664 terminator : & mir:: Terminator < ' tcx > ,
655665 reason : UnwindTerminateReason ,
@@ -678,7 +688,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
678688 /// Returns `Some` if this is indeed a panic intrinsic and codegen is done.
679689 fn codegen_panic_intrinsic (
680690 & mut self ,
681- helper : & TerminatorCodegenHelper < ' tcx > ,
691+ helper : & TerminatorCodegenHelper < ' _ , ' tcx > ,
682692 bx : & mut Bx ,
683693 intrinsic : Option < Symbol > ,
684694 instance : Option < Instance < ' tcx > > ,
@@ -744,9 +754,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
744754 }
745755 }
746756
747- fn codegen_call_terminator (
757+ pub ( crate ) fn codegen_call_terminator (
748758 & mut self ,
749- helper : TerminatorCodegenHelper < ' tcx > ,
759+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
750760 bx : & mut Bx ,
751761 terminator : & mir:: Terminator < ' tcx > ,
752762 func : & mir:: Operand < ' tcx > ,
@@ -1068,7 +1078,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10681078
10691079 fn codegen_asm_terminator (
10701080 & mut self ,
1071- helper : TerminatorCodegenHelper < ' tcx > ,
1081+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
10721082 bx : & mut Bx ,
10731083 terminator : & mir:: Terminator < ' tcx > ,
10741084 template : & [ ast:: InlineAsmTemplatePiece ] ,
0 commit comments