Skip to content

Commit a3c91aa

Browse files
authored
Merge pull request #51 from goblint/loc-end
Add end locations to statements
2 parents 0cd459f + c3ef49d commit a3c91aa

30 files changed

+503
-419
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
* Add ends to locations, allowing for ranges.
3+
* Add additional expression locations to statements, etc.
4+
5+
## Older versions
6+
17
18 November 2021: goblint-cil-1.8.2
28

39
* Add columns to locations.

src/cfg.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ class caseLabeledStmtFinder slr = object(self)
8484
then begin
8585
slr := s :: (!slr);
8686
match s.skind with
87-
| Switch(_,_,_,_) -> SkipChildren
87+
| Switch(_,_,_,_,_) -> SkipChildren
8888
| _ -> DoChildren
8989
end else match s.skind with
90-
| Switch(_,_,_,_) -> SkipChildren
90+
| Switch(_,_,_,_,_) -> SkipChildren
9191
| _ -> DoChildren
9292
end
9393

@@ -180,10 +180,10 @@ and cfgStmt (s: stmt) (next:stmt option) (break:stmt option) (cont:stmt option)
180180
| hd::_ -> addSucc hd
181181
in
182182
let instrFallsThrough (i : instr) : bool = match i with
183-
Call (_, Lval (Var vf, NoOffset), _, _) ->
183+
Call (_, Lval (Var vf, NoOffset), _, _, _) ->
184184
(* See if this has the noreturn attribute *)
185185
not (hasAttribute "noreturn" vf.vattr)
186-
| Call (_, f, _, _) ->
186+
| Call (_, f, _, _, _) ->
187187
not (hasAttribute "noreturn" (typeAttrs (typeOf f)))
188188
| _ -> true
189189
in
@@ -198,7 +198,7 @@ and cfgStmt (s: stmt) (next:stmt option) (break:stmt option) (cont:stmt option)
198198
| ComputedGoto (e,_) -> List.iter addSucc rlabels
199199
| Break _ -> addOptionSucc break
200200
| Continue _ -> addOptionSucc cont
201-
| If (_, blk1, blk2, _) ->
201+
| If (_, blk1, blk2, _, _) ->
202202
(* The succs of If is [true branch;false branch] *)
203203
addBlockSucc blk2 next;
204204
addBlockSucc blk1 next;
@@ -207,7 +207,7 @@ and cfgStmt (s: stmt) (next:stmt option) (break:stmt option) (cont:stmt option)
207207
| Block b ->
208208
addBlockSucc b next;
209209
cfgBlock b next break cont nodeList rlabels
210-
| Switch(_,blk,l,_) ->
210+
| Switch(_,blk,l,_,_) ->
211211
let bl = findCaseLabeledStmts blk in
212212
List.iter addSucc (List.rev bl(*l*)); (* Add successors in order *)
213213
(* sfg: if there's no default, need to connect s->next *)
@@ -219,8 +219,8 @@ and cfgStmt (s: stmt) (next:stmt option) (break:stmt option) (cont:stmt option)
219219
then
220220
addOptionSucc next;
221221
cfgBlock blk next next cont nodeList rlabels
222-
| Loop(blk, loc, s1, s2) ->
223-
s.skind <- Loop(blk, loc, (Some s), next);
222+
| Loop(blk, loc, eloc, s1, s2) ->
223+
s.skind <- Loop(blk, loc, eloc, (Some s), next);
224224
addBlockSucc blk (Some s);
225225
cfgBlock blk (Some s) next (Some s) nodeList rlabels
226226
(* Since all loops have terminating condition true, we don't put
@@ -246,9 +246,9 @@ and fasStmt (todo) (s : stmt) =
246246
ignore(todo s);
247247
match s.skind with
248248
| Block b -> fasBlock todo b
249-
| If (_, tb, fb, _) -> (fasBlock todo tb; fasBlock todo fb)
250-
| Switch (_, b, _, _) -> fasBlock todo b
251-
| Loop (b, _, _, _) -> fasBlock todo b
249+
| If (_, tb, fb, _, _) -> (fasBlock todo tb; fasBlock todo fb)
250+
| Switch (_, b, _, _, _) -> fasBlock todo b
251+
| Loop (b, _, _, _, _) -> fasBlock todo b
252252
| (Return _ | Break _ | Continue _ | Goto _ | ComputedGoto _ | Instr _) -> ()
253253
| TryExcept _ | TryFinally _ -> E.s (E.unimp "try/except/finally")
254254
end
@@ -264,7 +264,7 @@ let d_cfgnodelabel () (s : stmt) =
264264
let label =
265265
begin
266266
match s.skind with
267-
| If (e, _, _, _) -> "if" (*sprint ~width:999 (dprintf "if %a" d_exp e)*)
267+
| If (e, _, _, _, _) -> "if" (*sprint ~width:999 (dprintf "if %a" d_exp e)*)
268268
| Loop _ -> "loop"
269269
| Break _ -> "break"
270270
| Continue _ -> "continue"

src/check.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,11 @@ and checkStmt (s: stmt) =
730730
if H.mem labels ln then
731731
ignore (warn "Multiply defined label %s" ln);
732732
H.add labels ln ()
733-
| Case (e, _) ->
733+
| Case (e, _, _) ->
734734
let t = checkExp true e in
735735
if not (isIntegralType t) then
736736
E.s (bug "Type of case expression is not integer");
737-
| CaseRange (e1, e2, _) ->
737+
| CaseRange (e1, e2, _, _) ->
738738
let t1 = checkExp true e1 in
739739
if not (isIntegralType t1) then
740740
E.s (bug "Type of case expression is not integer");
@@ -776,16 +776,18 @@ and checkStmt (s: stmt) =
776776
| None, _ -> ignore (warn "Invalid return value")
777777
| Some re', rt' -> checkExpType false re' rt'
778778
end
779-
| Loop (b, l, _, _) -> checkBlock b
779+
| Loop (b, l, el, _, _) -> checkBlock b
780780
| Block b -> checkBlock b
781-
| If (e, bt, bf, l) ->
781+
| If (e, bt, bf, l, el) ->
782782
currentLoc := l;
783+
currentExpLoc := el;
783784
let te = checkExp false e in
784785
checkScalarType te;
785786
checkBlock bt;
786787
checkBlock bf
787-
| Switch (e, b, cases, l) ->
788+
| Switch (e, b, cases, l, el) ->
788789
currentLoc := l;
790+
currentExpLoc := el;
789791
let t = checkExp false e in
790792
if not (isIntegralType t) then
791793
E.s (bug "Type of switch expression is not integer");
@@ -836,8 +838,9 @@ and checkInstr (i: instr) =
836838
if !ignoreInstr i then ()
837839
else
838840
match i with
839-
| Set (dest, e, l) ->
841+
| Set (dest, e, l, el) ->
840842
currentLoc := l;
843+
currentExpLoc := el;
841844
let t = checkLval false false dest in
842845
(* Not all types can be assigned to *)
843846
(match unrollType t with
@@ -847,8 +850,9 @@ and checkInstr (i: instr) =
847850
| _ -> ());
848851
checkExpType false e t
849852

850-
| Call(dest, what, args, l) ->
853+
| Call(dest, what, args, l, el) ->
851854
currentLoc := l;
855+
currentExpLoc := el;
852856
let (rt, formals, isva, fnAttrs) =
853857
match unrollType (checkExp false what) with
854858
TFun(rt, formals, isva, fnAttrs) -> rt, formals, isva, fnAttrs

0 commit comments

Comments
 (0)