Skip to content

Commit fd669d8

Browse files
committed
Avoid adding duplicate coverage IDs
Previously, if a program element happened to already be labeled with the label that's auto-generated for another element, Boogie would fail when adding an already-existing key to the coverage tracking map.
1 parent 6d8896f commit fd669d8

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

Source/Core/CoverageAnnotator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ private void AddIdIfMissing(ICarriesAttributes node, bool isGoal)
2929
return;
3030
}
3131
var idStr = node.FindStringAttribute("id");
32-
if (idStr == null) {
33-
idStr = $"id_l{absy.tok.line}_c{absy.tok.col}_{NodeType(node)}_{idCount}";
34-
idCount++;
32+
if (idStr == null || idMap.ContainsKey(idStr)) {
33+
do {
34+
idStr = $"id_l{absy.tok.line}_c{absy.tok.col}_{NodeType(node)}_{idCount}";
35+
idCount++;
36+
} while(idMap.ContainsKey(idStr));
3537
}
3638
idMap.Add(idStr, absy);
3739
if (isGoal) {
@@ -112,4 +114,4 @@ public override Ensures VisitEnsures(Ensures ensures)
112114
AddIdIfMissing(ensures, true);
113115
return base.VisitEnsures(ensures);
114116
}
115-
}
117+
}

Source/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- Target framework and package configuration -->
44
<PropertyGroup>
5-
<Version>3.5.2</Version>
5+
<Version>3.5.3</Version>
66
<TargetFramework>net8.0</TargetFramework>
77
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
88
<Authors>Boogie</Authors>

Test/coverage/duplicateIds.bpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %boogie /warnVacuousProofs /trace "%s" > "%t"
2+
// RUN: %OutputCheck "%s" --file-to-check="%t.coverage"
3+
// CHECK:Proof dependencies:
4+
// CHECK: id_l12_c5_assert_0
5+
// CHECK: id_l12_c5_assert_1
6+
// CHECK:Proof dependencies of whole program:
7+
// CHECK: id_l12_c5_assert_0
8+
// CHECK: id_l12_c5_assert_1
9+
procedure P(x: int) {
10+
assume {:id "id_l12_c5_assert_0"} x > 0;
11+
assert x > 0;
12+
}

0 commit comments

Comments
 (0)