Skip to content
This repository was archived by the owner on Oct 3, 2021. It is now read-only.

Commit 4eb3b2c

Browse files
committed
Port undefined behavior fixes from #1164 to goblint-regression races-as-reachability benchmarks
1 parent 70a578a commit 4eb3b2c

28 files changed

+94
-24
lines changed

c/goblint-regression/28-race_reach_23-sound_unlock_racing.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include "racemacros.h"
33

44
int global = 0;
5-
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
6-
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
5+
pthread_mutexattr_t mutexattr;
6+
pthread_mutex_t mutex1;
7+
pthread_mutex_t mutex2;
78

89
void *t_fun(void *arg) {
910
pthread_mutex_lock(&mutex1);
@@ -13,14 +14,19 @@ void *t_fun(void *arg) {
1314
}
1415

1516
int main(void) {
17+
pthread_mutexattr_init(&mutexattr);
18+
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
19+
pthread_mutex_init(&mutex1, &mutexattr);
20+
pthread_mutex_init(&mutex2, &mutexattr);
21+
1622
int i = __VERIFIER_nondet_int();
1723
pthread_mutex_t *m = &mutex1;
1824
if (i) m = &mutex2;
1925
create_threads(t);
2026
pthread_mutex_lock(&mutex1);
21-
pthread_mutex_unlock(m);
27+
pthread_mutex_unlock(m); // no UB because ERRORCHECK
2228
assert_racefree(global); // UNKNOWN
23-
pthread_mutex_unlock(&mutex1);
29+
pthread_mutex_unlock(&mutex1); // no UB because ERRORCHECK
2430
join_threads(t);
2531
return 0;
2632
}

c/goblint-regression/28-race_reach_23-sound_unlock_racing.i

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,20 @@ void assume_abort_if_not(int cond) {
688688
}
689689
pthread_mutex_t __global_lock = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
690690
int global = 0;
691-
pthread_mutex_t mutex1 = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
692-
pthread_mutex_t mutex2 = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
691+
pthread_mutexattr_t mutexattr;
692+
pthread_mutex_t mutex1;
693+
pthread_mutex_t mutex2;
693694
void *t_fun(void *arg) {
694695
pthread_mutex_lock(&mutex1);
695696
do { do { pthread_mutex_lock(&__global_lock); (global)++; pthread_mutex_unlock(&__global_lock); } while (0); do { pthread_mutex_lock(&__global_lock); (global)--; pthread_mutex_unlock(&__global_lock); } while (0); } while (0);
696697
pthread_mutex_unlock(&mutex1);
697698
return ((void *)0);
698699
}
699700
int main(void) {
701+
pthread_mutexattr_init(&mutexattr);
702+
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
703+
pthread_mutex_init(&mutex1, &mutexattr);
704+
pthread_mutex_init(&mutex2, &mutexattr);
700705
int i = __VERIFIER_nondet_int();
701706
pthread_mutex_t *m = &mutex1;
702707
if (i) m = &mutex2;

c/goblint-regression/28-race_reach_36-indirect_racefree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1010
void *t_fun(void *arg) {
1111
pthread_mutex_lock(&mutex);
1212
access(*g1);
13-
pthread_mutex_lock(&mutex);
13+
pthread_mutex_unlock(&mutex);
1414
return NULL;
1515
}
1616

@@ -20,7 +20,7 @@ int main(void) {
2020
create_threads(t);
2121
pthread_mutex_lock(&mutex);
2222
assert_racefree(*g2);
23-
pthread_mutex_lock(&mutex);
23+
pthread_mutex_unlock(&mutex);
2424
join_threads(t);
2525
return 0;
2626
}

c/goblint-regression/28-race_reach_36-indirect_racefree.i

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,15 @@ pthread_mutex_t mutex = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
694694
void *t_fun(void *arg) {
695695
pthread_mutex_lock(&mutex);
696696
do { do { pthread_mutex_lock(&__global_lock); (*g1)++; pthread_mutex_unlock(&__global_lock); } while (0); do { pthread_mutex_lock(&__global_lock); (*g1)--; pthread_mutex_unlock(&__global_lock); } while (0); } while (0);
697-
pthread_mutex_lock(&mutex);
697+
pthread_mutex_unlock(&mutex);
698698
return ((void *)0);
699699
}
700700
int main(void) {
701701
g1 = g2 = &g;
702702
pthread_t t_ids[10000]; for (int i=0; i<10000; i++) pthread_create(&t_ids[i], ((void *)0), t_fun, ((void *)0));
703703
pthread_mutex_lock(&mutex);
704704
do { pthread_mutex_lock(&__global_lock); __VERIFIER_assert((*g2) == 0); pthread_mutex_unlock(&__global_lock); } while (0);
705-
pthread_mutex_lock(&mutex);
705+
pthread_mutex_unlock(&mutex);
706706
for (int i=0; i < 10000; i++) pthread_join (t_ids[i], ((void *)0));
707707
return 0;
708708
}

c/goblint-regression/28-race_reach_37-indirect_racing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1010
void *t_fun(void *arg) {
1111
pthread_mutex_lock(&mutex);
1212
access(*g1);
13-
pthread_mutex_lock(&mutex);
13+
pthread_mutex_unlock(&mutex);
1414
return NULL;
1515
}
1616

c/goblint-regression/28-race_reach_37-indirect_racing.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ pthread_mutex_t mutex = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
694694
void *t_fun(void *arg) {
695695
pthread_mutex_lock(&mutex);
696696
do { do { pthread_mutex_lock(&__global_lock); (*g1)++; pthread_mutex_unlock(&__global_lock); } while (0); do { pthread_mutex_lock(&__global_lock); (*g1)--; pthread_mutex_unlock(&__global_lock); } while (0); } while (0);
697-
pthread_mutex_lock(&mutex);
697+
pthread_mutex_unlock(&mutex);
698698
return ((void *)0);
699699
}
700700
int main(void) {

c/goblint-regression/28-race_reach_40-trylock_racing.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#include "racemacros.h"
33

44
int global;
5-
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
5+
pthread_mutexattr_t mutexattr;
6+
pthread_mutex_t mutex;
67

78
void *t_fun(void *arg) {
89
pthread_mutex_lock(&mutex);
@@ -13,11 +14,15 @@ void *t_fun(void *arg) {
1314
}
1415

1516
int main(void) {
17+
pthread_mutexattr_init(&mutexattr);
18+
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
19+
pthread_mutex_init(&mutex, &mutexattr);
20+
1621
create_threads(t);
1722

1823
pthread_mutex_trylock(&mutex);
1924
assert_racefree(global); // UNKNOWN
20-
pthread_mutex_unlock(&mutex);
25+
pthread_mutex_unlock(&mutex); // no UB because ERRORCHECK
2126
join_threads(t);
2227
return 0;
2328
}

c/goblint-regression/28-race_reach_40-trylock_racing.i

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,18 @@ void assume_abort_if_not(int cond) {
688688
}
689689
pthread_mutex_t __global_lock = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
690690
int global;
691-
pthread_mutex_t mutex = { { 0, 0, 0, 0, 0, { { 0, 0 } } } };
691+
pthread_mutexattr_t mutexattr;
692+
pthread_mutex_t mutex;
692693
void *t_fun(void *arg) {
693694
pthread_mutex_lock(&mutex);
694695
do { do { pthread_mutex_lock(&__global_lock); (global)++; pthread_mutex_unlock(&__global_lock); } while (0); do { pthread_mutex_lock(&__global_lock); (global)--; pthread_mutex_unlock(&__global_lock); } while (0); } while (0);
695696
pthread_mutex_unlock(&mutex);
696697
return ((void *)0);
697698
}
698699
int main(void) {
700+
pthread_mutexattr_init(&mutexattr);
701+
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
702+
pthread_mutex_init(&mutex, &mutexattr);
699703
pthread_t t_ids[10000]; for (int i=0; i<10000; i++) pthread_create(&t_ids[i], ((void *)0), t_fun, ((void *)0));
700704
pthread_mutex_trylock(&mutex);
701705
do { pthread_mutex_lock(&__global_lock); __VERIFIER_assert((global) == 0); pthread_mutex_unlock(&__global_lock); } while (0);

c/goblint-regression/28-race_reach_70-funloop_racefree.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ void *t_fun(void *arg) {
2121
}
2222

2323
int main () {
24+
for (int i = 0; i < 10; i++)
25+
pthread_mutex_init(&cache[i].refs_mutex, NULL);
26+
2427
int i;
2528
create_threads(t);
2629

c/goblint-regression/28-race_reach_70-funloop_racefree.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ void *t_fun(void *arg) {
941941
return ((void *)0);
942942
}
943943
int main () {
944+
for (int i = 0; i < 10; i++)
945+
pthread_mutex_init(&cache[i].refs_mutex, ((void *)0));
944946
int i;
945947
pthread_t t_ids[10000]; for (int i=0; i<10000; i++) pthread_create(&t_ids[i], ((void *)0), t_fun, ((void *)0));
946948
for(i=0; i<10; i++)

0 commit comments

Comments
 (0)