Skip to content

Commit

Permalink
Cache option ana.base.strings.domain, reset the cache in server.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerhard committed Nov 14, 2023
1 parent 3cb651f commit e64558d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/cdomains/stringDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@ include Printable.StdLeaf

let name () = "string"

type string_domain = Unit | Disjoint | Flat
let string_domain = ref None
let string_domain_config = "ana.base.strings.domain"
let parse config = match config with
| "unit" -> Unit
| "disjoint" -> Disjoint
| "flat" -> Flat
| _ -> raise @@ GobConfig.ConfigError ("Invalid option for " ^ string_domain_config)

let get_string_domain () =
if !string_domain = None then
string_domain := Some (parse (GobConfig.get_string string_domain_config));
Option.get !string_domain

let reset_lazy () =
string_domain := None

type t = string option [@@deriving eq, ord, hash]

let hash x =
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
if get_string_domain () = Disjoint then
hash x
else
13859
Expand All @@ -22,7 +39,7 @@ include Printable.SimpleShow (
)

let of_string x =
if GobConfig.get_string "ana.base.strings.domain" = "unit" then
if get_string_domain () = Unit then
None
else
Some x
Expand Down Expand Up @@ -74,7 +91,7 @@ let join x y =
| _, None -> None
| Some a, Some b when a = b -> Some a
| Some a, Some b (* when a <> b *) ->
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
if get_string_domain () = Disjoint then
raise Lattice.Uncomparable
else
None
Expand All @@ -85,13 +102,13 @@ let meet x y =
| a, None -> a
| Some a, Some b when a = b -> Some a
| Some a, Some b (* when a <> b *) ->
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
if get_string_domain () = Disjoint then
raise Lattice.Uncomparable
else
raise Lattice.BotValue

let repr x =
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
if get_string_domain () = Disjoint then
x (* everything else is kept separate, including strings if not limited *)
else
None (* all strings together if limited *)
3 changes: 3 additions & 0 deletions src/cdomains/stringDomain.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

include Printable.S

val reset_lazy: unit -> unit
(** Reset the cached configuration of the string domain. *)

val of_string: string -> t
(** Convert from string. *)

Expand Down
1 change: 1 addition & 0 deletions src/util/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ let analyze ?(reset=false) (s: t) =
InvariantCil.reset_lazy ();
WideningThresholds.reset_lazy ();
IntDomain.reset_lazy ();
StringDomain.reset_lazy ();
PrecisionUtil.reset_lazy ();
ApronDomain.reset_lazy ();
AutoTune.reset_lazy ();
Expand Down

0 comments on commit e64558d

Please sign in to comment.