Skip to content

Commit 187672e

Browse files
committed
Clean up LoopTermination.special
1 parent da7cb07 commit 187672e

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/analyses/loopTermination.ml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,33 @@ struct
4242
let startstate _ = ()
4343
let exitstate = startstate
4444

45-
let find_loop ~loop_counter =
46-
VarToStmt.find loop_counter !loop_counters
47-
4845
(** Recognizes a call of [__goblint_bounded] to check the EvalInt of the
4946
* respective loop counter variable at that position. *)
5047
let special ctx (lval : lval option) (f : varinfo) (arglist : exp list) =
51-
if !AnalysisState.postsolving then
48+
if !AnalysisState.postsolving then (
5249
match f.vname, arglist with
53-
"__goblint_bounded", [Lval (Var loop_counter, NoOffset)] ->
54-
(try
55-
let loop_statement = find_loop ~loop_counter in
56-
let bound = ask_bound ctx loop_counter in
57-
let is_bounded = bound <> `Top in
58-
ctx.sideg () (G.add (`Lifted loop_statement) is_bounded (ctx.global ()));
59-
let loc = M.Location.CilLocation (Cilfacade.get_stmtLoc loop_statement) in
60-
begin match bound with
61-
| `Top ->
62-
M.warn ~category:Termination ~loc "The program might not terminate! (Loop analysis)"
63-
| `Lifted bound ->
64-
(* TODO: aggregate these per loop (if unrolled) and warn using WarnGlobal? *)
65-
if GobConfig.get_bool "dbg.termination-bounds" then
66-
M.success ~category:Termination ~loc "Loop terminates: bounded by %a iteration(s)" IntDomain.IntDomTuple.pretty bound;
67-
end
68-
with Not_found ->
69-
failwith "Encountered a call to __goblint_bounded with an unknown loop counter variable.")
50+
| "__goblint_bounded", [Lval (Var loop_counter, NoOffset)] ->
51+
begin match VarToStmt.find_opt loop_counter !loop_counters with
52+
| Some loop_statement ->
53+
let bound = ask_bound ctx loop_counter in
54+
let is_bounded = bound <> `Top in
55+
ctx.sideg () (G.add (`Lifted loop_statement) is_bounded (ctx.global ()));
56+
let loc = M.Location.CilLocation (Cilfacade.get_stmtLoc loop_statement) in
57+
begin match bound with
58+
| `Top ->
59+
M.warn ~category:Termination ~loc "The program might not terminate! (Loop analysis)"
60+
| `Lifted bound ->
61+
(* TODO: aggregate these per loop (if unrolled) and warn using WarnGlobal? *)
62+
if GobConfig.get_bool "dbg.termination-bounds" then
63+
M.success ~category:Termination ~loc "Loop terminates: bounded by %a iteration(s)" IntDomain.IntDomTuple.pretty bound;
64+
end
65+
| None ->
66+
failwith "Encountered a call to __goblint_bounded with an unknown loop counter variable."
67+
end
68+
| "__goblint_bounded", _ ->
69+
failwith "__goblint_bounded call unexpected arguments"
7070
| _ -> ()
71-
else ()
71+
)
7272

7373
let query ctx (type a) (q: a Queries.t): a Queries.result =
7474
match q with

0 commit comments

Comments
 (0)