@@ -28,19 +28,19 @@ use std::cmp;
28
28
// can happen when BB jumps directly to its successor and the successor has no
29
29
// other predecessors.
30
30
#[ derive( Debug , PartialEq ) ]
31
- enum MergingSucc {
31
+ pub ( crate ) enum MergingSucc {
32
32
False ,
33
33
True ,
34
34
}
35
35
36
36
/// Used by `FunctionCx::codegen_terminator` for emitting common patterns
37
37
/// 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 > ,
41
41
}
42
42
43
- impl < ' a , ' tcx > TerminatorCodegenHelper < ' tcx > {
43
+ impl < ' term , ' a , ' tcx > TerminatorCodegenHelper < ' term , ' tcx > {
44
44
/// Returns the appropriate `Funclet` for the current funclet, if on MSVC,
45
45
/// either already previously cached, or newly created, by `landing_pad_for`.
46
46
fn funclet < ' b , Bx : BuilderMethods < ' a , ' tcx > > (
@@ -98,6 +98,10 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
98
98
fx : & mut FunctionCx < ' a , ' tcx , Bx > ,
99
99
target : mir:: BasicBlock ,
100
100
) -> ( bool , bool ) {
101
+ if self . bb > fx. mir . basic_blocks . len ( ) . into ( ) {
102
+ return ( false , false ) ;
103
+ }
104
+
101
105
if let Some ( ref cleanup_kinds) = fx. cleanup_kinds {
102
106
let funclet_bb = cleanup_kinds[ self . bb ] . funclet_bb ( self . bb ) ;
103
107
let target_funclet = cleanup_kinds[ target] . funclet_bb ( target) ;
@@ -226,8 +230,10 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
226
230
MergingSucc :: False
227
231
} else {
228
232
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
+ }
231
237
}
232
238
233
239
if let Some ( ( ret_dest, target) ) = destination {
@@ -296,7 +302,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
296
302
/// Codegen implementations for some terminator variants.
297
303
impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
298
304
/// 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
+ ) {
300
310
if let Some ( funclet) = helper. funclet ( self ) {
301
311
bx. cleanup_ret ( funclet, None ) ;
302
312
} else {
@@ -313,7 +323,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
313
323
314
324
fn codegen_switchint_terminator (
315
325
& mut self ,
316
- helper : TerminatorCodegenHelper < ' tcx > ,
326
+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
317
327
bx : & mut Bx ,
318
328
discr : & mir:: Operand < ' tcx > ,
319
329
targets : & SwitchTargets ,
@@ -451,7 +461,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
451
461
#[ tracing:: instrument( level = "trace" , skip( self , helper, bx) ) ]
452
462
fn codegen_drop_terminator (
453
463
& mut self ,
454
- helper : TerminatorCodegenHelper < ' tcx > ,
464
+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
455
465
bx : & mut Bx ,
456
466
location : mir:: Place < ' tcx > ,
457
467
target : mir:: BasicBlock ,
@@ -569,7 +579,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
569
579
570
580
fn codegen_assert_terminator (
571
581
& mut self ,
572
- helper : TerminatorCodegenHelper < ' tcx > ,
582
+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
573
583
bx : & mut Bx ,
574
584
terminator : & mir:: Terminator < ' tcx > ,
575
585
cond : & mir:: Operand < ' tcx > ,
@@ -649,7 +659,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
649
659
650
660
fn codegen_terminate_terminator (
651
661
& mut self ,
652
- helper : TerminatorCodegenHelper < ' tcx > ,
662
+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
653
663
bx : & mut Bx ,
654
664
terminator : & mir:: Terminator < ' tcx > ,
655
665
reason : UnwindTerminateReason ,
@@ -678,7 +688,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
678
688
/// Returns `Some` if this is indeed a panic intrinsic and codegen is done.
679
689
fn codegen_panic_intrinsic (
680
690
& mut self ,
681
- helper : & TerminatorCodegenHelper < ' tcx > ,
691
+ helper : & TerminatorCodegenHelper < ' _ , ' tcx > ,
682
692
bx : & mut Bx ,
683
693
intrinsic : Option < Symbol > ,
684
694
instance : Option < Instance < ' tcx > > ,
@@ -744,9 +754,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
744
754
}
745
755
}
746
756
747
- fn codegen_call_terminator (
757
+ pub ( crate ) fn codegen_call_terminator (
748
758
& mut self ,
749
- helper : TerminatorCodegenHelper < ' tcx > ,
759
+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
750
760
bx : & mut Bx ,
751
761
terminator : & mir:: Terminator < ' tcx > ,
752
762
func : & mir:: Operand < ' tcx > ,
@@ -1068,7 +1078,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1068
1078
1069
1079
fn codegen_asm_terminator (
1070
1080
& mut self ,
1071
- helper : TerminatorCodegenHelper < ' tcx > ,
1081
+ helper : TerminatorCodegenHelper < ' _ , ' tcx > ,
1072
1082
bx : & mut Bx ,
1073
1083
terminator : & mir:: Terminator < ' tcx > ,
1074
1084
template : & [ ast:: InlineAsmTemplatePiece ] ,
0 commit comments