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

Hack incremental accesses to only restart during postsolving #633

Closed
wants to merge 4 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
2 changes: 1 addition & 1 deletion scripts/test-incremental.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ patch -p0 -b <$patch

./goblint --conf $conf $args --enable incremental.load --set save_run $base/$test-incrementalrun $source &> $base/$test.after.incr.log
./goblint --conf $conf $args --enable incremental.only-rename --set save_run $base/$test-originalrun $source &> $base/$test.after.scratch.log
./goblint --conf $conf --enable solverdiffs --compare_runs $base/$test-originalrun $base/$test-incrementalrun $source
./goblint --conf $conf --disable dbg.compare_runs.glob --enable solverdiffs --compare_runs $base/$test-originalrun $base/$test-incrementalrun $source

patch -p0 -b -R <$patch
rm -r $base/$test-originalrun $base/$test-incrementalrun
1 change: 1 addition & 0 deletions src/analyses/accessAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct
module V =
struct
include Printable.Either (V0) (CilType.Varinfo)
let name () = "access" (* HACK: incremental accesses rely on this! *)
let access x = `Left x
let vars x = `Right x
end
Expand Down
2 changes: 0 additions & 2 deletions src/cdomains/basetype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ struct
| _ -> Local
let name () = "variables"
let printXml f x = BatPrintf.fprintf f "<value>\n<data>\n%s\n</data>\n</value>\n" (XmlUtil.escape (show x))
let var_id _ = "globals"
let node _ = MyCFG.Function Cil.dummyFunDec

let arbitrary () = MyCheck.Arbitrary.varinfo
end
Expand Down
2 changes: 1 addition & 1 deletion src/framework/analyses.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct
let contexts x = `Right x

(* from Basetype.Variables *)
let var_id _ = "globals"
let var_id = show (* HACK: incremental accesses rely on this! *)
let node _ = MyCFG.Function Cil.dummyFunDec
let pretty_trace = pretty
end
Expand Down
19 changes: 16 additions & 3 deletions src/solvers/postSolver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ module Verify: F =
struct
include Unit (S) (VH)

let accs = VH.create 123

let init () =
Goblintutil.verified := Some true
Goblintutil.verified := Some true;
VH.clear accs

let complain_constraint x ~lhs ~rhs =
Goblintutil.verified := Some false;
Expand All @@ -84,8 +87,18 @@ module Verify: F =
ignore (Pretty.printf "Fixpoint not reached at %a\nOrigin: %a\n @[Solver computed:\n%a\nSide-effect:\n%a\nDifference: %a\n@]" S.Var.pretty_trace y S.Var.pretty_trace x S.Dom.pretty lhs S.Dom.pretty rhs S.Dom.pretty_diff (rhs, lhs))

let one_side ~vh ~x ~y ~d =
let y_lhs = try VH.find vh y with Not_found -> S.Dom.bot () in
if not (S.Dom.leq d y_lhs) then
(* HACK: incremental accesses insanity! *)
(* ignore (Pretty.printf "one_side %s: %a\n" (S.Var.var_id y) S.Dom.pretty d); *)
let is_acc = String.starts_with (S.Var.var_id y) "access:" in
let y_lhs =
if is_acc && not (VH.mem accs y) then (
VH.replace accs y ();
S.Dom.bot ()
)
else
try VH.find vh y with Not_found -> S.Dom.bot ()
in
if not is_acc && not (S.Dom.leq d y_lhs) then
Comment on lines +90 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we not still need some special logic to account for side-effects from things that are superstable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. When I later thought about it, I was confused about that too, but it somehow works on all the incremental tests we have.

Maybe this is completely broken after all...

complain_side x y ~lhs:y_lhs ~rhs:d
else
VH.replace vh y (S.Dom.join y_lhs d) (* HACK: allow warnings/accesses to be added *)
Expand Down
23 changes: 23 additions & 0 deletions tests/incremental/11-restart/12-mutex-simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <pthread.h>
#include <stdio.h>

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; // RACE!
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; // RACE!
pthread_mutex_unlock(&mutex2);
pthread_join (id, NULL);
return 0;
}
9 changes: 9 additions & 0 deletions tests/incremental/11-restart/12-mutex-simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"incremental": {
"restart": {
"sided": {
"enabled": false
}
}
}
}
24 changes: 24 additions & 0 deletions tests/incremental/11-restart/12-mutex-simple.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- tests/incremental/11-restart/12-mutex-simple.c
+++ tests/incremental/11-restart/12-mutex-simple.c
@@ -7,7 +7,7 @@ pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;

void *t_fun(void *arg) {
pthread_mutex_lock(&mutex1);
- myglobal=myglobal+1; // RACE!
+ myglobal=myglobal+1; // NORACE
pthread_mutex_unlock(&mutex1);
return NULL;
}
@@ -15,9 +15,9 @@ void *t_fun(void *arg) {
int main(void) {
pthread_t id;
pthread_create(&id, NULL, t_fun, NULL);
- pthread_mutex_lock(&mutex2);
- myglobal=myglobal+1; // RACE!
- pthread_mutex_unlock(&mutex2);
+ pthread_mutex_lock(&mutex1);
+ myglobal=myglobal+1; // NORACE
+ pthread_mutex_unlock(&mutex1);
pthread_join (id, NULL);
return 0;
}