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

Exclude free-free accesses from racing #1193

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 7 additions & 9 deletions src/domains/access.ml
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,14 @@ struct
end


(* Check if two accesses may race and if yes with which confidence *)
(** Check if two accesses may race. *)
let may_race A.{kind; acc; _} A.{kind=kind2; acc=acc2; _} =
if kind = Read && kind2 = Read then
false (* two read/read accesses do not race *)
else if not (get_bool "ana.race.free") && (kind = Free || kind2 = Free) then
false
else if not (MCPAccess.A.may_race acc acc2) then
false (* analysis-specific information excludes race *)
else
true
match kind, kind2 with
| Read, Read -> false (* two read/read accesses do not race *)
| Free, Free -> false (* two free/free accesses do not race *)
| Free, _
| _, Free when not (get_bool "ana.race.free") -> false
| _, _ -> MCPAccess.A.may_race acc acc2 (* analysis-specific information excludes race *)

(** Access sets for race detection and warnings. *)
module WarnAccs =
Expand Down
2 changes: 1 addition & 1 deletion src/util/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@
"properties": {
"free": {
"title": "ana.race.free",
"description": "Consider memory free as racing write.",
"description": "Consider memory free as racing with read or write (but not another free).",
"type": "boolean",
"default": true
},
Expand Down
14 changes: 13 additions & 1 deletion tests/regression/04-mutex/64-free_direct_rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ void *t_fun(void *arg) {
return NULL;
}

void *t_fun2(void *arg) {
int *p = (int *) arg;
free(p); // NORACE
return NULL;
}

int main(void) {
pthread_t id;
int *p = malloc(sizeof(int));
int *p;
p = malloc(sizeof(int));
pthread_create(&id, NULL, t_fun, (void *) p);
free(p); // RACE!
pthread_join (id, NULL);

p = malloc(sizeof(int));
pthread_create(&id, NULL, t_fun2, (void *) p);
free(p); // NORACE
pthread_join (id, NULL);
return 0;
}