Skip to content

Commit 5a780a6

Browse files
authored
Merge pull request #721 from goblint/access_restart
Option to only destabilize access globals
2 parents 3ab211e + 5cec6c2 commit 5a780a6

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

src/solvers/td3.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ module WP =
131131
(* If true, incremental side-effected var restart will only restart destabilized globals (using hack).
132132
If false, it will restart all destabilized side-effected vars. *)
133133
let restart_only_globals = GobConfig.get_bool "incremental.restart.sided.only-global" in
134+
let restart_only_access = GobConfig.get_bool "incremental.restart.sided.only-access" in
135+
let restart_destab_with_sides = GobConfig.get_bool "incremental.restart.sided.destab-with-sides" in
134136

135137
(* If true, wpoint will be restarted to bot when added.
136138
This allows incremental to avoid reusing and republishing imprecise local values due to globals (which get restarted). *)
@@ -580,7 +582,14 @@ module WP =
580582
let w = HM.find_default side_dep x VS.empty in
581583
HM.remove side_dep x;
582584

583-
if not (VS.is_empty w) && (not restart_only_globals || Node.equal (S.Var.node x) (Function Cil.dummyFunDec)) && not (S.Var.is_write_only x) then (
585+
let should_restart =
586+
if restart_only_access then
587+
S.Var.is_write_only x
588+
else
589+
(not restart_only_globals || Node.equal (S.Var.node x) (Function Cil.dummyFunDec)) && (not (S.Var.is_write_only x))
590+
in
591+
592+
if not (VS.is_empty w) && should_restart then (
584593
(* restart side-effected var *)
585594
restart_leaf x;
586595

@@ -593,7 +602,10 @@ module WP =
593602
if tracing then trace "sol2" "stable remove %a\n" S.Var.pretty_trace y;
594603
HM.remove stable y;
595604
HM.remove superstable y;
596-
destabilize_with_side ~front:false y
605+
if restart_destab_with_sides then
606+
destabilize_with_side ~front:false y
607+
else
608+
destabilize_normal ~front:false y
597609
) w
598610
);
599611

src/util/options.schema.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,18 @@
10501050
"description": "TODO",
10511051
"type": "boolean",
10521052
"default": false
1053+
},
1054+
"only-access" : {
1055+
"title" : "incremental.restart.sided.only-access",
1056+
"description" : "TODO",
1057+
"type" : "boolean",
1058+
"default" : false
1059+
},
1060+
"destab-with-sides": {
1061+
"title" : "incremental.restart.sided.destab-with-sides",
1062+
"description" : "TODO",
1063+
"type" : "boolean",
1064+
"default" : true
10531065
}
10541066
},
10551067
"additionalProperties": false
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Same as 13-restart-write/01-mutex-simple
2+
#include <pthread.h>
3+
#include <stdio.h>
4+
5+
int myglobal;
6+
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
7+
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
8+
9+
void *t_fun(void *arg) {
10+
pthread_mutex_lock(&mutex1);
11+
myglobal=myglobal+1; // RACE!
12+
pthread_mutex_unlock(&mutex1);
13+
return NULL;
14+
}
15+
16+
int main(void) {
17+
pthread_t id;
18+
pthread_create(&id, NULL, t_fun, NULL);
19+
pthread_mutex_lock(&mutex2);
20+
myglobal=myglobal+1; // RACE!
21+
pthread_mutex_unlock(&mutex2);
22+
pthread_join (id, NULL);
23+
return 0;
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"incremental": {
3+
"restart": {
4+
"sided": {
5+
"enabled": true,
6+
"only-access": true,
7+
"destab-with-sides": false
8+
}
9+
}
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--- tests/incremental/11-restart/12-mutex-simple-access.c
2+
+++ tests/incremental/11-restart/12-mutex-simple-access.c
3+
@@ -8,7 +8,7 @@ pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
4+
5+
void *t_fun(void *arg) {
6+
pthread_mutex_lock(&mutex1);
7+
- myglobal=myglobal+1; // RACE!
8+
+ myglobal=myglobal+1; // NORACE
9+
pthread_mutex_unlock(&mutex1);
10+
return NULL;
11+
}
12+
@@ -16,9 +16,9 @@ void *t_fun(void *arg) {
13+
int main(void) {
14+
pthread_t id;
15+
pthread_create(&id, NULL, t_fun, NULL);
16+
- pthread_mutex_lock(&mutex2);
17+
- myglobal=myglobal+1; // RACE!
18+
- pthread_mutex_unlock(&mutex2);
19+
+ pthread_mutex_lock(&mutex1);
20+
+ myglobal=myglobal+1; // NORACE
21+
+ pthread_mutex_unlock(&mutex1);
22+
pthread_join (id, NULL);
23+
return 0;
24+
}

0 commit comments

Comments
 (0)