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

Ignore atomic types in race detection #540

Merged
merged 1 commit into from
Jan 17, 2022
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
7 changes: 4 additions & 3 deletions src/domains/access.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ module M = Messages

let is_ignorable_type (t: typ): bool =
match t with
| TNamed (info, attr) -> info.tname = "atomic_t" || info.tname = "pthread_mutex_t" || info.tname = "spinlock_t"
| TComp (info, attr) -> info.cname = "lock_class_key"
| TInt (IInt, attr) -> hasAttribute "mutex" attr
| TNamed ({ tname = "atomic_t" | "pthread_mutex_t" | "spinlock_t"; _ }, _) -> true
| TComp ({ cname = "lock_class_key"; _ }, _) -> true
| TInt (IInt, attr) when hasAttribute "mutex" attr -> true
| t when hasAttribute "atomic" (typeAttrs t) -> true (* C11 _Atomic *)
| _ -> false

let is_ignorable = function
Expand Down
24 changes: 24 additions & 0 deletions tests/regression/04-mutex/62-simple_atomic_nr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <pthread.h>
#include <stdio.h>
#include <stdatomic.h>

atomic_int myglobal;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;

void *t_fun(void *arg) {
pthread_mutex_lock(&mutex1);
myglobal=myglobal+1; // NORACE
pthread_mutex_unlock(&mutex1);
return NULL;
}

int main(void) {
pthread_t id;
pthread_create(&id, NULL, t_fun, NULL);
pthread_mutex_lock(&mutex2);
myglobal=myglobal+1; // NORACE
pthread_mutex_unlock(&mutex2);
pthread_join (id, NULL);
return 0;
}