Skip to content
Snippets Groups Projects
Commit aae0f70b authored by Basile Desloges's avatar Basile Desloges
Browse files

[eacsl] Fix memory tracking of VLA

- Remove the renaming of Frama-C built-ins in the injector since the
  code printer is now responsible for it;
- Explicitely add calls to `store_block` (resp. `delete_block`) when
  allocating (resp. deallocating) a VLA.
parent 75945fff
No related branches found
No related tags found
No related merge requests found
...@@ -59,17 +59,7 @@ let rec inject_in_init env kf_opt vi off = function ...@@ -59,17 +59,7 @@ let rec inject_in_init env kf_opt vi off = function
let inject_in_local_init loc env kf vi = function let inject_in_local_init loc env kf vi = function
| ConsInit (fvi, sz :: _, _) as init | ConsInit (fvi, sz :: _, _) as init
when Functions.Libc.is_vla_alloc_name fvi.vname -> when Functions.Libc.is_vla_alloc_name fvi.vname ->
(* handle variable-length array allocation via [__fc_vla_alloc]. Here each (* add a store statement when creating a variable length array *)
instance of [__fc_vla_alloc] is rewritten to [alloca] (that is used to
implement VLA) and further a custom call to [store_block] tracking VLA
allocation is issued. *)
(* KV: do not add handling [alloca] allocation here (or anywhere else for
that matter). Handling of [alloca] should be implemented in Frama-C
(eventually). This is such that each call to [alloca] becomes
[__fc_vla_alloc]. It is already handled using the code below. *)
fvi.vname <- Functions.Libc.actual_alloca;
(* Since we need to pass [vi] by value, cannot use [Misc.mk_store_stmt]
here. Do it manually. *)
let store = Constructor.mk_store_stmt ~str_size:sz vi in let store = Constructor.mk_store_stmt ~str_size:sz vi in
let env = Env.add_stmt ~post:true env kf store in let env = Env.add_stmt ~post:true env kf store in
init, env init, env
...@@ -122,12 +112,6 @@ let rename_caller loc args exp = match exp.enode with ...@@ -122,12 +112,6 @@ let rename_caller loc args exp = match exp.enode with
vi.vname <- Functions.RTL.get_rtl_replacement_name vi.vname; vi.vname <- Functions.RTL.get_rtl_replacement_name vi.vname;
exp, args exp, args
| Lval(Var vi , _) when Functions.Libc.is_vla_free_name vi.vname ->
(* handle variable-length array allocation via [__fc_vla_free]. Rewrite its
name to [delete_block]. The rest is in place. *)
vi.vname <- Functions.RTL.mk_api_name "delete_block";
exp, args
| Lval(Var vi, _) | Lval(Var vi, _)
when Options.Validate_format_strings.get () when Options.Validate_format_strings.get ()
&& Functions.Libc.is_printf_name vi.vname && Functions.Libc.is_printf_name vi.vname
...@@ -200,6 +184,17 @@ let inject_in_instr env kf stmt = function ...@@ -200,6 +184,17 @@ let inject_in_instr env kf stmt = function
| _ -> | _ ->
env env
in in
(* if this is a call to free a vla, add a call to delete_block *)
let env =
if Functions.Libc.is_vla_free caller then
match args with
| [ { enode = CastE (_, { enode = Lval (Var vi, NoOffset) }) } ] ->
let delete_block = Constructor.mk_delete_stmt ~is_addr:true vi in
Env.add_stmt env kf delete_block
| _ -> Options.fatal "The normalization of __fc_vla_free() has changed"
else
env
in
Call(result, caller, args, loc), env Call(result, caller, args, loc), env
| Local_init(vi, linit, loc) -> | Local_init(vi, linit, loc) ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment