Skip to content

Commit 840c4ec

Browse files
committed
C library: whitespace fix to make fmaxf, fmaxl available
We parse the comments for "FUNCTION:" and therefore must not have a space before the colon. Enable and add regression tests for all variants of fmax (and also its dual fmin, while at it).
1 parent aad7825 commit 840c4ec

File tree

13 files changed

+76
-19
lines changed

13 files changed

+76
-19
lines changed

regression/cbmc-library/fmax-01/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
int main()
55
{
6-
fmax();
7-
assert(0);
6+
double d1, d2;
7+
__CPROVER_assume(!isnan(d1) || !isnan(d2));
8+
double r = fmax(d1, d2);
9+
assert(!isnan(d1) || r == d2);
10+
assert(!isnan(d2) || r == d1);
11+
assert(isnan(d1) || isnan(d2) || (d1 > d2 ? r == d1 : r == d2));
812
return 0;
913
}

regression/cbmc-library/fmax-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+
--pointer-check --bounds-check --nan-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
int main()
5+
{
6+
float f1, f2;
7+
__CPROVER_assume(!isnan(f1) || !isnan(f2));
8+
float r = fmaxf(f1, f2);
9+
assert(!isnan(f1) || r == f2);
10+
assert(!isnan(f2) || r == f1);
11+
assert(isnan(f1) || isnan(f2) || (f1 > f2 ? r == f1 : r == f2));
12+
return 0;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
int main()
5+
{
6+
long double d1, d2;
7+
__CPROVER_assume(!isnan(d1) || !isnan(d2));
8+
long double r = fmaxl(d1, d2);
9+
assert(!isnan(d1) || r == d2);
10+
assert(!isnan(d2) || r == d1);
11+
assert(isnan(d1) || isnan(d2) || (d1 > d2 ? r == d1 : r == d2));
12+
return 0;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/cbmc-library/fmin-01/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
int main()
55
{
6-
fmin();
7-
assert(0);
6+
double d1, d2;
7+
__CPROVER_assume(!isnan(d1) || !isnan(d2));
8+
double r = fmin(d1, d2);
9+
assert(!isnan(d1) || r == d2);
10+
assert(!isnan(d2) || r == d1);
11+
assert(isnan(d1) || isnan(d2) || (d1 < d2 ? r == d1 : r == d2));
812
return 0;
913
}

regression/cbmc-library/fmin-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+
--pointer-check --bounds-check --nan-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

regression/cbmc-library/fminf-01/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
int main()
55
{
6-
fminf();
7-
assert(0);
6+
float f1, f2;
7+
__CPROVER_assume(!isnan(f1) || !isnan(f2));
8+
float r = fminf(f1, f2);
9+
assert(!isnan(f1) || r == f2);
10+
assert(!isnan(f2) || r == f1);
11+
assert(isnan(f1) || isnan(f2) || (f1 < f2 ? r == f1 : r == f2));
812
return 0;
913
}

regression/cbmc-library/fminf-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+
--pointer-check --bounds-check --nan-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

regression/cbmc-library/fminl-01/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
int main()
55
{
6-
fminl();
7-
assert(0);
6+
long double d1, d2;
7+
__CPROVER_assume(!isnan(d1) || !isnan(d2));
8+
long double r = fminl(d1, d2);
9+
assert(!isnan(d1) || r == d2);
10+
assert(!isnan(d2) || r == d1);
11+
assert(isnan(d1) || isnan(d2) || (d1 < d2 ? r == d1 : r == d2));
812
return 0;
913
}

regression/cbmc-library/fminl-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+
--pointer-check --bounds-check --nan-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

src/ansi-c/library/math.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ long double sqrtl(long double d)
955955
// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
956956
double fmax(double f, double g) { return ((f >= g) || isnan(g)) ? f : g; }
957957

958-
/* FUNCTION : fmaxf */
958+
/* FUNCTION: fmaxf */
959959

960960
#ifndef __CPROVER_MATH_H_INCLUDED
961961
#include <math.h>
@@ -965,8 +965,7 @@ double fmax(double f, double g) { return ((f >= g) || isnan(g)) ? f : g; }
965965
// TODO : Should call a __CPROVER_function so that it can be converted to SMT-LIB
966966
float fmaxf(float f, float g) { return ((f >= g) || isnan(g)) ? f : g; }
967967

968-
969-
/* FUNCTION : fmaxl */
968+
/* FUNCTION: fmaxl */
970969

971970
#ifndef __CPROVER_MATH_H_INCLUDED
972971
#include <math.h>

0 commit comments

Comments
 (0)