Skip to content

Commit 22276ad

Browse files
author
ge46lup
committed
mallocFresh
1 parent 26c3dc6 commit 22276ad

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/analyses/mallocFresh.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ struct
99
include Analyses.IdentitySpec
1010

1111
(* must fresh variables *)
12-
module D = SetDomain.Reverse (SetDomain.ToppedSet (CilType.Varinfo) (struct let topname = "All variables" end)) (* need bot (top) for hoare widen *)
12+
(*module D = SetDomain.Reverse (SetDomain.ToppedSet (CilType.Varinfo) (struct let topname = "All variables" end)) (* need bot (top) for hoare widen *)
13+
*)
14+
module D = SetDomain.ToppedSet (CilType.Varinfo) (struct let topname = "All variables" end)
15+
16+
17+
1318
module C = D
1419

1520
let name () = "mallocFresh"
@@ -21,7 +26,12 @@ struct
2126
match ask.f (MayPointTo (AddrOf lval)) with
2227
| ad when Queries.AD.is_top ad -> D.empty ()
2328
| ad when Queries.AD.exists (function
24-
| Queries.AD.Addr.Addr (v,_) -> not (D.mem v local) && (v.vglob || ThreadEscape.has_escaped ask v)
29+
(*| Queries.AD.Addr.Addr (v,_) -> not (D.mem v local) && (v.vglob || ThreadEscape.has_escaped ask v)*)
30+
| Queries.AD.Addr.Addr (v,_) ->
31+
if D.mem (v, false) local then
32+
D.add (v, true) local (* Invalidate the variable *)
33+
else
34+
local
2535
| _ -> false
2636
) ad -> D.empty ()
2737
| _ -> local

src/common/util/cilfacade0.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ let get_instrLoc = function
3030
| Set (_, _, loc, eloc) -> eloc_fallback ~eloc ~loc
3131
| Call (_, _, _, loc, eloc) -> eloc_fallback ~eloc ~loc
3232
| VarDecl (_, loc) -> loc
33+
3334

3435
(** Get expression location for [Cil.stmt]. *)
3536
(* confusingly CIL.get_stmtLoc works on stmtkind instead *)

tests/practical/test_file

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
void allocateMemory() {
5+
int *ptr = malloc(sizeof(int));
6+
7+
if (ptr != NULL) {
8+
*ptr = 42;
9+
10+
// Your code that uses 'ptr'
11+
12+
printf("Value: %d\n", *ptr);
13+
14+
free(ptr);
15+
} else {
16+
fprintf(stderr, "Memory allocation failed.\n");
17+
}
18+
}
19+
20+
int main() {
21+
allocateMemory();
22+
23+
// Additional code if needed
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)