66
77 Copyright (c) 2005-2019 Kestrel Technology LLC
88 Copyright (c) 2020-2022 Henny Sipma
9- Copyright (c) 2023 Aarno Labs LLC
9+ Copyright (c) 2023-2024 Aarno Labs LLC
1010
1111 Permission is hereby granted, free of charge, to any person obtaining a copy
1212 of this software and associated documentation files (the "Software"), to deal
2929
3030(* chlib *)
3131open CHNumerical
32- open CHPretty
3332
3433(* chutil *)
3534open CHPrettyUtil
36- open CHUtil
3735
3836(* xprlib *)
3937open Xprt
@@ -45,7 +43,6 @@ open Xsimplify
4543open CCHBasicTypes
4644open CCHLibTypes
4745open CCHTypesToPretty
48- open CCHTypesUtil
4946
5047(* cchpre *)
5148open CCHPOPredicate
@@ -70,19 +67,20 @@ object (self)
7067
7168 method private mk_predicate a = PIndexLowerBound a
7269
73- method mk_safe_constraint x = XOp (XGe , [ x ; zero_constant_expr ])
70+ method mk_safe_constraint x = XOp (XGe , [x ; zero_constant_expr])
7471
75- method mk_violation_constraint x = XOp (XLt , [ x ; zero_constant_expr ])
72+ method mk_violation_constraint x = XOp (XLt , [x ; zero_constant_expr])
7673
7774 (* ----------------------------- safe ------------------------------------- *)
7875 method private global_implies_safe invindex g =
7976 let pred = self#mk_predicate g in
8077 match poq#check_implied_by_assumptions pred with
8178 | Some pred ->
82- let deps = DEnvC ([ invindex ],[ GlobalApiAssumption pred ]) in
83- let msg = " index lower bound implied by global assumption: "
84- ^ (p2s (po_predicate_to_pretty pred)) in
85- Some (deps,msg)
79+ let deps = DEnvC ([invindex], [GlobalApiAssumption pred]) in
80+ let msg =
81+ " index lower bound implied by global assumption: "
82+ ^ (p2s (po_predicate_to_pretty pred)) in
83+ Some (deps, msg)
8684 | _ ->
8785 let xpred = po_predicate_to_xpredicate poq#fenv pred in
8886 begin
@@ -98,7 +96,7 @@ object (self)
9896 let r =
9997 match epcs with
10098 | [] ->
101- List. fold_left (fun acc (pc ,_ ) ->
99+ List. fold_left (fun acc (pc , _ ) ->
102100 match acc with
103101 | Some _ -> acc
104102 | _ ->
@@ -131,13 +129,13 @@ object (self)
131129 let deps = DLocal [invindex] in
132130 let msg =
133131 " index: " ^ (x2s x) ^ " satisfies constraint: " ^ (x2s xconstraint) in
134- Some (deps,msg)
132+ Some (deps, msg)
135133 else if poq#is_global_expression x then
136134 match self#global_implies_safe invindex (poq#get_global_expression x) with
137135 | Some r -> Some r
138136 | _ ->
139137 begin
140- poq#set_diagnostic (" remaining constraint: " ^ (x2s sconstraint)) ;
138+ poq#set_diagnostic (" remaining constraint: " ^ (x2s sconstraint));
141139 None
142140 end
143141 else
@@ -153,12 +151,16 @@ object (self)
153151
154152 method check_safe =
155153 match invs with
156- | [] -> false
154+ | [] ->
155+ begin
156+ poq#set_diagnostic (" no invariants for " ^ (e2s e));
157+ false ;
158+ end
157159 | _ ->
158160 List. fold_left (fun acc inv ->
159161 acc ||
160162 match self#inv_implies_safe inv with
161- | Some (deps ,msg ) ->
163+ | Some (deps , msg ) ->
162164 begin
163165 poq#record_safe_result deps msg;
164166 true
@@ -174,7 +176,7 @@ object (self)
174176 match poq#get_witness vconstraint v with
175177 | Some violationvalue ->
176178 let (s, callee, pc) = poq#get_tainted_value_origin v in
177- let deps = DEnvC ([ invindex ],[ PostAssumption (callee.vid,pc) ]) in
179+ let deps = DEnvC ([invindex],[PostAssumption (callee.vid,pc)]) in
178180 let msg =
179181 s
180182 ^ " choose value: "
@@ -190,12 +192,12 @@ object (self)
190192 | XConst (IntConst n ) when n#lt numerical_zero ->
191193 let deps = DLocal [invindex] in
192194 let msg = " upper bound on index value is negative: " ^ n#toString in
193- Some (deps,msg)
195+ Some (deps, msg)
194196 | XVar v ->
195197 self#var_implies_violation invindex v zero_constant_expr
196- | XOp (XPlus, [ XVar v ; xincr ]) ->
198+ | XOp (XPlus, [XVar v ; xincr ]) ->
197199 self#var_implies_violation invindex v xincr
198- | XOp (XMinus, [ XVar v ; xdecr ]) ->
200+ | XOp (XMinus, [XVar v ; xdecr ]) ->
199201 let xincr = simplify_xpr (XOp (XMinus , [zero_constant_expr; xdecr])) in
200202 self#var_implies_violation invindex v xincr
201203 | _ -> None
@@ -221,7 +223,7 @@ object (self)
221223 List. fold_left (fun acc x ->
222224 match acc with
223225 | None -> None
224- | Some (deps ,msg ) ->
226+ | Some (deps , msg ) ->
225227 match self#xpr_implies_violation inv#index x with
226228 | Some (d , m ) ->
227229 let deps = join_dependencies deps d in
@@ -245,7 +247,7 @@ object (self)
245247 | Some (d , m ) ->
246248 let deps = join_dependencies deps d in
247249 let msg = msg ^ " ; " ^ m in
248- Some (deps,msg)
250+ Some (deps, msg)
249251 | _ -> None ) (Some r) tl
250252 | _ -> None
251253 end
@@ -264,9 +266,9 @@ object (self)
264266 List. fold_left (fun acc inv ->
265267 acc ||
266268 match self#inv_implies_violation inv with
267- | Some (deps ,msg ) ->
269+ | Some (deps , msg ) ->
268270 begin
269- poq#record_violation_result deps msg ;
271+ poq#record_violation_result deps msg;
270272 true
271273 end
272274 | _ -> false ) false invs
@@ -281,13 +283,13 @@ object (self)
281283 " condition "
282284 ^ (p2s (po_predicate_to_pretty pred))
283285 ^ " delegated to the api" in
284- Some (deps,msg)
286+ Some (deps, msg)
285287 else
286288 None
287289
288290 method private inv_implies_delegation inv =
289291 match inv#lower_bound_xpr with
290- | Some x -> self#xpr_implies_delegation inv#index x
292+ | Some x -> self#xpr_implies_delegation inv#index x
291293 | _ -> None
292294
293295 method check_delegation =
@@ -297,7 +299,7 @@ object (self)
297299 List. fold_left (fun acc inv ->
298300 acc ||
299301 match self#inv_implies_delegation inv with
300- | Some (deps ,msg ) ->
302+ | Some (deps , msg ) ->
301303 begin
302304 poq#record_safe_result deps msg;
303305 true
0 commit comments