Skip to content

Commit d5d0805

Browse files
authored
Merge pull request #1836 from goblint/halbwachs-phd-tests
Add tests from Halbwachs' PhD thesis
2 parents a5bee96 + d82727b commit d5d0805

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

src/analyses/loopTermination.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
(** Termination analysis for loops and [goto] statements ([termination]). *)
1+
(** Termination analysis for loops and [goto] statements ([termination]).
2+
3+
@see <https://theses.hal.science/tel-00288805> Halbwachs, N. Détermination automatique de relations linéaires vérifiées par les variables d’un programme. PhD thesis. Section 8.3. *)
24

35
open Analyses
46
open GoblintCil
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SKIP TERM PARAM: --set ana.activated[+] apron --set ana.apron.domain polyhedra --set ana.activated[+] termination
2+
// fully works with --set ana.widen.delay.local 6
3+
// Somehow we prove termination even without and don't have good bounds on termination counter.
4+
// From Nicolas Halbwachs' PhD thesis, section 5.6.2.
5+
#include <goblint.h>
6+
7+
int main() {
8+
unsigned int i = 0;
9+
unsigned int j = 0;
10+
while (i <= 10) {
11+
__goblint_check(j >= 0);
12+
__goblint_check(i - 2 * j >= 0);
13+
__goblint_check(i <= 10);
14+
15+
int r; // rand
16+
if (r) {
17+
i += 2;
18+
j++;
19+
}
20+
else
21+
i += 4;
22+
}
23+
24+
__goblint_check(j >= 0);
25+
__goblint_check(i - 2 * j >= 0);
26+
__goblint_check(11 <= i);
27+
__goblint_check(i <= 14); // TODO: needs one narrowing iteration
28+
__goblint_check(i + 2 * j <= 24); // TODO: needs one narrowing iteration
29+
return 0;
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SKIP PARAM: --set ana.activated[+] apron --set ana.apron.domain polyhedra
2+
// fully works with --set ana.widen.delay.local 6
3+
// From Nicolas Halbwachs' PhD thesis, section 8.3.
4+
// Same as 01-halbwachs-phd-sec5.6.2 annotated with an explicit termination counter.
5+
#include <goblint.h>
6+
7+
int main() {
8+
unsigned int i = 0;
9+
unsigned int j = 0;
10+
unsigned int k = 0; // explicit termination counter
11+
while (k++, i <= 10) {
12+
__goblint_check(j >= 0);
13+
__goblint_check(i + 2 * j + 4 == 4 * k);
14+
__goblint_check(i <= 10);
15+
__goblint_check(2 * k <= i + 2);
16+
17+
int r; // rand
18+
if (r) {
19+
i += 2;
20+
j++;
21+
}
22+
else
23+
i += 4;
24+
25+
__goblint_check(j >= 0);
26+
__goblint_check(i + 2 * j == 4 * k);
27+
__goblint_check(i <= 14);
28+
__goblint_check(1 <= k);
29+
__goblint_check(k <= 6);
30+
__goblint_check(2 * k <= i);
31+
}
32+
33+
__goblint_check(j >= 0);
34+
__goblint_check(i + 2 * j + 4 == 4 * k); // TODO: needs one narrowing iteration?
35+
__goblint_check(11 <= i);
36+
__goblint_check(i <= 14); // TODO: needs one narrowing iteration?
37+
__goblint_check(2 * k <= i + 2); // TODO: needs one narrowing iteration?
38+
39+
// if i and j are projected out:
40+
__goblint_check(4 <= k);
41+
__goblint_check(k <= 7); // TODO: needs one narrowing iteration?
42+
return 0;
43+
}

tests/regression/89-apron3/dune

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(rule
2+
(aliases runtest runaprontest)
3+
(enabled_if %{lib-available:apron})
4+
(deps
5+
(package goblint)
6+
../../../goblint ; update_suite calls local goblint
7+
(:update_suite ../../../scripts/update_suite.rb)
8+
(glob_files ??-*.c))
9+
(locks /update_suite)
10+
(action (chdir ../../.. (run %{update_suite} group apron3 -q))))

0 commit comments

Comments
 (0)