Skip to content

Commit f931125

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 5ba152c + 39d0a8a commit f931125

File tree

21 files changed

+251
-84
lines changed

21 files changed

+251
-84
lines changed

.semgrep/fold.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
rules:
2+
- id: fold-exists
3+
patterns:
4+
- pattern-either:
5+
- pattern: $D.fold ... false
6+
- pattern: $D.fold_left ... false
7+
- pattern: $D.fold_right ... false
8+
- pattern: fold ... false
9+
- pattern: fold_left ... false
10+
- pattern: fold_right ... false
11+
message: consider replacing fold with exists
12+
languages: [ocaml]
13+
severity: WARNING
14+
15+
- id: fold-for_all
16+
patterns:
17+
- pattern-either:
18+
- pattern: $D.fold ... true
19+
- pattern: $D.fold_left ... true
20+
- pattern: $D.fold_right ... true
21+
- pattern: fold ... true
22+
- pattern: fold_left ... true
23+
- pattern: fold_right ... true
24+
message: consider replacing fold with for_all
25+
languages: [ocaml]
26+
severity: WARNING

.semgrep/tracing.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ rules:
88
- pattern: Messages.tracec
99
- pattern: Messages.traceu
1010
- pattern: Messages.traceli
11+
- pattern: M.trace
12+
- pattern: M.tracel
13+
- pattern: M.tracei
14+
- pattern: M.tracec
15+
- pattern: M.traceu
16+
- pattern: M.traceli
1117
- pattern-not-inside: if Messages.tracing then ...
1218
- pattern-not-inside: if Messages.tracing && ... then ...
19+
- pattern-not-inside: if M.tracing then ...
20+
- pattern-not-inside: if M.tracing && ... then ...
1321
message: trace functions should only be called if tracing is enabled at compile time
1422
languages: [ocaml]
1523
severity: WARNING

src/analyses/base.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,11 +2172,7 @@ struct
21722172
in
21732173
List.filter_map (create_thread ~multiple (Some (Mem id, NoOffset)) (Some ptc_arg)) start_funvars_with_unknown
21742174
end
2175-
| _, _ when get_bool "sem.unknown_function.spawn" ->
2176-
(* TODO: Remove sem.unknown_function.spawn check because it is (and should be) really done in LibraryFunctions.
2177-
But here we consider all non-ThreadCreate functions also unknown, so old-style LibraryFunctions access
2178-
definitions using `Write would still spawn because they are not truly unknown functions (missing from LibraryFunctions).
2179-
Need this to not have memmove spawn in SV-COMP. *)
2175+
| _, _ ->
21802176
let shallow_args = LibraryDesc.Accesses.find desc.accs { kind = Spawn; deep = false } args in
21812177
let deep_args = LibraryDesc.Accesses.find desc.accs { kind = Spawn; deep = true } args in
21822178
let shallow_flist = collect_invalidate ~deep:false ~ctx ctx.local shallow_args in
@@ -2185,7 +2181,6 @@ struct
21852181
let addrs = List.concat_map AD.to_var_may flist in
21862182
if addrs <> [] then M.debug ~category:Analyzer "Spawning non-unique functions from unknown function: %a" (d_list ", " CilType.Varinfo.pretty) addrs;
21872183
List.filter_map (create_thread ~multiple:true None None) addrs
2188-
| _, _ -> []
21892184

21902185
let assert_fn ctx e refine =
21912186
(* make the state meet the assertion in the rest of the code *)
@@ -2656,6 +2651,15 @@ struct
26562651
| Unknown, "__goblint_assume_join" ->
26572652
let id = List.hd args in
26582653
Priv.thread_join ~force:true (Analyses.ask_of_ctx ctx) (priv_getg ctx.global) id st
2654+
| ThreadSelf, _ ->
2655+
begin match lv, ThreadId.get_current (Analyses.ask_of_ctx ctx) with
2656+
| Some lv, `Lifted tid ->
2657+
set ~ctx st (eval_lv ~ctx st lv) (Cilfacade.typeOfLval lv) (Thread (ValueDomain.Threads.singleton tid))
2658+
| Some lv, _ ->
2659+
invalidate_ret_lv st
2660+
| None, _ ->
2661+
st
2662+
end
26592663
| Alloca size, _ -> begin
26602664
match lv with
26612665
| Some lv ->

src/analyses/basePriv.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,11 @@ struct
10401040
let s = MustLockset.remove m (current_lockset ask) in
10411041
let t = current_thread ask in
10421042
let side_cpa = CPA.filter (fun x _ ->
1043-
GWeak.fold (fun s' tm acc ->
1043+
GWeak.exists (fun s' tm ->
10441044
(* TODO: swap 2^M and T partitioning for lookup by t here first? *)
10451045
let v = ThreadMap.find t tm in
1046-
(MustLockset.mem m s' && not (VD.is_bot v)) || acc
1047-
) (G.weak (getg (V.global x))) false
1046+
(MustLockset.mem m s' && not (VD.is_bot v))
1047+
) (G.weak (getg (V.global x)))
10481048
) st.cpa
10491049
in
10501050
sideg (V.mutex m) (G.create_sync (GSync.singleton s side_cpa));
@@ -1098,9 +1098,9 @@ struct
10981098
let unlock ask getg sideg (st: BaseComponents (D).t) m =
10991099
let s = MustLockset.remove m (current_lockset ask) in
11001100
let side_cpa = CPA.filter (fun x _ ->
1101-
GWeak.fold (fun s' v acc ->
1102-
(MustLockset.mem m s' && not (VD.is_bot v)) || acc
1103-
) (G.weak (getg (V.global x))) false
1101+
GWeak.exists (fun s' v ->
1102+
(MustLockset.mem m s' && not (VD.is_bot v))
1103+
) (G.weak (getg (V.global x)))
11041104
) st.cpa
11051105
in
11061106
sideg (V.mutex m) (G.create_sync (GSync.singleton s side_cpa));

src/autoTune.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ let hasFunction pred =
157157
Goblint_backtrace.wrap_val ~mark:(Cilfacade.FunVarinfo var) @@ fun () ->
158158
if LibraryFunctions.is_special var then
159159
let desc = LibraryFunctions.find var in
160-
GobOption.exists (fun args -> pred (desc.special args)) (functionArgs var)
160+
GobOption.exists (fun args -> pred desc args) (functionArgs var)
161161
else
162162
false
163163
in
@@ -169,7 +169,7 @@ let hasFunction pred =
169169
match unrollType var.vtype with
170170
| TFun (_, args, _, _) ->
171171
let args = BatOption.map_default (List.map (fun (x,_,_) -> MyCFG.unknown_exp)) [] args in
172-
pred (desc.special args)
172+
pred desc args
173173
| _ -> false
174174
else
175175
false
@@ -191,9 +191,10 @@ let enableAnalyses anas =
191191

192192
let notNeccessaryThreadAnalyses = ["race"; "deadlock"; "maylocks"; "symb_locks"; "thread"; "threadid"; "threadJoins"; "threadreturn"; "mhp"; "region"; "pthreadMutexType"]
193193
let reduceThreadAnalyses () =
194-
let isThreadCreate = function
194+
let isThreadCreate (desc: LibraryDesc.t) args =
195+
match desc.special args with
195196
| LibraryDesc.ThreadCreate _ -> true
196-
| _ -> false
197+
| _ -> LibraryDesc.Accesses.find_kind desc.accs Spawn args <> []
197198
in
198199
let hasThreadCreate = hasFunction isThreadCreate in
199200
if not @@ hasThreadCreate then (
@@ -446,7 +447,8 @@ let wideningOption factors file =
446447
}
447448

448449
let activateTmpSpecialAnalysis () =
449-
let isMathFun = function
450+
let isMathFun (desc: LibraryDesc.t) args =
451+
match desc.special args with
450452
| LibraryDesc.Math _ -> true
451453
| _ -> false
452454
in

src/cdomain/value/cdomains/stringDomain.ml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ let reset_lazy () =
2020

2121

2222
type t = string option [@@deriving eq, ord, hash]
23+
(** [None] means top. *)
2324

2425
let hash x =
25-
if get_string_domain () = Disjoint then
26-
hash x
27-
else
28-
13859
26+
match get_string_domain () with
27+
| Disjoint | Flat -> hash x
28+
| Unit -> 13859
2929

3030
let show = function
3131
| Some x -> "\"" ^ x ^ "\""
@@ -39,10 +39,9 @@ include Printable.SimpleShow (
3939
)
4040

4141
let of_string x =
42-
if get_string_domain () = Unit then
43-
None
44-
else
45-
Some x
42+
match get_string_domain () with
43+
| Unit -> None
44+
| Disjoint | Flat -> Some x
4645
let to_string x = x
4746

4847
(* only keep part before first null byte *)
@@ -91,24 +90,25 @@ let join x y =
9190
| _, None -> None
9291
| Some a, Some b when a = b -> Some a
9392
| Some a, Some b (* when a <> b *) ->
94-
if get_string_domain () = Disjoint then
95-
raise Lattice.Uncomparable
96-
else
97-
None
93+
match get_string_domain () with
94+
| Disjoint -> raise Lattice.Uncomparable
95+
| Flat -> None
96+
| Unit -> assert false
9897

9998
let meet x y =
10099
match x, y with
101100
| None, a
102101
| a, None -> a
103102
| Some a, Some b when a = b -> Some a
104103
| Some a, Some b (* when a <> b *) ->
105-
if get_string_domain () = Disjoint then
106-
raise Lattice.Uncomparable
107-
else
108-
raise Lattice.BotValue
104+
match get_string_domain () with
105+
| Disjoint -> raise Lattice.Uncomparable
106+
| Flat -> raise Lattice.BotValue
107+
| Unit -> assert false
109108

110109
let repr x =
111-
if get_string_domain () = Disjoint then
110+
match get_string_domain () with
111+
| Disjoint ->
112112
x (* everything else is kept separate, including strings if not limited *)
113-
else
113+
| Flat | Unit ->
114114
None (* all strings together if limited *)

src/cdomain/value/cdomains/threadIdDomain.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ struct
8383
(v, None)
8484

8585
let is_main = function
86-
| ({vname; _}, None) -> List.mem vname @@ GobConfig.get_string_list "mainfun"
86+
| ({vname; _}, None) -> GobConfig.get_bool "ana.thread.include-node" && List.mem vname @@ GobConfig.get_string_list "mainfun"
8787
| _ -> false
8888

89-
let is_unique _ = false (* TODO: should this consider main unique? *)
89+
let is_unique = is_main
9090
let may_create _ _ = true
9191
let is_must_parent _ _ = false
9292
end

src/config/options.schema.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,19 @@
15441544
}
15451545
},
15461546
"additionalProperties": false
1547+
},
1548+
"atexit": {
1549+
"title": "sem.atexit",
1550+
"type": "object",
1551+
"properties": {
1552+
"ignore": {
1553+
"title": "sem.atexit.ignore",
1554+
"description": "Ignore atexit callbacks (unsound).",
1555+
"type": "boolean",
1556+
"default": false
1557+
}
1558+
},
1559+
"additionalProperties": false
15471560
}
15481561
},
15491562
"additionalProperties": false

src/domain/partitionDomain.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ struct
3131
let meet _ _ = failwith "PartitonDomain.Set.meet: unsound"
3232

3333
let collapse (s1:t) (s2:t): bool =
34-
let f vf2 res =
35-
res || exists (fun vf1 -> S.collapse vf1 vf2) s1
34+
let f vf2 =
35+
exists (fun vf1 -> S.collapse vf1 vf2) s1
3636
in
37-
fold f s2 false
37+
exists f s2
3838

3939
let add e s = join s (singleton e)
4040

src/incremental/compareCFG.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ let reexamine f1 f2 (same : biDirectionNodeMap) (diffNodes1 : unit NH.t) (module
131131
false
132132
end in
133133
let cond n2 = Node.equal n2 (FunctionEntry f2) || check_all_nodes_in_same (List.map snd (CfgNew.prev n2)) n2 in
134-
let forall = NH.fold (fun n2 n1 acc -> acc && cond n2) same.node2to1 true in
134+
let forall = NH.fold (fun n2 n1 acc -> acc && cond n2) same.node2to1 true in (* nosemgrep: fold-for_all *) (* cond does side effects *)
135135
if not forall then repeat () in
136136
repeat ();
137137
NH.to_seq same.node1to2, NH.to_seq_keys diffNodes1

0 commit comments

Comments
 (0)