summaryrefslogtreecommitdiff
path: root/src/anf.ml
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-09-13 17:38:09 +0100
committerAlasdair Armstrong2018-09-13 17:38:09 +0100
commit03387349dceaecd8feb708eb467a0bde372cb664 (patch)
tree7fa4134a58d5d76fe345a680eed1bd9e6a079352 /src/anf.ml
parent61abeccf6c37169bc22a1674897caf482195857f (diff)
C: Fix an issue with assigning to unitialized variables at end of blocks
Assigning to an uninitialized variable as the last statement in a block is almost certainly a type, and if that occurs then the lift_assign re-write will introduce empty blocks causing this error to occur. Now when we see such an empty block when converting to A-normal form we turn it into unit, and emit a warning stating that an empty block has been found as well as the probable cause (uninitialized variable).
Diffstat (limited to 'src/anf.ml')
-rw-r--r--src/anf.ml4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/anf.ml b/src/anf.ml
index e87f2bfd..38be1127 100644
--- a/src/anf.ml
+++ b/src/anf.ml
@@ -509,6 +509,10 @@ let rec anf (E_aux (e_aux, ((l, _) as exp_annot)) as exp) =
match e_aux with
| E_lit lit -> mk_aexp (ae_lit lit (typ_of exp))
+ | E_block [] ->
+ Util.warn (Reporting_basic.loc_to_string l
+ ^ "\n\nTranslating empty block (possibly assigning to an uninitialized variable at the end of a block?)");
+ mk_aexp (ae_lit (L_aux (L_unit, l)) (typ_of exp))
| E_block exps ->
let exps, last = split_block l exps in
let aexps = List.map anf exps in