-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1208 from goblint/string-unit-domain
Add `ana.base.strings.domain` option and unit string domain
- Loading branch information
Showing
14 changed files
with
216 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
include Printable.StdLeaf | ||
|
||
let name () = "string" | ||
|
||
type string_domain = Unit | Disjoint | Flat | ||
|
||
let string_domain: string_domain ResettableLazy.t = | ||
ResettableLazy.from_fun (fun () -> | ||
match GobConfig.get_string "ana.base.strings.domain" with | ||
| "unit" -> Unit | ||
| "disjoint" -> Disjoint | ||
| "flat" -> Flat | ||
| _ -> failwith "ana.base.strings.domain: illegal value" | ||
) | ||
|
||
let get_string_domain () = ResettableLazy.force string_domain | ||
|
||
let reset_lazy () = | ||
ResettableLazy.reset string_domain | ||
|
||
|
||
type t = string option [@@deriving eq, ord, hash] | ||
|
||
let hash x = | ||
if get_string_domain () = Disjoint then | ||
hash x | ||
else | ||
13859 | ||
|
||
let show = function | ||
| Some x -> "\"" ^ x ^ "\"" | ||
| None -> "(unknown string)" | ||
|
||
include Printable.SimpleShow ( | ||
struct | ||
type nonrec t = t | ||
let show = show | ||
end | ||
) | ||
|
||
let of_string x = | ||
if get_string_domain () = Unit then | ||
None | ||
else | ||
Some x | ||
let to_string x = x | ||
|
||
(* only keep part before first null byte *) | ||
let to_c_string = function | ||
| Some x -> | ||
begin match String.split_on_char '\x00' x with | ||
| s::_ -> Some s | ||
| [] -> None | ||
end | ||
| None -> None | ||
|
||
let to_n_c_string n x = | ||
match to_c_string x with | ||
| Some x -> | ||
if n > String.length x then | ||
Some x | ||
else if n < 0 then | ||
None | ||
else | ||
Some (String.sub x 0 n) | ||
| None -> None | ||
|
||
let to_string_length x = | ||
match to_c_string x with | ||
| Some x -> Some (String.length x) | ||
| None -> None | ||
|
||
let to_exp = function | ||
| Some x -> GoblintCil.mkString x | ||
| None -> raise (Lattice.Unsupported "Cannot express unknown string pointer as expression.") | ||
|
||
let semantic_equal x y = | ||
match x, y with | ||
| None, _ | ||
| _, None -> Some true | ||
| Some a, Some b -> if a = b then None else Some false | ||
|
||
let leq x y = | ||
match x, y with | ||
| _, None -> true | ||
| a, b -> a = b | ||
|
||
let join x y = | ||
match x, y with | ||
| None, _ | ||
| _, None -> None | ||
| Some a, Some b when a = b -> Some a | ||
| Some a, Some b (* when a <> b *) -> | ||
if get_string_domain () = Disjoint then | ||
raise Lattice.Uncomparable | ||
else | ||
None | ||
|
||
let meet x y = | ||
match x, y with | ||
| None, a | ||
| a, None -> a | ||
| Some a, Some b when a = b -> Some a | ||
| Some a, Some b (* when a <> b *) -> | ||
if get_string_domain () = Disjoint then | ||
raise Lattice.Uncomparable | ||
else | ||
raise Lattice.BotValue | ||
|
||
let repr x = | ||
if get_string_domain () = Disjoint then | ||
x (* everything else is kept separate, including strings if not limited *) | ||
else | ||
None (* all strings together if limited *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(** String literals domain. *) | ||
|
||
include Printable.S | ||
|
||
val reset_lazy: unit -> unit | ||
(** Reset the cached configuration of the string domain. *) | ||
|
||
val of_string: string -> t | ||
(** Convert from string. *) | ||
|
||
val to_string: t -> string option | ||
(** Convert to string if possible. *) | ||
|
||
(** C strings are different from OCaml strings as they are not processed after the first [NUL] byte, even though the OCaml string (and a C string literal) may be longer. *) | ||
|
||
val to_c_string: t -> string option | ||
(** Convert to C string if possible. *) | ||
|
||
val to_n_c_string: int -> t -> string option | ||
(** Convert to C string of given maximum length if possible. *) | ||
|
||
val to_string_length: t -> int option | ||
(** Find length of C string if possible. *) | ||
|
||
val to_exp: t -> GoblintCil.exp | ||
(** Convert to CIL expression. *) | ||
|
||
val semantic_equal: t -> t -> bool option | ||
(** Check semantic equality of two strings. | ||
@return [Some true] if definitely equal, [Some false] if definitely not equal, [None] if unknown. *) | ||
|
||
(** Some {!Lattice.S} operations. *) | ||
|
||
val leq: t -> t -> bool | ||
val join: t -> t -> t | ||
val meet: t -> t -> t | ||
|
||
val repr : t -> t | ||
(** Representative for address lattice. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.