Skip to content

Commit

Permalink
Add get_unknownptrs and has_unknownptr and use remove_unknownptrs ins…
Browse files Browse the repository at this point in the history
…tead of remove
  • Loading branch information
karoliineh committed Nov 21, 2023
1 parent b03e5bc commit d5a81da
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1325,10 +1325,11 @@ struct
| Bot -> Queries.Result.bot q (* TODO: remove *)
| Address a ->
let a' = AD.remove_unknownptrs a in (* run reachable_vars without unknown just to be safe: TODO why? *)
let u = AD.get_unknownptrs a in
let addrs = reachable_vars (Analyses.ask_of_ctx ctx) [a'] ctx.global ctx.local in
let addrs' = List.fold_left (AD.join) (AD.empty ()) addrs in
if AD.may_be_unknown a then
AD.add UnknownPtr addrs' (* add unknown back *)
AD.union u addrs' (* add unknowns back *)
else
addrs'
| Int i ->
Expand Down
4 changes: 2 additions & 2 deletions src/analyses/condVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ struct

let mayPointTo ctx exp =
let ad = ctx.ask (Queries.MayPointTo exp) in
let a' = if Queries.AD.mem UnknownPtr ad then (
let a' = if Queries.AD.has_unknownptr ad then (
M.info ~category:Unsound "mayPointTo: query result for %a contains TOP!" d_exp exp; (* UNSOUND *)
Queries.AD.remove UnknownPtr ad
Queries.AD.remove_unknownptrs ad
) else ad
in
List.filter_map (function
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/extractPthread.ml
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ module Spec : Analyses.MCPSpec = struct
module ExprEval = struct
let eval_ptr ctx exp =
ctx.ask (Queries.MayPointTo exp)
|> Queries.AD.remove UnknownPtr (* UNSOUND *)
|> Queries.AD.remove_unknownptrs (* UNSOUND *)
|> Queries.AD.to_var_may

let eval_var ctx exp =
Expand Down
12 changes: 12 additions & 0 deletions src/cdomains/addressDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ struct
| UnknownPtr _ -> false
| _ -> true
) ad

let get_unknownptrs ad = filter (function
| UnknownPtr _ -> true
| _ -> false
) ad

let has_unknownptr ad = fold (fun a acc ->
match a with
| UnknownPtr _ -> true
| _ -> acc
) ad false

let unknownptrs_origins doc ad =
fold (fun addr acc ->
match addr with
Expand Down
2 changes: 2 additions & 0 deletions src/cdomains/addressDomain_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ sig
val string_comparison: t -> t -> int option -> ID.t
val string_writing_defined: t -> bool
val remove_unknownptrs: t -> t
val get_unknownptrs: t -> t
val has_unknownptr: t -> bool
val unknownptrs_origins: GoblintCil.Pretty.doc -> t -> (GoblintCil.Pretty.doc * Messages.Location.t option) list
end
end

0 comments on commit d5a81da

Please sign in to comment.