Skip to content

Commit 61a35ff

Browse files
Merge branch 'master' into multishot-svcomp25
2 parents 46877e8 + 2dd48c1 commit 61a35ff

23 files changed

+616
-224
lines changed

.semgrep/let.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rules:
2+
- id: let-unit-in
3+
pattern: let () = $E in ...
4+
message: use ; instead (and, if needed, add surrounding parentheses to preserve precedence)
5+
languages: [ocaml]
6+
severity: WARNING

src/analyses/apron/apronAnalysis.apron.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let () =
3636
Printexc.register_printer
3737
(function
3838
| Apron.Manager.Error e ->
39-
let () = Apron.Manager.print_exclog Format.str_formatter e in
40-
Some(Printf.sprintf "Apron.Manager.Error\n %s" (Format.flush_str_formatter ()))
39+
Apron.Manager.print_exclog Format.str_formatter e;
40+
Some (Printf.sprintf "Apron.Manager.Error\n %s" (Format.flush_str_formatter ()))
4141
| _ -> None (* for other exceptions *)
4242
)

src/analyses/memOutOfBounds.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ struct
269269
| None -> ID.bot_of @@ Cilfacade.ptrdiff_ikind ()
270270
end in
271271
let e_size = get_size_of_ptr_target man e in
272-
let () = begin match e_size with
272+
begin match e_size with
273273
| `Top ->
274274
(set_mem_safety_flag InvalidDeref;
275275
M.warn "Size of lval dereference expression %a is top. Out-of-bounds memory access may occur" d_exp e)
@@ -297,7 +297,7 @@ struct
297297
(set_mem_safety_flag InvalidDeref;
298298
M.warn ~category:(Behavior behavior) ~tags:[CWE cwe_number] "Could not compare size of lval dereference expression (%a) (in bytes) with offset by (%a) (in bytes). Memory out-of-bounds access might occur" ID.pretty casted_es ID.pretty casted_offs)
299299
end
300-
end in
300+
end;
301301
begin match e with
302302
| Lval (Var v, _) as lval_exp -> check_no_binop_deref man lval_exp
303303
| BinOp (binop, e1, e2, t) when binop = PlusPI || binop = MinusPI || binop = IndexPI ->

src/analyses/varEq.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ struct
1717
struct
1818
include PartitionDomain.ExpPartitions
1919

20+
let is_str_constant = function
21+
| Const (CStr _ | CWStr _) -> true
22+
| _ -> false
23+
2024
let invariant ~scope ss =
2125
fold (fun s a ->
2226
if B.mem MyCFG.unknown_exp s then
2327
a
2428
else (
25-
let s' = B.filter (fun x -> not (InvariantCil.exp_contains_tmp x) && InvariantCil.exp_is_in_scope scope x) s in
29+
let s' = B.filter (fun x -> not (InvariantCil.exp_contains_tmp x) && InvariantCil.exp_is_in_scope scope x && not (is_str_constant x)) s in
2630
if B.cardinal s' >= 2 then (
2731
(* instead of returning quadratically many pairwise equalities from a cluster,
2832
output linear number of equalities with just one expression *)

src/arg/myARG.ml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct
156156
| n :: stack ->
157157
let cfgnode = Arg.Node.cfgnode n in
158158
match cfgnode with
159-
| Function _ -> (* TODO: can this be done without cfgnode? *)
159+
| Function cfgnode_fd -> (* TODO: can this be done without cfgnode? *)
160160
begin match stack with
161161
(* | [] -> failwith "StackArg.next: return stack empty" *)
162162
| [] -> [] (* main return *)
@@ -171,14 +171,33 @@ struct
171171
| _ -> None
172172
)
173173
in
174+
let (entry_lval, entry_args) =
175+
Arg.next call_n
176+
(* filter because infinite loops starting with function call
177+
will have another Neg(1) edge from the head *)
178+
|> List.filter_map (fun (edge, to_n) ->
179+
match edge with
180+
| InlineEntry (lval, _, args) -> Some (lval, args)
181+
| _ -> None
182+
)
183+
|> List.sort_uniq [%ord: CilType.Lval.t option * CilType.Exp.t list] (* TODO: deduplicate unique element in O(n) *)
184+
|> (function
185+
| [lval_args] -> lval_args
186+
| _ -> assert false (* all calls from a node must have same args and lval, even if called function might be different via function pointer *)
187+
)
188+
in
174189
Arg.next n
175190
|> List.filter_map (fun (edge, to_n) ->
176-
if BatList.mem_cmp Arg.Node.compare to_n call_next then (
177-
let to_n' = to_n :: call_stack in
178-
Some (edge, to_n')
179-
)
180-
else
181-
None
191+
match edge with
192+
| InlineReturn (lval, fd, args) ->
193+
assert (CilType.Fundec.equal fd cfgnode_fd); (* fd in return node should be the same as in InlineReturn edge *)
194+
if BatList.mem_cmp Arg.Node.compare to_n call_next && [%eq: CilType.Lval.t option] lval entry_lval && [%eq: CilType.Exp.t list] args entry_args then (
195+
let to_n' = to_n :: call_stack in
196+
Some (edge, to_n')
197+
)
198+
else
199+
None
200+
| _ -> assert false
182201
)
183202
end
184203
| _ ->

src/cdomain/value/domains/invariantCil.ml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,23 @@ let exp_deep_unroll_types =
2626
let visitor = new exp_deep_unroll_types_visitor in
2727
visitCilExpr visitor
2828

29+
let var_may_be_shadowed scope vi =
30+
let vi_original_name = Cilfacade.find_original_name vi in
31+
let local_may_shadow local =
32+
not (CilType.Varinfo.equal vi local) && (* exclude self-equality by vid because the original names would always equal *)
33+
vi_original_name = Cilfacade.find_original_name local
34+
in
35+
List.exists local_may_shadow scope.sformals || List.exists local_may_shadow scope.slocals
2936

3037
let var_is_in_scope scope vi =
3138
match Cilfacade.find_scope_fundec vi with
32-
| None -> vi.vstorage <> Static (* CIL pulls static locals into globals, but they aren't syntactically in global scope *)
39+
| None ->
40+
vi.vstorage <> Static && (* CIL pulls static locals into globals, but they aren't syntactically in global scope *)
41+
not (var_may_be_shadowed scope vi)
3342
| Some fd ->
34-
if CilType.Fundec.equal fd scope then
35-
GobConfig.get_bool "witness.invariant.all-locals" || (not @@ hasAttribute "goblint_cil_nested" vi.vattr)
36-
else
37-
false
43+
CilType.Fundec.equal fd scope &&
44+
(GobConfig.get_bool "witness.invariant.all-locals" || (not @@ hasAttribute "goblint_cil_nested" vi.vattr)) &&
45+
not (var_may_be_shadowed scope vi) (* TODO: could distinguish non-nested and nested? *)
3846

3947
class exp_is_in_scope_visitor (scope: fundec) (acc: bool ref) = object
4048
inherit nopCilVisitor

src/solver/sLRterm.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ module SLR3term =
4949
let count = ref 0 in
5050
let count_side = ref (max_int - 1) in
5151

52-
let () = print_solver_stats := fun () ->
52+
print_solver_stats := (fun () ->
5353
Logs.info "wpoint: %d, rho: %d, rho': %d, q: %d, count: %d, count_side: %d" (HM.length wpoint) (HM.length rho) (HPM.length rho') (H.size !q) (Int.neg !count) (max_int - !count_side);
5454
let histo = Hashtbl.create 13 in (* histogram: node id -> number of contexts *)
5555
HM.iter (fun k _ -> Hashtbl.modify_def 1 (S.Var.var_id k) ((+)1) histo) rho;
5656
let vid,n = Hashtbl.fold (fun k v (k',v') -> if v > v' then k,v else k',v') histo (Obj.magic (), 0) in
5757
Logs.info "max #contexts: %d for var_id %s" n vid
58-
in
58+
);
5959

6060
let init ?(side=false) x =
6161
if not (HM.mem rho x) then begin

src/solver/td3.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ module Base =
287287
include WPS (EqS) (HM) (VS)
288288
end in
289289

290-
let () = print_solver_stats := fun () ->
290+
print_solver_stats := (fun () ->
291291
print_data data;
292292
Logs.info "|called|=%d" (HM.length called);
293293
print_context_stats rho
294-
in
294+
);
295295

296296
if GobConfig.get_bool "incremental.load" then (
297297
print_data_verbose data "Loaded data for incremental analysis";

src/solver/td_simplified.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ module Base : GenericEqSolver =
2424
let wpoint = HM.create 10 in
2525
let stable = HM.create 10 in
2626

27-
let () = print_solver_stats := fun () ->
27+
print_solver_stats := (fun () ->
2828
Logs.debug "|rho|=%d" (HM.length rho);
2929
Logs.debug "|stable|=%d" (HM.length stable);
3030
Logs.debug "|infl|=%d" (HM.length infl);
3131
Logs.debug "|wpoint|=%d" (HM.length wpoint);
3232
Logs.info "|called|=%d" (HM.length called);
3333
print_context_stats rho
34-
in
34+
);
3535

3636
let add_infl y x =
3737
if tracing then trace "infl" "add_infl %a %a" S.Var.pretty_trace y S.Var.pretty_trace x;
@@ -122,7 +122,7 @@ module Base : GenericEqSolver =
122122
if M.tracing then M.trace "wpoint" "widen %a" S.Var.pretty_trace x;
123123
box old eqd)
124124
in
125-
if not (Timing.wrap "S.Dom.equal" (fun () -> S.Dom.equal old wpd) ()) then (
125+
if not (Timing.wrap "S.Dom.equal" (fun () -> S.Dom.equal old wpd) ()) then (
126126
(* old != wpd *)
127127
if tracing && not (S.Dom.is_bot old) then trace "update" "%a (wpx: %b): %a" S.Var.pretty_trace x (HM.mem wpoint x) S.Dom.pretty_diff (wpd, old);
128128
update_var_event x old wpd;
@@ -132,7 +132,7 @@ module Base : GenericEqSolver =
132132
(iterate[@tailcall]) x
133133
) else (
134134
(* old == wpd *)
135-
if not (HM.mem stable x) then (
135+
if not (HM.mem stable x) then (
136136
(* value unchanged, but not stable, i.e. destabilized itself during rhs *)
137137
if tracing then trace "iter" "iterate still unstable %a" S.Var.pretty_trace x;
138138
(iterate[@tailcall]) x
@@ -172,7 +172,7 @@ module Base : GenericEqSolver =
172172
);
173173
List.iter (fun x -> HM.replace called x ();
174174
if tracing then trace "multivar" "solving for %a" S.Var.pretty_trace x;
175-
iterate x;
175+
iterate x;
176176
HM.remove called x
177177
) unstable_vs;
178178
solver ();

src/solver/td_simplified_ref.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ module Base : GenericEqSolver =
2828
let solve st vs =
2929
let (data : var_data ref HM.t) = HM.create 10 in
3030

31-
let () = print_solver_stats := fun () ->
31+
print_solver_stats := (fun () ->
3232
Logs.debug "|data|=%d" (HM.length data);
33-
in
33+
);
3434

3535
let add_infl y x =
3636
if tracing then trace "infl" "add_infl %a %a" S.Var.pretty_trace y S.Var.pretty_trace x;
@@ -46,12 +46,12 @@ module Base : GenericEqSolver =
4646
begin
4747
new_var_event x;
4848
if tracing then trace "init" "init %a" S.Var.pretty_trace x;
49-
let data_x = ref {
49+
let data_x = ref {
5050
infl = VS.empty;
5151
value = S.Dom.bot ();
5252
wpoint = false;
5353
stable = false;
54-
called = false
54+
called = false
5555
} in
5656
HM.replace data x data_x;
5757
data_x
@@ -138,7 +138,7 @@ module Base : GenericEqSolver =
138138
if M.tracing then M.trace "wpoint" "widen %a" S.Var.pretty_trace x;
139139
box old eqd)
140140
in
141-
if not (Timing.wrap "S.Dom.equal" (fun () -> S.Dom.equal old wpd) ()) then (
141+
if not (Timing.wrap "S.Dom.equal" (fun () -> S.Dom.equal old wpd) ()) then (
142142
(* old != wpd *)
143143
if tracing && not (S.Dom.is_bot old) && !x_ref.wpoint then trace "solchange" "%a (wpx: %b): %a" S.Var.pretty_trace x (!x_ref.wpoint) S.Dom.pretty_diff (wpd, old);
144144
update_var_event x old wpd;
@@ -148,7 +148,7 @@ module Base : GenericEqSolver =
148148
(iterate[@tailcall]) x
149149
) else (
150150
(* old == wpd *)
151-
if not (!x_ref.stable) then (
151+
if not (!x_ref.stable) then (
152152
(* value unchanged, but not stable, i.e. destabilized itself during rhs *)
153153
if tracing then trace "iter" "iterate still unstable %a" S.Var.pretty_trace x;
154154
(iterate[@tailcall]) x
@@ -185,12 +185,12 @@ module Base : GenericEqSolver =
185185
Logs.newline ();
186186
flush_all ();
187187
);
188-
List.iter (fun x ->
188+
List.iter (fun x ->
189189
let x_ref = HM.find data x in
190190
x_ref := { !x_ref with called = true };
191191
if tracing then trace "multivar" "solving for %a" S.Var.pretty_trace x;
192-
iterate x;
193-
x_ref := { !x_ref with called = false }
192+
iterate x;
193+
x_ref := { !x_ref with called = false }
194194
) unstable_vs;
195195
solver ();
196196
)

0 commit comments

Comments
 (0)