@@ -465,17 +465,15 @@ struct
465
465
466
466
(* Give the set of reachables from argument. *)
467
467
let reachables (ask : Queries.ask ) es =
468
- let reachable e st =
469
- match st with
470
- | None -> None
471
- | Some st ->
468
+ let reachable acc e =
469
+ Option. bind acc (fun st ->
472
470
let ad = ask.f (Queries. ReachableFrom e) in
473
471
if Queries.AD. is_top ad then
474
472
None
475
473
else
476
- Some (Queries.AD. join ad st)
474
+ Some (Queries.AD. join ad st))
477
475
in
478
- List. fold_right reachable es (Some (Queries.AD. empty () ))
476
+ List. fold_left reachable (Some (Queries.AD. empty () )) es
479
477
480
478
481
479
let forget_reachable man st es =
@@ -484,9 +482,8 @@ struct
484
482
match reachables ask es with
485
483
| None ->
486
484
(* top reachable, so try to invalidate everything *)
487
- RD. vars st.rel
488
- |> List. filter_map RV. to_cil_varinfo
489
- |> List. map Cil. var
485
+ let to_cil_lval x = Option. map Cil. var @@ RV. to_cil_varinfo x in
486
+ RD. vars st.rel |> List. filter_map to_cil_lval
490
487
| Some ad ->
491
488
let to_cil addr rs =
492
489
match addr with
@@ -521,14 +518,10 @@ struct
521
518
match desc.special args, f.vname with
522
519
| Assert { exp; refine; _ } , _ -> assert_fn man exp refine
523
520
| ThreadJoin { thread = id ; ret_var = retvar } , _ ->
524
- (
525
- (* Forget value that thread return is assigned to *)
526
- let st' = forget_reachable man st [retvar] in
527
- let st' = Priv. thread_join ask man.global id st' in
528
- match r with
529
- | Some lv -> invalidate_one ask man st' lv
530
- | None -> st'
531
- )
521
+ (* Forget value that thread return is assigned to *)
522
+ let st' = forget_reachable man st [retvar] in
523
+ let st' = Priv. thread_join ask man.global id st' in
524
+ Option. map_default (invalidate_one ask man st') st' r
532
525
| ThreadExit _ , _ ->
533
526
begin match ThreadId. get_current ask with
534
527
| `Lifted tid ->
@@ -543,11 +536,10 @@ struct
543
536
let id = List. hd args in
544
537
Priv. thread_join ~force: true ask man.global id st
545
538
| Rand , _ ->
546
- (match r with
547
- | Some lv ->
539
+ Option. map_default (fun lv ->
548
540
let st = invalidate_one ask man st lv in
549
541
assert_fn {man with local = st} (BinOp (Ge , Lval lv, zero, intType)) true
550
- | None -> st)
542
+ ) st r
551
543
| _ , _ ->
552
544
let lvallist e =
553
545
match ask.f (Queries. MayPointTo e) with
@@ -575,10 +567,7 @@ struct
575
567
let shallow_lvals = List. concat_map lvallist shallow_addrs in
576
568
let st' = List. fold_left (invalidate_one ask man) st' shallow_lvals in
577
569
(* invalidate lval if present *)
578
- match r with
579
- | Some lv -> invalidate_one ask man st' lv
580
- | None -> st'
581
-
570
+ Option. map_default (invalidate_one ask man st') st' r
582
571
583
572
let query_invariant man context =
584
573
let keep_local = GobConfig. get_bool " ana.relation.invariant.local" in
0 commit comments