Skip to content

Commit 2059391

Browse files
committed
C2PO: Adapt C2PO such that is does not read attributes from richvarinfo vars.
The C2PO analysis maps some varinfos to varinfos via the RichVarinfo module. The code used to read some attributes from these variables from the result varinfos. Thus, it required a change where the all the attributes of resulting rich varinfos can be specified. With this change, this is no longer necessary.
1 parent 1377a28 commit 2059391

File tree

8 files changed

+46
-117
lines changed

8 files changed

+46
-117
lines changed

src/analyses/basePriv.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,11 +1197,7 @@ struct
11971197
(* sync: M -> (2^M -> (G -> D)) *)
11981198
include AbstractLockCenteredBase (ThreadMap) (LockCenteredBase.CPA)
11991199

1200-
let global_init_thread () =
1201-
let v = RichVarinfo.VarinfoDescription.empty "global_init" in
1202-
let v = {v with vtype_=Some GoblintCil.voidType } in
1203-
RichVarinfo.create_var v
1204-
1200+
let global_init_thread = RichVarinfo.single ~name:"global_init" ~typ:GoblintCil.voidType
12051201
let current_thread (ask: Q.ask): Thread.t =
12061202
if !AnalysisState.global_initialization then
12071203
ThreadIdDomain.Thread.threadinit (global_init_thread ()) ~multiple:false

src/analyses/wrapperFunctionAnalysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ module MallocWrapper : MCPSpec = struct
145145
in
146146
Format.asprintf "(alloc@sid:%s%t%t)" (Node.show_id node) tid uniq_count
147147

148-
let varinfo_attributes x = RichVarinfo.VarinfoDescription.empty (name_varinfo x)
148+
let typ _ = GoblintCil.voidType
149149
end
150150

151151
module NodeVarinfoMap = RichVarinfo.BiVarinfoMap.Make(ThreadNode)

src/cdomains/c2poDomain.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ module D = struct
245245
if M.tracing then M.trace "c2po" "remove_terms_not_containing_variables: %s\n" (List.fold_left (fun s v -> s ^"; " ^Var.show v) "" vars);
246246
let not_global_and_not_contains_variable t =
247247
let var = T.get_var t in
248-
let var = Var.to_varinfo var in
249-
(not var.vglob) && not (T.contains_variable vars t)
248+
not (DuplicateVars.VarType.vglob var) && not (T.contains_variable vars t)
250249
in
251250
remove_terms not_global_and_not_contains_variable cc
252251

src/cdomains/duplicateVars.ml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ module VarType = struct
4747

4848
List.of_seq complete
4949

50+
(* Need to lookup attributes such as vaddrof in the original varinfo *)
51+
let vaddrof : t -> bool = function
52+
| AssignAux _
53+
| ReturnAux _ -> false
54+
| NormalVar v
55+
| DuplicVar v -> v.vaddrof
56+
57+
let vglob : t -> bool = function
58+
| AssignAux _
59+
| ReturnAux _ -> false
60+
| NormalVar v
61+
| DuplicVar v -> v.vglob
62+
5063
let duplic_var_prefix =
5164
"c2po__"
5265
let duplic_var_postfix =
@@ -76,18 +89,19 @@ module VarType = struct
7689
| ReturnAux _ -> true
7790
| _ -> false
7891

79-
let varinfo_attributes v =
80-
let open RichVarinfo.VarinfoDescription in
92+
let name_varinfo v =
8193
match v with
8294
| AssignAux t ->
83-
({(empty "AuxAssign") with vtype_=Some t})
95+
"AuxAssign"
8496
| ReturnAux t ->
85-
({(empty "AuxReturn") with vtype_=Some t})
97+
"AuxReturn"
8698
| NormalVar v ->
87-
from_varinfo v
99+
v.vname
88100
| DuplicVar v ->
89-
let vname_ = duplic_var_prefix ^ string_of_int v.vid ^ duplic_var_postfix in
90-
from_varinfo {v with vname = vname_}
101+
duplic_var_prefix ^ string_of_int v.vid ^ duplic_var_postfix
102+
103+
let typ v =
104+
get_type v
91105

92106
(* Description that gets appended to the varinfo-name in user output. *)
93107
let describe_varinfo (var: varinfo) v =

src/cdomains/unionFind.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,15 @@ module T = struct
216216
let lval = Lval (var, NoOffset) in
217217
Aux (vinfo, lval)
218218

219-
let term_of_varinfo vinfo =
220-
let var = Var.to_varinfo vinfo in
219+
(* *)
220+
let term_of_varinfo var_type =
221+
let var = Var.to_varinfo var_type in
221222
let lval = Lval (Var var, NoOffset) in
222223

223-
if is_struct_type var.vtype || var.vaddrof then
224-
Deref (Addr vinfo, Z.zero, lval)
224+
if is_struct_type var.vtype || DuplicateVars.VarType.vaddrof var_type then
225+
Deref (Addr var_type, Z.zero, lval)
225226
else
226-
aux_term_of_varinfo vinfo
227+
aux_term_of_varinfo var_type
227228

228229
(** From a offset, compute the index in bits *)
229230
let offset_to_index ?typ offset =

src/common/util/richVarinfo.ml

Lines changed: 10 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
open GoblintCil
22

3+
let create_var name typ = Cilfacade.create_var @@ makeGlobalVar name typ
4+
5+
let single ~name ~typ =
6+
let vi = lazy (create_var name typ) in
7+
fun () ->
8+
Lazy.force vi
9+
310
module type VarinfoMap =
411
sig
512
type t
@@ -10,78 +17,11 @@ sig
1017
val bindings: unit -> (t * varinfo) list
1118
end
1219

13-
module VarinfoDescription = struct
14-
(**This type is equal to `varinfo`, but the fields are not mutable and they are optional.
15-
Only the name is not optional. *)
16-
type t = {
17-
vname_: string;
18-
vtype_: typ option;
19-
vattr_: attributes option;
20-
vstorage_: storage option;
21-
vglob_: bool option;
22-
vinline_: bool option;
23-
vdecl_: location option;
24-
vinit_: initinfo option;
25-
vaddrof_: bool option;
26-
vreferenced_: bool option;
27-
}
28-
29-
let from_varinfo (v: varinfo) =
30-
{vname_=v.vname;
31-
vtype_=Some v.vtype;
32-
vattr_=Some v.vattr;
33-
vstorage_=Some v.vstorage;
34-
vglob_=Some v.vglob;
35-
vinline_=Some v.vinline;
36-
vdecl_=Some v.vdecl;
37-
vinit_=Some v.vinit;
38-
vaddrof_=Some v.vaddrof;
39-
vreferenced_=Some v.vreferenced}
40-
41-
let empty name =
42-
{vname_=name;
43-
vtype_=None;
44-
vattr_=None;
45-
vstorage_=None;
46-
vglob_=None;
47-
vinline_=None;
48-
vdecl_=None;
49-
vinit_=None;
50-
vaddrof_=None;
51-
vreferenced_=None}
52-
53-
let update_varinfo (v: varinfo) (update: t) =
54-
let open Batteries in
55-
{vname=update.vname_;
56-
vtype=Option.default v.vtype update.vtype_;
57-
vattr=Option.default v.vattr update.vattr_;
58-
vstorage=Option.default v.vstorage update.vstorage_;
59-
vglob=Option.default v.vglob update.vglob_;
60-
vinline=Option.default v.vinline update.vinline_;
61-
vdecl=Option.default v.vdecl update.vdecl_;
62-
vinit=Option.default v.vinit update.vinit_;
63-
vid=v.vid;
64-
vaddrof=Option.default v.vaddrof update.vaddrof_;
65-
vreferenced=Option.default v.vreferenced update.vreferenced_;
66-
vdescr=v.vdescr;
67-
vdescrpure=v.vdescrpure;
68-
vhasdeclinstruction=v.vhasdeclinstruction}
69-
end
70-
71-
let create_var (vd: VarinfoDescription.t) =
72-
Cilfacade.create_var (
73-
VarinfoDescription.update_varinfo (makeGlobalVar vd.vname_ voidType) vd
74-
)
75-
76-
let single ~name =
77-
let vi = lazy (create_var (VarinfoDescription.empty name)) in
78-
fun () ->
79-
Lazy.force vi
80-
8120
module type G =
8221
sig
8322
include Hashtbl.HashedType
84-
val varinfo_attributes: t -> VarinfoDescription.t
23+
val name_varinfo: t -> string
24+
val typ: t -> typ
8525
end
8626

8727
module type H =
@@ -108,7 +48,7 @@ struct
10848
try
10949
XH.find !xh x
11050
with Not_found ->
111-
let vi = create_var (X.varinfo_attributes x) in
51+
let vi = create_var (X.name_varinfo x) (X.typ x) in
11252
store_f x vi;
11353
vi
11454

src/common/util/richVarinfo.mli

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
open GoblintCil
44

5+
val single: name:string -> typ:typ -> (unit -> varinfo)
6+
57
module type VarinfoMap =
68
sig
79
type t
@@ -12,32 +14,11 @@ sig
1214
val bindings: unit -> (t * varinfo) list
1315
end
1416

15-
module VarinfoDescription:
16-
sig
17-
type t = {
18-
vname_: string;
19-
vtype_: typ option;
20-
vattr_: attributes option;
21-
vstorage_: storage option;
22-
vglob_: bool option;
23-
vinline_: bool option;
24-
vdecl_: location option;
25-
vinit_: initinfo option;
26-
vaddrof_: bool option;
27-
vreferenced_: bool option;
28-
}
29-
val from_varinfo: varinfo -> t
30-
val empty: string -> t
31-
val update_varinfo: varinfo -> t -> varinfo
32-
end
33-
34-
val create_var: VarinfoDescription.t -> varinfo
35-
val single: name:string -> (unit -> varinfo)
36-
3717
module type G =
3818
sig
3919
include Hashtbl.HashedType
40-
val varinfo_attributes: t -> VarinfoDescription.t
20+
val name_varinfo: t -> string
21+
val typ: t -> typ
4122
end
4223

4324
module type H =

src/witness/witnessGhostVar.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type t =
55
| Multithreaded
66
[@@deriving eq, ord, hash]
77

8-
let show = function
8+
let name_varinfo = function
99
| Locked (v, os) ->
1010
let name =
1111
if CilType.Varinfo.equal v LibraryFunctions.verifier_atomic_var then
@@ -25,9 +25,7 @@ let show = function
2525
name ^ offs os ^ "_locked"
2626
| Multithreaded -> "multithreaded"
2727

28-
let varinfo_attributes l =
29-
let name = show l in
30-
RichVarinfo.VarinfoDescription.empty name
28+
let show = name_varinfo
3129

3230
include Printable.SimpleShow (struct
3331
type nonrec t = t

0 commit comments

Comments
 (0)