Skip to content

Commit

Permalink
Change ana.base.limit-string-addresses to ana.base.strings.domain
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Oct 6, 2023
1 parent 12a22b6 commit 26b9cad
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 29 deletions.
4 changes: 3 additions & 1 deletion conf/examples/very-precise.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
"structs" : {
"domain" : "combined-sk"
},
"limit-string-addresses": false
"strings": {
"domain": "disjoint"
}
}
},
"exp": {
Expand Down
2 changes: 1 addition & 1 deletion src/cdomains/addressDomain_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sig
- Each {!Addr}, modulo precise index expressions in the offset, is a sublattice with ordering induced by {!Mval}.
- {!NullPtr} is a singleton sublattice.
- {!UnknownPtr} is a singleton sublattice.
- If [ana.base.limit-string-addresses] is enabled, then all {!StrPtr} are together in one sublattice with flat ordering. If [ana.base.limit-string-addresses] is disabled, then each {!StrPtr} is a singleton sublattice. *)
- If [ana.base.strings.domain] is disjoint, then each {!StrPtr} is a singleton sublattice. Otherwise, all {!StrPtr} are together in one sublattice with flat ordering. *)
module AddressLattice (Mval: Mval.Lattice):
sig
include module type of AddressPrintable (Mval)
Expand Down
30 changes: 17 additions & 13 deletions src/cdomains/stringDomain.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
type t = string option [@@deriving eq, ord, hash]

let hash x =
if GobConfig.get_bool "ana.base.limit-string-addresses" then
13859
else
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
hash x
else
13859

let show = function
| Some x -> "\"" ^ x ^ "\""
Expand All @@ -17,7 +17,11 @@ include Printable.SimpleShow (
end
)

let of_string x = Some x
let of_string x =
if GobConfig.get_string "ana.base.strings.domain" = "unit" then
None
else
Some x
let to_string x = x

(* only keep part before first null byte *)
Expand Down Expand Up @@ -66,24 +70,24 @@ 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_bool "ana.base.limit-string-addresses" then
None
else
if GobConfig.get_string "ana.base.strings.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 GobConfig.get_bool "ana.base.limit-string-addresses" then
raise Lattice.BotValue
else
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
raise Lattice.Uncomparable
else
raise Lattice.BotValue

let repr x =
if GobConfig.get_bool "ana.base.limit-string-addresses" then
None (* all strings together if limited *)
else
if GobConfig.get_string "ana.base.strings.domain" = "disjoint" then
x (* everything else is kept separate, including strings if not limited *)
else
None (* all strings together if limited *)
18 changes: 13 additions & 5 deletions src/util/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,19 @@
},
"additionalProperties": false
},
"limit-string-addresses": {
"title": "ana.base.limit-string-addresses",
"description": "Limit abstract address sets to keep at most one distinct string pointer.",
"type": "boolean",
"default": true
"strings": {
"title": "ana.base.strings",
"type": "object",
"properties": {
"domain": {
"title": "ana.base.strings.domain",
"description": "Domain for string literals.",
"type": "string",
"enum": ["unit", "flat", "disjoint"],
"default": "flat"
}
},
"additionalProperties": false
},
"partition-arrays": {
"title": "ana.base.partition-arrays",
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/02-base/88-string-ptrs-limited.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//PARAM: --enable ana.base.limit-string-addresses
//PARAM: --set ana.base.strings.domain flat
#include <stdlib.h>
#include <goblint.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/regression/02-base/89-string-ptrs-not-limited.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//PARAM: --disable ana.base.limit-string-addresses
//PARAM: --set ana.base.strings.domain disjoint
#include <stdlib.h>
#include <goblint.h>

Expand Down
8 changes: 4 additions & 4 deletions tests/regression/73-strings/01-string_literals.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PARAM: --disable ana.base.limit-string-addresses --enable ana.int.interval
// PARAM: --set ana.base.strings.domain disjoint --enable ana.int.interval

#include <goblint.h>
#include <string.h>
Expand All @@ -21,7 +21,7 @@ int main() {
char* s1 = "abcde";
char* s2 = "abcdfg";
char* s3 = hello_world();

int i = strlen(s1);
__goblint_check(i == 5);

Expand Down Expand Up @@ -96,10 +96,10 @@ int main() {
#define STRNCAT strncat(s1, "hi", 1)
#endif
STRNCAT; // WARN

#ifdef __APPLE__
// do nothing => no warning
#else
#else
char s4[] = "hello";
strcpy(s4, s2); // NOWARN
strncpy(s4, s3, 2); // NOWARN
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/73-strings/02-string_literals_with_null.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PARAM: --disable ana.base.limit-string-addresses --enable ana.int.interval
// PARAM: --set ana.base.strings.domain disjoint --enable ana.int.interval

#include <goblint.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/73-strings/03-string_basics.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PARAM: --disable ana.base.limit-string-addresses --enable ana.int.interval
// PARAM: --set ana.base.strings.domain disjoint --enable ana.int.interval

#include <goblint.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/73-strings/05-string-unit-domain.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PARAM: --enable ana.base.limit-string-addresses
// PARAM: --set ana.base.strings.domain unit
#include <string.h>
#include <goblint.h>

Expand Down

0 comments on commit 26b9cad

Please sign in to comment.