Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check semantic indices of unlocked mutex #1409

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions src/cdomains/lockDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,21 @@ struct
include SetDomain.Reverse(SetDomain.ToppedSet (Lock) (struct let topname = "All mutexes" end))
let name () = "lockset"

let may_be_same_offset of1 of2 =
(* Only reached with definite of2 and indefinite of1. *)
(* TODO: Currently useless, because MayPointTo query doesn't return index offset ranges, so not enough information to ever return false. *)
(* TODO: Use Addr.Offs.semantic_equal. *)
true

let add (addr,rw) set =
match (Addr.to_mval addr) with
| Some (_,x) when Offs.is_definite x -> add (addr,rw) set
| _ -> set

let remove (addr,rw) set =
let collect_diff_varinfo_with (vi,os) (addr,rw) =
match (Addr.to_mval addr) with
| Some (v,o) when CilType.Varinfo.equal vi v -> not (may_be_same_offset o os)
| Some (v,o) -> true
| None -> false
in
match (Addr.to_mval addr) with
| Some (_,x) when Offs.is_definite x -> remove (addr,rw) set
| Some x -> filter (collect_diff_varinfo_with x) set
| _ -> top ()
let add ((addr, _) as lock) set =
match addr with
| Addr.Addr mv when Addr.Mval.is_definite mv -> (* avoids NULL *)
add lock set
| _ ->
set

let remove ((addr, _) as lock) set =
match addr with
| Addr.Addr mv when Addr.Mval.is_definite mv -> (* avoids NULL *)
remove lock set
| _ ->
filter (fun (addr', _) ->
Addr.semantic_equal addr addr' = Some false
) set

let export_locks ls =
let f (x,_) set = Mutexes.add x set in
Expand Down
7 changes: 3 additions & 4 deletions tests/regression/05-lval_ls/19-idxunknown_unlock_precise.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// PARAM: --enable ana.int.interval
// TODO because queries don't pass lvalue index intervals
// PARAM: --enable ana.int.interval --enable ana.sv-comp.functions
extern int __VERIFIER_nondet_int();
extern void abort(void);
void assume_abort_if_not(int cond) {
Expand All @@ -15,7 +14,7 @@ pthread_mutex_t m[10];

void *t_fun(void *arg) {
pthread_mutex_lock(&m[4]);
data++; // TODO NORACE
data++; // NORACE
pthread_mutex_unlock(&m[4]);
return NULL;
}
Expand All @@ -33,7 +32,7 @@ int main() {
pthread_create(&id, NULL, t_fun, NULL);
pthread_mutex_lock(&m[4]);
pthread_mutex_unlock(&m[i]); // no UB because ERRORCHECK
data++; // TODO NORACE
data++; // NORACE
pthread_mutex_unlock(&m[4]);
return 0;
}
Expand Down
Loading