Skip to content

Commit 3a98366

Browse files
committed
Record handler label for Itrywith in Cfgize.state.iends_with_poptrap
1 parent 82bcb4b commit 3a98366

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

backend/cfg/cfgize.ml

+15-9
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ module State : sig
3232

3333
val get_next_instruction_id : t -> int
3434

35-
val add_iend_with_poptrap : t -> Mach.instruction -> unit
35+
val add_iend_with_poptrap : t -> Mach.instruction -> Label.t -> unit
3636

3737
val is_iend_with_poptrap : t -> Mach.instruction -> bool
3838

39+
val get_iend_with_poptrap : t -> Mach.instruction -> Label.t option
40+
3941
val add_exception_handler : t -> Label.t -> unit
4042

4143
val get_exception_handlers : t -> Label.t list
@@ -48,7 +50,7 @@ end = struct
4850
layout : Cfg_with_layout.layout;
4951
catch_handlers : Label.t Numbers.Int.Tbl.t;
5052
mutable next_instruction_id : int;
51-
mutable iends_with_poptrap : Mach.instruction list;
53+
mutable iends_with_poptrap : (Mach.instruction * Label.t) list;
5254
mutable exception_handlers : Label.t list
5355
}
5456

@@ -115,13 +117,17 @@ end = struct
115117
| Itrywith _ | Iraise _ ->
116118
false
117119

118-
let add_iend_with_poptrap t iend =
120+
let add_iend_with_poptrap t iend pop_action =
119121
assert (is_iend iend);
120-
t.iends_with_poptrap <- iend :: t.iends_with_poptrap
122+
t.iends_with_poptrap <- (iend, pop_action) :: t.iends_with_poptrap
121123

122124
let is_iend_with_poptrap t iend =
123125
assert (is_iend iend);
124-
List.memq iend t.iends_with_poptrap
126+
List.mem_assq iend t.iends_with_poptrap
127+
128+
let get_iend_with_poptrap t iend =
129+
assert (is_iend iend);
130+
List.assq_opt iend t.iends_with_poptrap
125131

126132
let add_exception_handler t lbl =
127133
t.exception_handlers <- lbl :: t.exception_handlers
@@ -558,9 +564,9 @@ let rec add_blocks :
558564
else
559565
terminate_block
560566
~trap_actions:
561-
(if State.is_iend_with_poptrap state last
562-
then [Cmm.Pop Pop_generic]
563-
else [])
567+
(match State.get_iend_with_poptrap state last with
568+
| Some _lbl_handler -> [Cmm.Pop Pop_generic]
569+
| None -> [])
564570
(copy_instruction_no_reg state last ~desc:(Cfg.Always next))
565571
| Ireturn trap_actions ->
566572
terminate_block ~trap_actions
@@ -628,7 +634,7 @@ let rec add_blocks :
628634
terminate_block ~trap_actions:[]
629635
(copy_instruction_no_reg state last ~desc:(Cfg.Always label_body));
630636
let next, add_next_block = prepare_next_block () in
631-
State.add_iend_with_poptrap state (get_end body);
637+
State.add_iend_with_poptrap state (get_end body) label_handler;
632638
State.add_exception_handler state label_handler;
633639
add_blocks body state ~starts_with_pushtrap ~start:label_body ~next
634640
~is_cold;

0 commit comments

Comments
 (0)