@@ -178,12 +178,22 @@ struct
178178 type field = fieldinfo
179179 type idx = Idx .t
180180 module Offs = OffsetPrintable (Idx )
181+
181182 type t =
182183 | Addr of CilType.Varinfo .t * Offs .t (* * Pointer to offset of a variable. *)
183184 | NullPtr (* * NULL pointer. *)
184185 | UnknownPtr (* * Unknown pointer. Could point to globals, heap and escaped variables. *)
185- | StrPtr of string (* * String literal pointer. *)
186+ | StrPtr of string option (* * String literal pointer. [StrPtr None] abstracts any string pointer *)
186187 [@@ deriving eq , ord , hash ] (* TODO: StrPtr equal problematic if the same literal appears more than once *)
188+
189+ let hash x = match x with
190+ | StrPtr _ ->
191+ if GobConfig. get_bool " ana.base.limit-string-addresses" then
192+ 13859
193+ else
194+ hash x
195+ | _ -> hash x
196+
187197 include Printable. Std
188198 let name () = " Normal Lvals"
189199
@@ -210,9 +220,9 @@ struct
210220 | _ -> None
211221
212222 (* strings *)
213- let from_string x = StrPtr x
223+ let from_string x = StrPtr ( Some x)
214224 let to_string = function
215- | StrPtr x -> Some x
225+ | StrPtr (Some x ) -> Some x
216226 | _ -> None
217227
218228 let rec short_offs = function
@@ -228,7 +238,8 @@ struct
228238
229239 let show = function
230240 | Addr (x , o )-> short_addr (x, o)
231- | StrPtr x -> " \" " ^ x ^ " \" "
241+ | StrPtr (Some x ) -> " \" " ^ x ^ " \" "
242+ | StrPtr None -> " (unknown string)"
232243 | UnknownPtr -> " ?"
233244 | NullPtr -> " NULL"
234245
@@ -277,7 +288,8 @@ struct
277288 in
278289 match x with
279290 | Addr (v ,o ) -> AddrOf (Var v, to_cil o)
280- | StrPtr x -> mkString x
291+ | StrPtr (Some x ) -> mkString x
292+ | StrPtr None -> raise (Lattice. Unsupported " Cannot express unknown string pointer as expression." )
281293 | NullPtr -> integer 0
282294 | UnknownPtr -> raise Lattice. TopValue
283295 let rec add_offsets x y = match x with
@@ -303,24 +315,46 @@ struct
303315 module Offs = Offset (Idx )
304316
305317 let is_definite = function
306- | NullPtr | StrPtr _ -> true
318+ | NullPtr -> true
307319 | Addr (v ,o ) when Offs. is_definite o -> true
308320 | _ -> false
309321
310322 let leq x y = match x, y with
311- | StrPtr a , StrPtr b -> a = b
323+ | StrPtr _ , StrPtr None -> true
324+ | StrPtr a , StrPtr b -> a = b
312325 | Addr (x ,o ), Addr (y ,u ) -> CilType.Varinfo. equal x y && Offs. leq o u
313326 | _ -> x = y
314327
315328 let drop_ints = function
316329 | Addr (x , o ) -> Addr (x, Offs. drop_ints o)
317330 | x -> x
318331
332+ let join_string_ptr x y = match x, y with
333+ | None , _
334+ | _ , None -> None
335+ | Some a , Some b when a = b -> Some a
336+ | Some a , Some b (* when a <> b *) ->
337+ if GobConfig. get_bool " ana.base.limit-string-addresses" then
338+ None
339+ else
340+ raise Lattice. Uncomparable
341+
342+ let meet_string_ptr x y = match x, y with
343+ | None , a
344+ | a , None -> a
345+ | Some a , Some b when a = b -> Some a
346+ | Some a , Some b (* when a <> b *) -> raise Lattice. Uncomparable
347+
319348 let merge cop x y =
320349 match x, y with
321350 | UnknownPtr , UnknownPtr -> UnknownPtr
322351 | NullPtr , NullPtr -> NullPtr
323- | StrPtr a , StrPtr b when a= b -> StrPtr a
352+ | StrPtr a , StrPtr b ->
353+ StrPtr
354+ begin match cop with
355+ | `Join | `Widen -> join_string_ptr a b
356+ | `Meet | `Narrow -> meet_string_ptr a b
357+ end
324358 | Addr (x ,o ), Addr (y ,u ) when CilType.Varinfo. equal x y -> Addr (x, Offs. merge cop o u)
325359 | _ -> raise Lattice. Uncomparable
326360
0 commit comments