Skip to content

Commit b1cac2d

Browse files
authored
Merge pull request #197 from goblint/loop-condition-labels
Add `__loop_condition` labels before syntactic loop conditions
2 parents d1da1ba + 2e07612 commit b1cac2d

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/frontc/cabs2cil.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ let alwaysGenerateVarDecl = false
8686
*)
8787
let addNestedScopeAttr = ref false
8888

89+
let addLoopConditionLabels = ref false
90+
8991
(** Indicates whether we're allowed to duplicate small chunks. *)
9092
let allowDuplication: bool ref = ref true
9193

@@ -1257,6 +1259,12 @@ let consLabContinue (c: chunk) =
12571259
| While :: rest -> c
12581260
| NotWhile lr :: rest -> if !lr = "" then c else consLabel !lr c !currentLoc false
12591261

1262+
let consLabLoopCondition (c: chunk) =
1263+
if !addLoopConditionLabels then
1264+
consLabel (newLabelName "__loop_condition") c !currentLoc false
1265+
else
1266+
c
1267+
12601268
let break_env = Stack.create ()
12611269

12621270
let enter_break_env () = Stack.push () break_env
@@ -6792,7 +6800,7 @@ and doStatement (s : A.statement) : chunk =
67926800
exitLoop ();
67936801
currentLoc := SynthetizeLoc.doLoc loc';
67946802
currentExpLoc := SynthetizeLoc.doLoc eloc';
6795-
loopChunk ((doCondition false e skipChunk break_cond)
6803+
loopChunk (consLabLoopCondition (doCondition false e skipChunk break_cond)
67966804
@@ s')
67976805

67986806
| A.DOWHILE(e,s,loc,eloc) ->
@@ -6803,7 +6811,7 @@ and doStatement (s : A.statement) : chunk =
68036811
currentLoc := SynthetizeLoc.doLoc loc';
68046812
currentExpLoc := SynthetizeLoc.doLoc eloc';
68056813
let s'' =
6806-
consLabContinue (doCondition false e skipChunk (breakChunk loc')) (* TODO: use eloc'? *)
6814+
consLabContinue (consLabLoopCondition (doCondition false e skipChunk (breakChunk loc'))) (* TODO: use eloc'? *)
68076815
in
68086816
exitLoop ();
68096817
loopChunk (s' @@ s'')
@@ -6837,9 +6845,9 @@ and doStatement (s : A.statement) : chunk =
68376845
let res =
68386846
match e2 with
68396847
A.NOTHING -> (* This means true *)
6840-
se1 @@ loopChunk (s' @@ s'')
6848+
se1 @@ loopChunk (consLabLoopCondition s' @@ s'')
68416849
| _ ->
6842-
se1 @@ loopChunk ((doCondition false e2 skipChunk break_cond)
6850+
se1 @@ loopChunk (consLabLoopCondition (doCondition false e2 skipChunk break_cond)
68436851
@@ s' @@ s'')
68446852
in
68456853
exitScope ();

src/frontc/cabs2cil.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ val nocil: int ref
5656
*)
5757
val addNestedScopeAttr: bool ref
5858

59+
(** Add [__loop_condition] labels before syntactic loop conditions. *)
60+
val addLoopConditionLabels: bool ref
61+
5962
(** Indicates whether we're allowed to duplicate small chunks of code. *)
6063
val allowDuplication: bool ref
6164

0 commit comments

Comments
 (0)