Skip to content

Commit

Permalink
Merge pull request #707 from goblint/unknown-invalidate-args
Browse files Browse the repository at this point in the history
Add option sem.unknown_function.invalidate.args
  • Loading branch information
sim642 authored May 3, 2022
2 parents 9ee1de1 + f608b19 commit fb54fa5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/analyses/accessAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,14 @@ struct
ctx.local
| _, x ->
let arg_acc act =
match LF.get_threadsafe_inv_ac x with
| Some fnc -> (fnc act arglist)
| _ -> arglist
match act, LF.get_threadsafe_inv_ac x with
| _, Some fnc -> (fnc act arglist)
| `Read, None -> arglist
| (`Write | `Free), None ->
if get_bool "sem.unknown_function.invalidate.args" then
arglist
else
[]
in
(* TODO: per-argument reach *)
let reach =
Expand Down
1 change: 1 addition & 0 deletions src/analyses/apron/apronAnalysis.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ struct
let st' = match LibraryFunctions.get_invalidate_action f.vname with
| Some fnc -> st (* nothing to do because only AddrOf arguments may be invalidated *)
| None ->
(* nothing to do for args because only AddrOf arguments may be invalidated *)
if GobConfig.get_bool "sem.unknown_function.invalidate.globals" then (
let globals = foldGlobals !Cilfacade.current_file (fun acc global ->
match global with
Expand Down
10 changes: 8 additions & 2 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,12 @@ struct
let special_unknown_invalidate ctx ask gs st f args =
(if not (CilType.Varinfo.equal f dummyFunDec.svar) && not (LF.use_special f.vname) then M.error ~category:Imprecise ~tags:[Category Unsound] "Function definition missing for %s" f.vname);
(if CilType.Varinfo.equal f dummyFunDec.svar then M.warn "Unknown function ptr called");
let addrs =
if get_bool "sem.unknown_function.invalidate.args" then
args
else
[]
in
let addrs =
if get_bool "sem.unknown_function.invalidate.globals" then (
M.info ~category:Imprecise "INVALIDATING ALL GLOBALS!";
Expand All @@ -2092,10 +2098,10 @@ struct
mkAddrOf (Var vi, NoOffset) :: acc
(* TODO: what about GVarDecl? *)
| _ -> acc
) args
) addrs
)
else
args
addrs
in
(* TODO: what about escaped local variables? *)
(* invalidate arguments and non-static globals for unknown functions *)
Expand Down
8 changes: 6 additions & 2 deletions src/analyses/symbLocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct
| `Unknown fn when VarEq.safe_fn fn ->
Messages.warn "Assume that %s does not change lockset." fn;
ctx.local
| `Unknown x -> begin
| `Unknown x -> begin (* TODO: _ ? *)
let st =
match lval with
| Some lv -> invalidate_lval (Analyses.ask_of_ctx ctx) lv ctx.local
Expand All @@ -94,7 +94,11 @@ struct
let write_args =
match LF.get_invalidate_action f.vname with
| Some fnc -> fnc `Write arglist
| _ -> arglist
| None ->
if GobConfig.get_bool "sem.unknown_function.invalidate.args" then
arglist
else
[]
in
List.fold_left (fun st e -> invalidate_exp (Analyses.ask_of_ctx ctx) e st) st write_args
end
Expand Down
6 changes: 5 additions & 1 deletion src/analyses/varEq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ struct
let args =
match LF.get_invalidate_action f.vname with
| Some fnc -> fnc `Write args
| _ -> args
| None ->
if GobConfig.get_bool "sem.unknown_function.invalidate.args" then
args
else
[]
in
let es =
match lval with
Expand Down
7 changes: 7 additions & 0 deletions src/util/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,13 @@
"Unknown function call invalidates all globals",
"type": "boolean",
"default": true
},
"args": {
"title": "sem.unknown_function.invalidate.args",
"description":
"Unknown function call invalidates arguments passed to it",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
Expand Down

0 comments on commit fb54fa5

Please sign in to comment.