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

BaseAnalysis: For non-definite AD, join over **all** components not just cpa in set #1458

Merged
merged 3 commits into from
May 15, 2024
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
2 changes: 1 addition & 1 deletion src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ struct
(* if M.tracing then M.tracel "set" ~var:firstvar "new state1 %a" CPA.pretty nst; *)
(* If the address was definite, then we just return it. If the address
* was ambiguous, we have to join it with the initial state. *)
let nst = if AD.cardinal lval > 1 then { nst with cpa = CPA.join st.cpa nst.cpa } else nst in
let nst = if AD.cardinal lval > 1 then D.join st nst else nst in
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved
(* if M.tracing then M.tracel "set" ~var:firstvar "new state2 %a" CPA.pretty nst; *)
nst
with
Expand Down
54 changes: 54 additions & 0 deletions tests/regression/13-privatized/80-nondet-struct-ptr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// PARAM: --set ana.base.privatization protection --enable ana.int.enums
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

struct a *ptr;
struct a *straightandnarrow;

pthread_mutex_t m;

void doit() {
void *newa = malloc(sizeof(struct a));

pthread_mutex_lock(&m);
ptr->b = 5;

int fear = straightandnarrow->b;
__goblint_check(fear == 5); //UNKNOWN!

ptr = newa;
pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
int hope = straightandnarrow->b;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
doit();
return NULL;
}

int main() {
int top;
struct a other = { 0 };
struct a other2 = { 42 };
if(top) {
ptr = &other;
} else {
ptr = &other2;
}

straightandnarrow = &other;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
55 changes: 55 additions & 0 deletions tests/regression/13-privatized/81-nondet-local-pointer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// PARAM: --set ana.base.privatization protection --enable ana.int.enums
// Like 80-nondet-struct-ptr.c, but somewhat simplified to not use structs and malloc etc
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

int *ptr;
int *immer_da_oane;

pthread_mutex_t m;

void doit() {
pthread_mutex_lock(&m);
*ptr = 5;

// Should be either 5 or 0, depending on which one the pointer points to
int fear = *immer_da_oane;
__goblint_check(fear == 5); //UNKNOWN!

pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
int hope = *immer_da_oane;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
// Force MT
return NULL;
}

int main() {
int top;

int da_oane = 0;
int de_andre = 42;

if(top) {
ptr = &da_oane;
} else {
ptr = &de_andre;
}

immer_da_oane = &da_oane;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
56 changes: 56 additions & 0 deletions tests/regression/13-privatized/82-nondet-global-pointer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// PARAM: --set ana.base.privatization protection --enable ana.int.enums
// Like 81-nondet-struct-ptr.c, but with syntactic globals instead of escaping ones.
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

int *ptr;
int *immer_da_oane;

int da_oane = 0;
int de_andre = 42;

pthread_mutex_t m;

void doit() {
pthread_mutex_lock(&m);
*ptr = 5;

// Should be either 0 or 5, depending on which one ptr points to
int fear = *immer_da_oane;
__goblint_check(fear == 5); //UNKNOWN!

pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
// This works
int hope = *immer_da_oane;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
// Force MT
return NULL;
}

int main() {
int top;

if(top) {
ptr = &da_oane;
} else {
ptr = &de_andre;
}

immer_da_oane = &da_oane;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
54 changes: 54 additions & 0 deletions tests/regression/13-privatized/83-nondet-struct-ptr-write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// PARAM: --set ana.base.privatization write --enable ana.int.enums
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

struct a *ptr;
struct a *straightandnarrow;

pthread_mutex_t m;

void doit() {
void *newa = malloc(sizeof(struct a));

pthread_mutex_lock(&m);
ptr->b = 5;

int fear = straightandnarrow->b;
__goblint_check(fear == 5); //UNKNOWN!

ptr = newa;
pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
int hope = straightandnarrow->b;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
doit();
return NULL;
}

int main() {
int top;
struct a other = { 0 };
struct a other2 = { 42 };
if(top) {
ptr = &other;
} else {
ptr = &other2;
}

straightandnarrow = &other;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
54 changes: 54 additions & 0 deletions tests/regression/13-privatized/84-nondet-local-pointer-write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// PARAM: --set ana.base.privatization write --enable ana.int.enums
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

int *ptr;
int *immer_da_oane;

pthread_mutex_t m;

void doit() {
pthread_mutex_lock(&m);
*ptr = 5;

// Should be either 5 or 0, depending on which one the pointer points to
int fear = *immer_da_oane;
__goblint_check(fear == 5); //UNKNOWN!

pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
int hope = *immer_da_oane;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
// Force MT
return NULL;
}

int main() {
int top;

int da_oane = 0;
int de_andre = 42;

if(top) {
ptr = &da_oane;
} else {
ptr = &de_andre;
}

immer_da_oane = &da_oane;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
55 changes: 55 additions & 0 deletions tests/regression/13-privatized/85-nondet-global-pointer-write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// PARAM: --set ana.base.privatization write --enable ana.int.enums
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

int *ptr;
int *immer_da_oane;

int da_oane = 0;
int de_andre = 42;

pthread_mutex_t m;

void doit() {
pthread_mutex_lock(&m);
*ptr = 5;

// Should be either 0 or 5, depending on which one ptr points to
int fear = *immer_da_oane;
__goblint_check(fear == 5); //UNKNOWN!

pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
// This works
int hope = *immer_da_oane;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
// Force MT
return NULL;
}

int main() {
int top;

if(top) {
ptr = &da_oane;
} else {
ptr = &de_andre;
}

immer_da_oane = &da_oane;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
54 changes: 54 additions & 0 deletions tests/regression/13-privatized/86-nondet-struct-ptr-lock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// PARAM: --set ana.base.privatization lock --enable ana.int.enums
#include<pthread.h>
#include<stdlib.h>
struct a {
int b;
};

struct a *ptr;
struct a *straightandnarrow;

pthread_mutex_t m;

void doit() {
void *newa = malloc(sizeof(struct a));

pthread_mutex_lock(&m);
ptr->b = 5;

int fear = straightandnarrow->b;
__goblint_check(fear == 5); //UNKNOWN!

ptr = newa;
pthread_mutex_unlock(&m);

pthread_mutex_lock(&m);
int hope = straightandnarrow->b;
__goblint_check(hope == 5); //UNKNOWN!
pthread_mutex_unlock(&m);

}

void* k(void *arg) {
doit();
return NULL;
}

int main() {
int top;
struct a other = { 0 };
struct a other2 = { 42 };
if(top) {
ptr = &other;
} else {
ptr = &other2;
}

straightandnarrow = &other;

pthread_t t1;
pthread_create(&t1, 0, k, 0);

doit();
return 0;
}
Loading
Loading