Skip to content

Commit bef86e2

Browse files
committed
Refactor old partition_if_next to check for more errors
1 parent 6d6c124 commit bef86e2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/arg/myARG.ml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,21 @@ let partition_if_next (if_next_n : (edge * node * cfg_path list) list): exp * (n
313313
in
314314
(exp, collapse_branch true, collapse_branch false)
315315

316-
let partition_if_next if_next_n =
317-
(* TODO: refactor, check extra edges for error *)
318-
let test_next b = List.find (function
319-
| (Test (_, b'), _, _) when b = b' -> true
320-
| (_, _, _) -> false
321-
) if_next_n
316+
let partition_if_next if_next =
317+
let (if_next_trues, if_next_falses) = List.partition (function
318+
| (Test (_, b), _, _) -> b
319+
| (_, _, _) -> failwith "partition_if_next: not Test edge"
320+
) if_next
322321
in
323-
assert (List.length if_next_n <= 2);
324-
match test_next true, test_next false with
325-
| (Test (e_true, true), if_true_next_n, if_true_next_p), (Test (e_false, false), if_false_next_n, if_false_next_p) when Basetype.CilExp.equal e_true e_false ->
326-
(e_true, (if_true_next_n, if_true_next_p), (if_false_next_n, if_false_next_p))
327-
| _, _ -> failwith "partition_if_next: bad branches"
322+
match if_next_trues, if_next_falses with
323+
| [(Test (e_true, true), if_true_next_n, if_true_next_ps)], [(Test (e_false, false), if_false_next_n, if_false_next_ps)] when Basetype.CilExp.equal e_true e_false ->
324+
(e_true, (if_true_next_n, if_true_next_ps), (if_false_next_n, if_false_next_ps))
325+
| _, _ ->
326+
(* This fails due to any of the following:
327+
- Either true or false branch is missing.
328+
- Either true or false branch has multiple different exps or nodes (same exp, branch and node should only occur once by construction/assumption).
329+
- True and false branch have different exps. *)
330+
failwith "partition_if_next: bad branches"
328331

329332
module UnCilLogicIntra (Arg: SIntraOpt): SIntraOpt =
330333
struct

0 commit comments

Comments
 (0)