Skip to content

Commit

Permalink
Allow non-void types for RichVarinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Mar 15, 2024
1 parent a10c973 commit 932ac3b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/analyses/basePriv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ struct
(* sync: M -> (2^M -> (G -> D)) *)
include AbstractLockCenteredBase (ThreadMap) (LockCenteredBase.CPA)

let global_init_thread = RichVarinfo.single ~name:"global_init"
let global_init_thread = RichVarinfo.single ~name:"global_init" ~typ:GoblintCil.voidType
let current_thread (ask: Q.ask): Thread.t =
if !AnalysisState.global_initialization then
ThreadIdDomain.Thread.threadinit (global_init_thread ()) ~multiple:false
Expand Down
2 changes: 2 additions & 0 deletions src/analyses/wrapperFunctionAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ module MallocWrapper : MCPSpec = struct
Format.dprintf "@tid:%s" (ThreadLifted.show t)
in
Format.asprintf "(alloc@sid:%s%t%t)" (Node.show_id node) tid uniq_count

let typ _ = GoblintCil.voidType
end

module NodeVarinfoMap = RichVarinfo.BiVarinfoMap.Make(ThreadNode)
Expand Down
9 changes: 5 additions & 4 deletions src/common/util/richVarinfo.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
open GoblintCil

let create_var name = Cilfacade.create_var @@ makeGlobalVar name voidType
let create_var name typ = Cilfacade.create_var @@ makeGlobalVar name typ

let single ~name =
let vi = lazy (create_var name) in
let single ~name ~typ =
let vi = lazy (create_var name typ) in
fun () ->
Lazy.force vi

Expand All @@ -21,6 +21,7 @@ module type G =
sig
include Hashtbl.HashedType
val name_varinfo: t -> string
val typ: t -> typ
end

module type H =
Expand All @@ -47,7 +48,7 @@ struct
try
XH.find !xh x
with Not_found ->
let vi = create_var (X.name_varinfo x) in
let vi = create_var (X.name_varinfo x) (X.typ x) in
store_f x vi;
vi

Expand Down
3 changes: 2 additions & 1 deletion src/common/util/richVarinfo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

open GoblintCil

val single: name:string -> (unit -> varinfo)
val single: name:string -> typ:typ -> (unit -> varinfo)

module type VarinfoMap =
sig
Expand All @@ -18,6 +18,7 @@ module type G =
sig
include Hashtbl.HashedType
val name_varinfo: t -> string
val typ: t -> typ
end

module type H =
Expand Down
6 changes: 2 additions & 4 deletions src/witness/witnessGhost.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ struct
| Locked l -> LockDomain.Addr.show l ^ "_locked" (* TODO: valid C name *)
| Multithreaded -> "multithreaded"

(* TODO: define correct types *)

let type_ = function
let typ = function
| Locked _ -> GoblintCil.intType
| Multithreaded -> GoblintCil.intType

Expand All @@ -30,7 +28,7 @@ include Map

let variable_entry ~task x =
let variable = name_varinfo x in
let type_ = String.trim (CilType.Typ.show (type_ x)) in (* CIL printer puts space at the end of some types *)
let type_ = String.trim (CilType.Typ.show (typ x)) in (* CIL printer puts space at the end of some types *)
let initial = CilType.Exp.show (initial x) in
YamlWitness.Entry.ghost_variable ~task ~variable ~type_ ~initial

Expand Down

0 comments on commit 932ac3b

Please sign in to comment.