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 5 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
3 changes: 2 additions & 1 deletion src/analyses/mallocFresh.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ struct
match desc.special args with
| Malloc _
| Calloc _
| Realloc _ ->
| Realloc _
| Alloca _ ->
sim642 marked this conversation as resolved.
Show resolved Hide resolved
begin match ctx.ask (AllocVar {on_stack = false}) with
| `Lifted var -> D.add var ctx.local
| _ -> ctx.local
Expand Down
3 changes: 2 additions & 1 deletion src/analyses/memLeak.ml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ struct
match desc.special arglist with
| Malloc _
| Calloc _
| Realloc _ ->
| Realloc _
| Alloca _ ->
karoliineh marked this conversation as resolved.
Show resolved Hide resolved
ctx.sideg () true;
begin match ctx.ask (Queries.AllocVar {on_stack = false}) with
| `Lifted var ->
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;
}