Skip to content

Commit d21a2f3

Browse files
authored
Merge pull request #745 from goblint/yaml-witness-validate
Add YAML witness validation by invariant checking
2 parents ea01109 + 8b2cccf commit d21a2f3

File tree

21 files changed

+487
-135
lines changed

21 files changed

+487
-135
lines changed

goblint.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dev-repo: "git+https://github.com/goblint/analyzer.git"
6868
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
6969
# also remember to generate/adjust goblint.opam.locked!
7070
pin-depends: [
71-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#56f5f9ad58e71908ff66e179e056a22ea71693a2" ]
71+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#0a37478e08b9ae10587b0355ad2805dfeca1cca9" ]
7272
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
7373
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
7474
# quoter workaround reverted for release, so no pin needed

goblint.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ version: "dev"
124124
pin-depends: [
125125
[
126126
"goblint-cil.1.8.2"
127-
"git+https://github.com/goblint/cil.git#56f5f9ad58e71908ff66e179e056a22ea71693a2"
127+
"git+https://github.com/goblint/cil.git#0a37478e08b9ae10587b0355ad2805dfeca1cca9"
128128
]
129129
[
130130
"apron.v0.9.13"

goblint.opam.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
22
# also remember to generate/adjust goblint.opam.locked!
33
pin-depends: [
4-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#56f5f9ad58e71908ff66e179e056a22ea71693a2" ]
4+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#0a37478e08b9ae10587b0355ad2805dfeca1cca9" ]
55
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
66
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
77
# quoter workaround reverted for release, so no pin needed

src/analyses/base.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ struct
697697
let x = Pretty.sprint ~width:80 (d_const () c) in (* escapes, see impl. of d_const in cil.ml *)
698698
let x = String.sub x 2 (String.length x - 3) in (* remove surrounding quotes: L"foo" -> foo *)
699699
`Address (AD.from_string x) (* `Address (AD.str_ptr ()) *)
700+
| Const _ -> VD.top ()
700701
(* Variables and address expressions *)
701702
| Lval (Var v, ofs) -> do_offs (get a gs st (eval_lv a gs st (Var v, ofs)) (Some exp)) ofs
702703
(*| Lval (Mem e, ofs) -> do_offs (get a gs st (eval_lv a gs st (Mem e, ofs))) ofs*)
@@ -794,7 +795,16 @@ struct
794795
| CastE (t, exp) ->
795796
let v = eval_rv a gs st exp in
796797
VD.cast ~torg:(Cilfacade.typeOf exp) t v
797-
| _ -> VD.top ()
798+
| SizeOf _
799+
| Real _
800+
| Imag _
801+
| SizeOfE _
802+
| SizeOfStr _
803+
| AlignOf _
804+
| AlignOfE _
805+
| Question _
806+
| AddrOfLabel _ ->
807+
VD.top ()
798808
in
799809
if M.tracing then M.traceu "evalint" "base eval_rv_base %a -> %a\n" d_exp exp VD.pretty r;
800810
r

src/analyses/malloc_null.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ struct
6565
| _ -> ()
6666
in
6767
match e with
68-
| Lval (Var v, offs) -> ()
68+
| Const _
69+
| SizeOf _
70+
| SizeOfStr _
71+
| AlignOf _
72+
| AddrOfLabel _
73+
| Lval (Var _, _) -> ()
6974
| AddrOf (Var _, _)
7075
| StartOf (Var _, _) -> warn_lval_mem e NoOffset
7176
| AddrOf (Mem e, offs)
@@ -77,9 +82,16 @@ struct
7782
warn_deref_exp a st e1;
7883
warn_deref_exp a st e2
7984
| UnOp (_,e,_)
85+
| Real e
86+
| Imag e
87+
| SizeOfE e
88+
| AlignOfE e
8089
| CastE (_,e) ->
8190
warn_deref_exp a st e
82-
| _ -> ()
91+
| Question (b, t, f, _) ->
92+
warn_deref_exp a st b;
93+
warn_deref_exp a st t;
94+
warn_deref_exp a st f
8395

8496
let may (f: 'a -> 'b) (x: 'a option) : unit =
8597
match x with

src/analyses/tutorials/taint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct
4242
| CastE (_,e)
4343
| UnOp (_,e,_) -> is_exp_tainted state e
4444
| SizeOf _ | SizeOfStr _ | Const _ | AlignOf _ | AddrOfLabel _ -> false
45-
| Question _ -> failwith "should be optimized away by CIL"
45+
| Question (b, t, f, _) -> is_exp_tainted state b || is_exp_tainted state t || is_exp_tainted state f
4646
and is_lval_tainted state = function
4747
| (Var v, _) ->
4848
(* TODO: Check whether variable v is tainted *)

src/analyses/uninit.ml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,31 @@ struct
4949

5050
let rec access_one_byval a rw (exp:exp) =
5151
match exp with
52-
(* Integer literals *)
53-
| Const _ -> []
52+
| Const _
53+
| SizeOf _
54+
| SizeOfStr _
55+
| AlignOf _
56+
| AddrOfLabel _ -> []
5457
(* Variables and address expressions *)
5558
| Lval lval -> access_address a rw lval @ (access_lv_byval a lval)
5659
(* Binary operators *)
5760
| BinOp (op,arg1,arg2,typ) ->
5861
let a1 = access_one_byval a rw arg1 in
5962
let a2 = access_one_byval a rw arg2 in
6063
a1 @ a2
61-
(* Unary operators *)
62-
| UnOp (op,arg1,typ) -> access_one_byval a rw arg1
64+
| UnOp (_,e,_)
65+
| Real e
66+
| Imag e
67+
| SizeOfE e
68+
| AlignOfE e ->
69+
access_one_byval a rw e
6370
(* The address operators, we just check the accesses under them *)
6471
| AddrOf lval -> access_lv_byval a lval
6572
| StartOf lval -> access_lv_byval a lval
6673
(* Most casts are currently just ignored, that's probably not a good idea! *)
6774
| CastE (t, exp) -> access_one_byval a rw exp
68-
| _ -> []
75+
| Question (b, t, f, _) ->
76+
access_one_byval a rw b @ access_one_byval a rw t @ access_one_byval a rw f
6977
(* Accesses during the evaluation of an lval, not the lval itself! *)
7078
and access_lv_byval a (lval:lval) =
7179
let rec access_offset (ofs: offset) =

src/analyses/varEq.ml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ struct
118118
| AlignOf _
119119
| AlignOfE _
120120
| UnOp _
121-
| BinOp _ -> false
121+
| BinOp _
122+
| Question _
123+
| Real _
124+
| Imag _
125+
| AddrOfLabel _ -> false
122126
| Const _ -> true
123127
| AddrOf (Var v2,_)
124128
| StartOf (Var v2,_)
@@ -127,8 +131,6 @@ struct
127131
| StartOf (Mem e,_)
128132
| Lval (Mem e,_)
129133
| CastE (_,e) -> interesting e
130-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
131-
| _ -> failwith "Unmatched pattern."
132134

133135
(* helper to decide equality *)
134136
let query_exp_equal ask e1 e2 g s =
@@ -157,8 +159,11 @@ struct
157159
| SizeOfE _
158160
| SizeOfStr _
159161
| AlignOf _
160-
| AlignOfE _ -> false
161-
| UnOp (_,e,_) -> type_may_change_t e bt
162+
| AlignOfE _
163+
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
164+
| UnOp (_,e,_)
165+
| Real e
166+
| Imag e -> type_may_change_t e bt
162167
| BinOp (_,e1,e2,_) -> type_may_change_t e1 bt || type_may_change_t e2 bt
163168
| Lval (Var _,o)
164169
| AddrOf (Var _,o)
@@ -167,8 +172,7 @@ struct
167172
| AddrOf (Mem e,o)
168173
| StartOf (Mem e,o) -> may_change_t_offset o || type_may_change_t e bt
169174
| CastE (t,e) -> type_may_change_t e bt
170-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
171-
| _ -> failwith "Unmatched pattern."
175+
| Question (b, t, f, _) -> type_may_change_t b bt || type_may_change_t t bt || type_may_change_t f bt
172176
in
173177
let bt = unrollTypeDeep (Cilfacade.typeOf b) in
174178
type_may_change_t a bt
@@ -191,8 +195,11 @@ struct
191195
| SizeOfE _
192196
| SizeOfStr _
193197
| AlignOf _
194-
| AlignOfE _ -> false
195-
| UnOp (_,e,_) -> lval_may_change_pt e bl
198+
| AlignOfE _
199+
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
200+
| UnOp (_,e,_)
201+
| Real e
202+
| Imag e -> lval_may_change_pt e bl
196203
| BinOp (_,e1,e2,_) -> lval_may_change_pt e1 bl || lval_may_change_pt e2 bl
197204
| Lval (Var _,o)
198205
| AddrOf (Var _,o)
@@ -201,8 +208,7 @@ struct
201208
| AddrOf (Mem e,o)
202209
| StartOf (Mem e,o) -> may_change_pt_offset o || lval_may_change_pt e bl
203210
| CastE (t,e) -> lval_may_change_pt e bl
204-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
205-
| _ -> failwith "Unmatched pattern."
211+
| Question (b, t, f, _) -> lval_may_change_pt t bl || lval_may_change_pt t bl || lval_may_change_pt f bl
206212
in
207213
let bls = pt b in
208214
if Queries.LS.is_top bls
@@ -258,8 +264,11 @@ struct
258264
| SizeOfE _
259265
| SizeOfStr _
260266
| AlignOf _
261-
| AlignOfE _ -> false
262-
| UnOp (_,e,_) -> type_may_change_t deref e
267+
| AlignOfE _
268+
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
269+
| UnOp (_,e,_)
270+
| Real e
271+
| Imag e -> type_may_change_t deref e
263272
| BinOp (_,e1,e2,_) -> type_may_change_t deref e1 || type_may_change_t deref e2
264273
| Lval (Var _,o)
265274
| AddrOf (Var _,o)
@@ -268,8 +277,7 @@ struct
268277
| AddrOf (Mem e,o) -> (*Messages.warn "Addr" ;*) may_change_t_offset o || type_may_change_t false e
269278
| StartOf (Mem e,o) -> (*Messages.warn "Start";*) may_change_t_offset o || type_may_change_t false e
270279
| CastE (t,e) -> type_may_change_t deref e
271-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
272-
| _ -> failwith "Unmatched pattern."
280+
| Question (b, t, f, _) -> type_may_change_t deref b || type_may_change_t deref t || type_may_change_t deref f
273281

274282
and lval_may_change_pt a bl : bool =
275283
let rec may_change_pt_offset o =
@@ -324,8 +332,11 @@ struct
324332
| SizeOfE _
325333
| SizeOfStr _
326334
| AlignOf _
327-
| AlignOfE _ -> false
328-
| UnOp (_,e,_) -> lval_may_change_pt e bl
335+
| AlignOfE _
336+
| AddrOfLabel _ -> false (* TODO: some may contain exps? *)
337+
| UnOp (_,e,_)
338+
| Real e
339+
| Imag e -> lval_may_change_pt e bl
329340
| BinOp (_,e1,e2,_) -> lval_may_change_pt e1 bl || lval_may_change_pt e2 bl
330341
| Lval (Var _,o)
331342
| AddrOf (Var _,o)
@@ -334,8 +345,7 @@ struct
334345
| AddrOf (Mem e,o)
335346
| StartOf (Mem e,o) -> may_change_pt_offset o || lval_may_change_pt e bl
336347
| CastE (t,e) -> lval_may_change_pt e bl
337-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
338-
| _ -> failwith "Unmatched pattern."
348+
| Question (b, t, f, _) -> lval_may_change_pt b bl || lval_may_change_pt t bl || lval_may_change_pt f bl
339349
in
340350
let r =
341351
if Queries.LS.is_top bls || Queries.LS.mem (dummyFunDec.svar, `NoOffset) bls
@@ -373,7 +383,11 @@ struct
373383
| AlignOf _
374384
| AlignOfE _
375385
| UnOp _
376-
| BinOp _ -> None
386+
| BinOp _
387+
| Question _
388+
| AddrOfLabel _
389+
| Real _
390+
| Imag _ -> None
377391
| Const _ -> Some false
378392
| Lval (Var v,_) ->
379393
Some (v.vglob || (ask.f (Queries.IsMultiple v)))
@@ -388,8 +402,6 @@ struct
388402
| AddrOf lv -> Some false (* TODO: sound?! *)
389403
| StartOf (Var v,_) -> Some (ask.f (Queries.IsMultiple v)) (* Taking an address of a global is fine*)
390404
| StartOf lv -> Some false (* TODO: sound?! *)
391-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
392-
| _ -> failwith "Unmatched pattern."
393405

394406
(* Set given lval equal to the result of given expression. On doubt do nothing. *)
395407
let add_eq ask (lv:lval) (rv:Exp.t) st =
@@ -551,6 +563,10 @@ struct
551563
| AlignOfE _
552564
| UnOp _
553565
| BinOp _
566+
| Question _
567+
| AddrOfLabel _
568+
| Real _
569+
| Imag _
554570
| AddrOf (Var _,_)
555571
| StartOf (Var _,_)
556572
| Lval (Var _,_) -> eq_set e s
@@ -562,8 +578,6 @@ struct
562578
Queries.ES.map (fun e -> Lval (mkMem ~addr:e ~off:ofs)) (eq_set_clos e s)
563579
| CastE (t,e) ->
564580
Queries.ES.map (fun e -> CastE (t,e)) (eq_set_clos e s)
565-
| Question _ -> failwith "Logical operations should be compiled away by CIL."
566-
| _ -> failwith "Unmatched pattern."
567581

568582

569583
let query ctx (type a) (x: a Queries.t): a Queries.result =

src/cdomains/apron/apronDomain.apron.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ struct
335335

336336

337337
let cil_exp_of_lincons1 fundec (lincons1:Lincons1.t) =
338-
let zero = Cil.zero in
338+
let zero = Cil.kinteger ILongLong 0 in
339339
try
340340
let linexpr1 = Lincons1.get_linexpr1 lincons1 in
341341
let cilexp = cil_exp_of_linexpr1 fundec linexpr1 in

src/cdomains/basetype.ml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,20 @@ struct
9696
match e with
9797
| Lval l -> occurs_lv l
9898
| AddrOf l -> occurs_lv l
99-
| UnOp (_,e,_) -> occurs x e
99+
| StartOf l -> occurs_lv l
100+
| UnOp (_,e,_)
101+
| Real e
102+
| Imag e
103+
| SizeOfE e
104+
| AlignOfE e -> occurs x e
100105
| BinOp (_,e1,e2,_) -> occurs x e1 || occurs x e2
101106
| CastE (_,e) -> occurs x e
102-
| _ -> false
107+
| Question (b, t, f, _) -> occurs x b || occurs x t || occurs x f
108+
| Const _
109+
| SizeOf _
110+
| SizeOfStr _
111+
| AlignOf _
112+
| AddrOfLabel _ -> false
103113

104114
let replace (x:varinfo) (exp: exp) (e:exp): exp =
105115
let rec replace_lv (v,offs): lval =
@@ -115,11 +125,21 @@ struct
115125
match e with
116126
| Lval (Var y, NoOffset) when Variables.equal x y -> exp
117127
| Lval l -> Lval (replace_lv l)
118-
| AddrOf l -> Lval (replace_lv l)
128+
| AddrOf l -> Lval (replace_lv l) (* TODO: should be AddrOf? *)
129+
| StartOf l -> StartOf (replace_lv l)
119130
| UnOp (op,e,t) -> UnOp (op, replace_rv e, t)
120131
| BinOp (op,e1,e2,t) -> BinOp (op, replace_rv e1, replace_rv e2, t)
121132
| CastE (t,e) -> CastE(t, replace_rv e)
122-
| x -> x
133+
| Real e -> Real (replace_rv e)
134+
| Imag e -> Imag (replace_rv e)
135+
| SizeOfE e -> SizeOfE (replace_rv e)
136+
| AlignOfE e -> AlignOfE (replace_rv e)
137+
| Question (b, t, f, typ) -> Question (replace_rv b, replace_rv t, replace_rv f, typ)
138+
| Const _
139+
| SizeOf _
140+
| SizeOfStr _
141+
| AlignOf _
142+
| AddrOfLabel _ -> e
123143
in
124144
constFold true (replace_rv e)
125145

@@ -134,7 +154,7 @@ struct
134154
| AlignOf _
135155
| Question _
136156
| AddrOf _
137-
| StartOf _ -> []
157+
| StartOf _ -> [] (* TODO: return not empty, some may contain vars! *)
138158
| UnOp (_, e, _ )
139159
| CastE (_, e)
140160
| Real e

0 commit comments

Comments
 (0)