Skip to content

Commit ee64e4a

Browse files
committed
Make first initializer eloc synthetic
1 parent 5eda904 commit ee64e4a

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/frontc/cabs2cil.ml

+44-1
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,49 @@ module BlockChunk =
932932
| stmts, postins ->
933933
doStmts stmts;
934934
c
935+
936+
let eDoInstr: instr -> instr = function
937+
| Set (l, e, loc, eloc) -> Set (l, e, loc, doLoc eloc)
938+
| VarDecl (v, loc) -> VarDecl (v, loc)
939+
| Call (l, f, a, loc, eloc) -> Call (l, f, a, loc, doLoc eloc)
940+
| Asm (a, b, c, d, e, loc) -> Asm (a, b, c, d, e, loc)
941+
942+
(** Change first stmt or instr eloc to synthetic. *)
943+
let eDoChunkHead (c: chunk): chunk =
944+
(* ignore (Pretty.eprintf "synthesizeFirstLoc %a\n" d_chunk c); *)
945+
let doInstrs = function
946+
| [] -> []
947+
| x :: xs -> eDoInstr x :: xs
948+
in
949+
(* must mutate stmts in order to not break refs (for gotos) *)
950+
let rec doStmt s: unit =
951+
s.skind <- match s.skind with
952+
| Instr xs -> Instr (doInstrs xs)
953+
| Return (e, loc, eloc) -> Return (e, loc, doLoc eloc)
954+
| Goto (s, loc) -> Goto (s, doLoc loc)
955+
| ComputedGoto (e, loc) -> ComputedGoto (e, doLoc loc)
956+
| Break loc -> Break (doLoc loc)
957+
| Continue loc -> Continue (doLoc loc)
958+
| If _
959+
| Switch _
960+
| Loop _ ->
961+
s.skind
962+
| Block b ->
963+
doBlock b;
964+
s.skind
965+
and doBlock b =
966+
doStmts b.bstmts
967+
and doStmts = function
968+
| [] -> ()
969+
| x :: xs ->
970+
doStmt x
971+
in
972+
match c.stmts, c.postins with
973+
| [], [] -> c
974+
| [], postins -> {c with postins = List.rev (doInstrs (List.rev postins))}
975+
| stmts, postins ->
976+
doStmts stmts;
977+
c
935978
end
936979

937980
let i2c (i: instr) =
@@ -5983,7 +6026,7 @@ and doDecl (isglobal: bool) : A.definition -> chunk = function
59836026
ignore (E.log "after doDecl %a: res=%a\n"
59846027
d_loc !currentLoc d_chunk res);
59856028
*)
5986-
SynthetizeLoc.doChunkTail res
6029+
SynthetizeLoc.eDoChunkHead (SynthetizeLoc.doChunkTail res)
59876030

59886031

59896032

0 commit comments

Comments
 (0)