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

Consider Alloca everywhere where Malloc, Calloc and Realloc are handled #1324

Merged
merged 7 commits into from
Jan 29, 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
12 changes: 7 additions & 5 deletions src/analyses/mallocFresh.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ struct

let special ctx lval f args =
let desc = LibraryFunctions.find f in
let alloc_var on_stack =
match ctx.ask (AllocVar {on_stack = on_stack}) with
| `Lifted var -> D.add var ctx.local
| _ -> ctx.local
in
match desc.special args with
| Malloc _
| Calloc _
| Realloc _ ->
begin match ctx.ask (AllocVar {on_stack = false}) with
| `Lifted var -> D.add var ctx.local
| _ -> ctx.local
end
| Realloc _ -> alloc_var false
| Alloca _ -> alloc_var true
| _ ->
match lval with
| None -> ctx.local
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/region.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct
let special ctx (lval: lval option) (f:varinfo) (arglist:exp list) : D.t =
let desc = LibraryFunctions.find f in
match desc.special arglist with
| Malloc _ | Calloc _ | Realloc _ -> begin
| Malloc _ | Calloc _ | Realloc _ | Alloca _ -> begin
match ctx.local, lval with
| `Lifted reg, Some lv ->
let old_regpart = ctx.global () in
Expand Down
1 change: 1 addition & 0 deletions src/util/loopUnrolling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class loopUnrollingCallVisitor = object
| Malloc _
| Calloc _
| Realloc _
| Alloca _
| Lock _
| Unlock _
| ThreadCreate _
Expand Down
27 changes: 27 additions & 0 deletions tests/regression/45-escape/49-fresh-alloca.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// PARAM: --set ana.activated[+] mallocFresh --set ana.activated[-] mhp --set ana.thread.domain plain
#include <pthread.h>
#include <stdlib.h>

pthread_mutex_t A = PTHREAD_MUTEX_INITIALIZER;

void *t_fun2(void *arg) {
int *i = arg;
pthread_mutex_lock(&A);
*i = 10; // NORACE
pthread_mutex_unlock(&A);
return NULL;
}

void *t_fun(void *arg) {
return NULL;
}

int main() {
pthread_t id, id2;
pthread_create(&id, NULL, t_fun, NULL); // enter multithreaded

int *i = alloca(sizeof(int));
*i = 5; // NORACE (fresh)
pthread_create(&id2, NULL, t_fun2, i);
return 0;
}