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

Fix mutex-meet for malloc after thread creation #1492

Merged
merged 4 commits into from
Jul 31, 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/apron/relationPriv.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ struct
in
let get_mutex_inits = getg V.mutex_inits in
let get_mutex_inits' = RD.keep_vars get_mutex_inits [g_var] in
if not (RD.mem_var get_mutex_inits' g_var) then (* TODO: is this just a workaround for an escape bug? https://github.com/goblint/analyzer/pull/1354/files#r1498882657 *)
if RD.mem_var get_mutex_global_g g_var && not (RD.mem_var get_mutex_inits' g_var) then (* TODO: is this just a workaround for an escape bug? https://github.com/goblint/analyzer/pull/1354/files#r1498882657 *)
(* This is an escaped variable whose value was never side-effected to get_mutex_inits' *)
get_mutex_global_g
else
Expand Down
21 changes: 21 additions & 0 deletions tests/regression/46-apron2/90-malloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SKIP PARAM: --set ana.activated[+] apron --set ana.relation.privatization mutex-meet --set ana.apron.domain interval --set sem.int.signed_overflow assume_none
// Checks that assinging to malloc'ed memory does not cause both branches to be dead
#include <pthread.h>
#include <goblint.h>
void nop(void* arg) {
}

void main() {
pthread_t thread;
pthread_create(&thread, 0, &nop, 0);

long *k = malloc(sizeof(long));
*k = 5;
if (1)
;

__goblint_check(*k >= 5); // Reachable and true

*k = *k+1;
__goblint_check(*k >= 5); // Reachable and true
}
21 changes: 21 additions & 0 deletions tests/regression/46-apron2/91-malloc-tid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SKIP PARAM: --set ana.activated[+] apron --set ana.path_sens[+] threadflag --set ana.relation.privatization mutex-meet-tid --set ana.apron.domain interval --set sem.int.signed_overflow assume_none
// Checks that assinging to malloc'ed memory does not cause both branches to be dead
#include <pthread.h>
#include <goblint.h>
void nop(void* arg) {
}

void main() {
pthread_t thread;
pthread_create(&thread, 0, &nop, 0);

long *k = malloc(sizeof(long));
*k = 5;
if (1)
;

__goblint_check(*k >= 5); // Reachable and true

*k = *k+1;
__goblint_check(*k >= 5); // Reachable and true
}
21 changes: 21 additions & 0 deletions tests/regression/46-apron2/92-malloc-atomic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SKIP PARAM: --set ana.activated[+] apron --set ana.relation.privatization mutex-meet-atomic --set ana.apron.domain interval --set sem.int.signed_overflow assume_none
// Checks that assinging to malloc'ed memory does not cause both branches to be dead
#include <pthread.h>
#include <goblint.h>
void nop(void* arg) {
}

void main() {
pthread_t thread;
pthread_create(&thread, 0, &nop, 0);

long *k = malloc(sizeof(long));
*k = 5;
if (1)
;

__goblint_check(*k >= 5); // Reachable and true

*k = *k+1;
__goblint_check(*k >= 5); // Reachable and true
}
Loading