Skip to content

Commit 97ffac6

Browse files
authored
Merge pull request #4658 from tautschnig/library-check
Check cbmc-library regressions for completeness
2 parents 64f48d6 + e8f5ffd commit 97ffac6

File tree

62 files changed

+479
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+479
-435
lines changed

regression/cbmc-library/Float-div1-refine/main.c

Lines changed: 0 additions & 53 deletions
This file was deleted.

regression/cbmc-library/Float-div1/main.c

Lines changed: 0 additions & 53 deletions
This file was deleted.

regression/cbmc-library/Float-no-simp8/main.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

regression/cbmc-library/Float-to-double1/main.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

regression/cbmc-library/Float_lib1/main.c

Lines changed: 0 additions & 55 deletions
This file was deleted.

regression/cbmc-library/Float_lib2/main.c

Lines changed: 0 additions & 33 deletions
This file was deleted.

regression/cbmc-library/Float_lib2/test.desc

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <time.h>
3+
4+
int main()
5+
{
6+
__acrt_iob_func();
7+
assert(0);
8+
return 0;
9+
}

regression/cbmc-library/Float-no-simp9/test.desc renamed to regression/cbmc-library/__acrt_iob_func-01/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
CORE
1+
KNOWNBUG
22
main.c
3-
--floatbv --no-simplify
3+
--pointer-check --bounds-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
11
#include <assert.h>
2+
#include <float.h>
23
#include <math.h>
34

45
int main()
56
{
6-
__builtin_isinf();
7-
assert(0);
8-
return 0;
7+
double xxx;
8+
9+
// Visual Studio needs to be 2013 onwards
10+
#if defined(_MSC_VER) && !defined(__CYGWIN__) && _MSC_VER < 1800
11+
12+
// see http://www.johndcook.com/math_h.html
13+
14+
#else
15+
assert(fpclassify(DBL_MAX + DBL_MAX) == FP_INFINITE);
16+
assert(fpclassify(0 * (DBL_MAX + DBL_MAX)) == FP_NAN);
17+
assert(fpclassify(1.0) == FP_NORMAL);
18+
assert(fpclassify(DBL_MIN) == FP_NORMAL);
19+
assert(fpclassify(DBL_MIN / 2) == FP_SUBNORMAL);
20+
assert(fpclassify(-0.0) == FP_ZERO);
21+
#endif
22+
23+
#if !defined(__clang__) && defined(__GNUC__)
24+
assert(__builtin_fpclassify(0, 1, 2, 3, 4, DBL_MAX + DBL_MAX) == 1);
25+
assert(__builtin_fpclassify(0, 1, 2, 3, 4, 0 * (DBL_MAX + DBL_MAX)) == 0);
26+
assert(__builtin_fpclassify(0, 1, 2, 3, 4, 1.0) == 2);
27+
assert(__builtin_fpclassify(0, 1, 2, 3, 4, DBL_MIN) == 2);
28+
assert(__builtin_fpclassify(0, 1, 2, 3, 4, DBL_MIN / 2) == 3);
29+
assert(__builtin_fpclassify(0, 1, 2, 3, 4, -0.0) == 4);
30+
31+
assert(__builtin_isinf(DBL_MAX + DBL_MAX) == 1);
32+
assert(__builtin_isinf(0.0) == 0);
33+
assert(__builtin_isinf(-(DBL_MAX + DBL_MAX)) == 1);
34+
35+
assert(__builtin_isinf_sign(DBL_MAX + DBL_MAX) == 1);
36+
assert(__builtin_isinf_sign(0.0) == 0);
37+
assert(__builtin_isinf_sign(-(DBL_MAX + DBL_MAX)) == -1);
38+
39+
// these are compile-time
40+
_Static_assert(
41+
__builtin_fpclassify(0, 1, 2, 3, 4, -0.0) == 4,
42+
"__builtin_fpclassify is constant");
43+
44+
_Static_assert(__builtin_isnormal(DBL_MIN), "__builtin_isnormal is constant");
45+
46+
_Static_assert(!__builtin_isinf(0.0), "__builtin_isinf is constant");
47+
48+
_Static_assert(
49+
__builtin_isinf_sign(0.0) == 0, "__builtin_isinf_sign is constant");
50+
51+
#endif
52+
53+
assert(signbit(-1.0) != 0);
54+
assert(signbit(1.0) == 0);
955
}

regression/cbmc-library/__builtin_isinf-01/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--pointer-check --bounds-check
3+
--floatbv
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
#include <assert.h>
22
#include <math.h>
33

4-
int main()
4+
#ifdef __GNUC__
5+
void inductiveStepHunt(float startState)
56
{
6-
__fpclassify();
7-
assert(0);
7+
float target = 0x1.fffffep-3f;
8+
9+
__CPROVER_assume(
10+
(0 < startState) && (fpclassify(startState) == FP_NORMAL) &&
11+
(0x1p-126f <= startState));
12+
13+
float secondPoint = (target / startState);
14+
15+
float nextState = (startState + secondPoint) / 2;
16+
17+
float oneAfter = (target / nextState);
18+
19+
assert(oneAfter > 0);
20+
}
21+
22+
void simplifiedInductiveStepHunt(float nextState)
23+
{
24+
float target = 0x1.fffffep-3f;
25+
26+
// Implies nextState == 0x1p+124f;
27+
__CPROVER_assume(
28+
(0x1.fffffep+123f < nextState) && (nextState < 0x1.000002p+124f));
29+
30+
float oneAfter = (target / nextState);
31+
32+
// Is true and correctly proven by constant evaluation
33+
// Note that this is the smallest normal number
34+
assert(0x1.fffffep-3f / 0x1p+124f == 0x1p-126f);
35+
36+
assert(oneAfter > 0);
37+
}
38+
#endif
39+
40+
int main(void)
41+
{
42+
#ifdef __GNUC__
43+
// inductiveStepHunt(0x1p+125f);
44+
// simplifiedInductiveStepHunt(0x1p+124f);
45+
46+
float f, g;
47+
48+
inductiveStepHunt(f);
49+
simplifiedInductiveStepHunt(g);
50+
#endif
51+
852
return 0;
953
}

regression/cbmc-library/__fpclassify-01/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--pointer-check --bounds-check
3+
--floatbv
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

0 commit comments

Comments
 (0)