Skip to content

Commit 529a650

Browse files
authored
Merge pull request #749 from goblint/remove-inthack
Remove `inthack` and fix i-lock star display
2 parents c0fead2 + 99a0f8e commit 529a650

File tree

5 files changed

+74
-26
lines changed

5 files changed

+74
-26
lines changed

src/analyses/symbLocks.ml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
(** Symbolic lock-sets for use in per-element patterns. *)
1+
(** Symbolic lock-sets for use in per-element patterns.
2+
3+
See Section 5 and 6 in https://dl.acm.org/doi/10.1145/2970276.2970337 for more details. *)
24

35
module LF = LibraryFunctions
46
module LP = SymbLocksDomain.LockingPattern
57
module Exp = SymbLocksDomain.Exp
8+
module ILock = SymbLocksDomain.ILock
69
module VarEq = VarEq.Spec
710

811
module PS = SetDomain.ToppedSet (LP) (struct let topname = "All" end)
@@ -106,22 +109,14 @@ struct
106109
ctx.local
107110

108111

109-
let rec conv_const_offset x =
110-
match x with
111-
| NoOffset -> `NoOffset
112-
113-
| Index (Const (CInt (i,ikind,s)),o) -> `Index (IntDomain.of_const (i,ikind,s), conv_const_offset o)
114-
| Index (_,o) -> `Index (ValueDomain.IndexDomain.top (), conv_const_offset o)
115-
| Field (f,o) -> `Field (f, conv_const_offset o)
116-
117112
module A =
118113
struct
119114
module E = struct
120-
include Printable.Either (CilType.Offset) (ValueDomain.Addr)
115+
include Printable.Either (CilType.Offset) (ILock)
121116

122117
let pretty () = function
123118
| `Left o -> Pretty.dprintf "p-lock:%a" (d_offset (text "*")) o
124-
| `Right addr -> Pretty.dprintf "i-lock:%a" ValueDomain.Addr.pretty addr
119+
| `Right addr -> Pretty.dprintf "i-lock:%a" ILock.pretty addr
125120

126121
include Printable.SimplePretty (
127122
struct
@@ -164,7 +159,7 @@ struct
164159
let one_lockstep (_,a,m) xs =
165160
match m with
166161
| AddrOf (Var v,o) ->
167-
let lock = ValueDomain.Addr.from_var_offset (v, conv_const_offset o) in
162+
let lock = ILock.from_var_offset (v, o) in
168163
A.add (`Right lock) xs
169164
| _ ->
170165
Messages.warn "Internal error: found a strange lockstep pattern.";

src/cdomains/intDomain.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ struct
930930
let bot () = raise Error
931931
let top_of ik = top ()
932932
let bot_of ik = bot ()
933-
let show (x: Ints_t.t) = if (Ints_t.to_int64 x) = GU.inthack then "*" else Ints_t.to_string x
933+
let show (x: Ints_t.t) = Ints_t.to_string x
934934

935935
include Std (struct type nonrec t = t let name = name let top_of = top_of let bot_of = bot_of let show = show let equal = equal end)
936936
(* is_top and is_bot are never called, but if they were, the Std impl would raise their exception, so we overwrite them: *)

src/cdomains/lval.ml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ type ('a, 'b) offs = [
1010
] [@@deriving eq, ord, hash]
1111

1212

13-
module Offset (Idx: IntDomain.Z) =
13+
(** Subinterface of IntDomain.Z which is sufficient for Printable (but not Lattice) Offset. *)
14+
module type IdxDomain =
15+
sig
16+
include Printable.S
17+
val equal_to: IntOps.BigIntOps.t -> t -> [`Eq | `Neq | `Top]
18+
val is_int: t -> bool
19+
end
20+
21+
module OffsetPrintable (Idx: IdxDomain) =
1422
struct
1523
type t = (fieldinfo, Idx.t) offs
1624
include Printable.Std
@@ -90,6 +98,17 @@ struct
9098
| `Field _, `Index _ -> -1
9199
| `Index _, `Field _ -> 1
92100

101+
let rec to_cil_offset (x:t) =
102+
match x with
103+
| `NoOffset -> NoOffset
104+
| `Field(f,o) -> Field(f, to_cil_offset o)
105+
| `Index(i,o) -> NoOffset (* array domain can not deal with this -> leads to being handeled as access to unknown part *)
106+
end
107+
108+
module Offset (Idx: IntDomain.Z) =
109+
struct
110+
include OffsetPrintable (Idx)
111+
93112
let rec leq x y =
94113
match x, y with
95114
| `NoOffset, `NoOffset -> true
@@ -112,12 +131,6 @@ struct
112131
| `Index (x1,y1), `Index (x2,y2) -> `Index (op x1 x2, merge cop y1 y2)
113132
| _ -> raise Lattice.Uncomparable
114133

115-
let rec to_cil_offset (x:t) =
116-
match x with
117-
| `NoOffset -> NoOffset
118-
| `Field(f,o) -> Field(f, to_cil_offset o)
119-
| `Index(i,o) -> NoOffset (* array domain can not deal with this -> leads to being handeled as access to unknown part *)
120-
121134
let join x y = merge `Join x y
122135
let meet x y = merge `Meet x y
123136
let widen x y = merge `Widen x y
@@ -160,11 +173,11 @@ sig
160173
(** Finds the type of the address location. *)
161174
end
162175

163-
module Normal (Idx: IntDomain.Z) =
176+
module Normal (Idx: IdxDomain) =
164177
struct
165178
type field = fieldinfo
166179
type idx = Idx.t
167-
module Offs = Offset (Idx)
180+
module Offs = OffsetPrintable (Idx)
168181
type t =
169182
| Addr of CilType.Varinfo.t * Offs.t (** Pointer to offset of a variable. *)
170183
| NullPtr (** NULL pointer. *)
@@ -287,6 +300,7 @@ end
287300
module NormalLat (Idx: IntDomain.Z) =
288301
struct
289302
include Normal (Idx)
303+
module Offs = Offset (Idx)
290304

291305
let is_definite = function
292306
| NullPtr | StrPtr _ -> true

src/cdomains/symbLocksDomain.ml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ struct
111111
| Index (i,o) -> isConstant i && conc o
112112
| Field (_,o) -> conc o
113113

114+
let star = Lval (Cil.var (Goblintutil.create_var (makeGlobalVar "*" intType)))
115+
114116
let rec one_unknown_array_index exp =
115117
let rec separate_fields_index o =
116118
match o with
@@ -121,7 +123,6 @@ struct
121123
| Some (osf, ie,o) -> Some ((fun o -> Field (f,o)), ie, o)
122124
| x -> x
123125
in
124-
let star = kinteger64 IInt Goblintutil.inthack in
125126
match exp with
126127
| Lval (Mem (Lval (Var v, io)),o) when conc o ->
127128
begin match separate_fields_index io with
@@ -272,3 +273,44 @@ struct
272273
with Invalid_argument _ -> None
273274
let printXml f (x,y,z) = BatPrintf.fprintf f "<value>\n<map>\n<key>1</key>\n%a<key>2</key>\n%a<key>3</key>\n%a</map>\n</value>\n" Exp.printXml x Exp.printXml y Exp.printXml z
274275
end
276+
277+
(** Index-based symbolic lock *)
278+
module ILock =
279+
struct
280+
281+
(** Index in index-based symbolic lock *)
282+
module Idx =
283+
struct
284+
include Printable.Std
285+
type t =
286+
| Unknown (** Unknown index. Mutex index not synchronized with access index. *)
287+
| Star (** Star index. Mutex index synchronized with access index. Corresponds to star_0 in ASE16 paper, multiple star indices not supported in this implementation. *)
288+
[@@deriving eq, ord, hash]
289+
let name () = "i-lock index"
290+
291+
let show = function
292+
| Unknown -> "?"
293+
| Star -> "*"
294+
295+
include Printable.SimpleShow (
296+
struct
297+
type nonrec t = t
298+
let show = show
299+
end
300+
)
301+
302+
let equal_to _ _ = `Top
303+
let is_int _ = false
304+
end
305+
306+
include Lval.Normal (Idx)
307+
308+
let rec conv_const_offset x =
309+
match x with
310+
| NoOffset -> `NoOffset
311+
| Index (i,o) when Exp.(equal i star) -> `Index (Idx.Star, conv_const_offset o)
312+
| Index (_,o) -> `Index (Idx.Unknown, conv_const_offset o)
313+
| Field (f,o) -> `Field (f, conv_const_offset o)
314+
315+
let from_var_offset (v, o) = from_var_offset (v, conv_const_offset o)
316+
end

src/util/goblintutil.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ let should_warn = ref false
1414
(** Whether signed overflow or underflow happened *)
1515
let svcomp_may_overflow = ref false
1616

17-
(** hack to use a special integer to denote synchronized array-based locking *)
18-
let inthack = Int64.of_int (-19012009) (* TODO do we still need this? *)
19-
2017
(** The file where everything is output *)
2118
let out = ref stdout
2219

0 commit comments

Comments
 (0)