mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
Create more double related tests
Including catching warnings :) (yay -Werror)
This commit is contained in:
parent
7e7e0526dd
commit
0542daacdf
6 changed files with 265 additions and 17 deletions
|
@ -47,6 +47,7 @@ typedef struct {
|
|||
|
||||
static expr_t *pointer_arithmetic (int op, expr_t *e1, expr_t *e2);
|
||||
static expr_t *inverse_multiply (int op, expr_t *e1, expr_t *e2);
|
||||
static expr_t *double_compare (int op, expr_t *e1, expr_t *e2);
|
||||
|
||||
static expr_type_t string_string[] = {
|
||||
{'+', &type_string},
|
||||
|
@ -111,6 +112,21 @@ static expr_type_t float_integer[] = {
|
|||
#define float_uinteger float_integer
|
||||
#define float_short float_integer
|
||||
|
||||
static expr_type_t float_double[] = {
|
||||
{'+', &type_double, &type_double, 0},
|
||||
{'-', &type_double, &type_double, 0},
|
||||
{'*', &type_double, &type_double, 0},
|
||||
{'/', &type_double, &type_double, 0},
|
||||
{'%', &type_double, &type_double, 0},
|
||||
{EQ, 0, 0, 0, double_compare},
|
||||
{NE, 0, 0, 0, double_compare},
|
||||
{LE, 0, 0, 0, double_compare},
|
||||
{GE, 0, 0, 0, double_compare},
|
||||
{LT, 0, 0, 0, double_compare},
|
||||
{GT, 0, 0, 0, double_compare},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t vector_float[] = {
|
||||
{'*', &type_vector},
|
||||
{'/', 0, 0, 0, inverse_multiply},
|
||||
|
@ -130,6 +146,12 @@ static expr_type_t vector_vector[] = {
|
|||
#define vector_uinteger vector_float
|
||||
#define vector_short vector_float
|
||||
|
||||
static expr_type_t vector_double[] = {
|
||||
{'*', &type_vector},
|
||||
{'/', 0, 0, 0, inverse_multiply},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t entity_entity[] = {
|
||||
{EQ, &type_integer},
|
||||
{NE, &type_integer},
|
||||
|
@ -195,6 +217,12 @@ static expr_type_t quat_integer[] = {
|
|||
#define quat_uinteger quat_integer
|
||||
#define quat_short quat_integer
|
||||
|
||||
static expr_type_t quat_double[] = {
|
||||
{'*', &type_quaternion},
|
||||
{'/', 0, 0, 0, inverse_multiply},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t integer_float[] = {
|
||||
{'+', &type_float, &type_float, 0},
|
||||
{'-', &type_float, &type_float, 0},
|
||||
|
@ -290,6 +318,21 @@ static expr_type_t integer_short[] = {
|
|||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t integer_double[] = {
|
||||
{'+', &type_double, &type_double, 0},
|
||||
{'-', &type_double, &type_double, 0},
|
||||
{'*', &type_double, &type_double, 0},
|
||||
{'/', &type_double, &type_double, 0},
|
||||
{'%', &type_double, &type_double, 0},
|
||||
{EQ, &type_integer, &type_double, 0},
|
||||
{NE, &type_integer, &type_double, 0},
|
||||
{LE, &type_integer, &type_double, 0},
|
||||
{GE, &type_integer, &type_double, 0},
|
||||
{LT, &type_integer, &type_double, 0},
|
||||
{GT, &type_integer, &type_double, 0},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
#define uinteger_float integer_float
|
||||
#define uinteger_vector integer_vector
|
||||
#define uinteger_pointer integer_pointer
|
||||
|
@ -335,6 +378,7 @@ static expr_type_t uinteger_uinteger[] = {
|
|||
{0, 0}
|
||||
};
|
||||
#define uinteger_short uinteger_integer
|
||||
#define uinteger_double integer_double
|
||||
|
||||
#define short_float integer_float
|
||||
#define short_vector integer_vector
|
||||
|
@ -400,8 +444,66 @@ static expr_type_t short_short[] = {
|
|||
{GT, &type_integer},
|
||||
{0, 0}
|
||||
};
|
||||
#define short_double integer_double
|
||||
|
||||
static expr_type_t *string_x[] = {
|
||||
static expr_type_t double_float[] = {
|
||||
{'+', &type_double, 0, &type_double},
|
||||
{'-', &type_double, 0, &type_double},
|
||||
{'*', &type_double, 0, &type_double},
|
||||
{'/', &type_double, 0, &type_double},
|
||||
{'%', &type_double, 0, &type_double},
|
||||
{EQ, 0, 0, 0, double_compare},
|
||||
{NE, 0, 0, 0, double_compare},
|
||||
{LE, 0, 0, 0, double_compare},
|
||||
{GE, 0, 0, 0, double_compare},
|
||||
{LT, 0, 0, 0, double_compare},
|
||||
{GT, 0, 0, 0, double_compare},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t double_vector[] = {
|
||||
{'*', &type_vector},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t double_quat[] = {
|
||||
{'*', &type_quaternion},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t double_integer[] = {
|
||||
{'+', &type_double, 0, &type_double},
|
||||
{'-', &type_double, 0, &type_double},
|
||||
{'*', &type_double, 0, &type_double},
|
||||
{'/', &type_double, 0, &type_double},
|
||||
{'%', &type_double, 0, &type_double},
|
||||
{EQ, 0, 0, 0, double_compare},
|
||||
{NE, 0, 0, 0, double_compare},
|
||||
{LE, 0, 0, 0, double_compare},
|
||||
{GE, 0, 0, 0, double_compare},
|
||||
{LT, 0, 0, 0, double_compare},
|
||||
{GT, 0, 0, 0, double_compare},
|
||||
{0, 0}
|
||||
};
|
||||
#define double_uinteger double_integer
|
||||
#define double_short double_integer
|
||||
|
||||
static expr_type_t double_double[] = {
|
||||
{'+', &type_double},
|
||||
{'-', &type_double},
|
||||
{'*', &type_double},
|
||||
{'/', &type_double},
|
||||
{'%', &type_double},
|
||||
{EQ, &type_integer},
|
||||
{NE, &type_integer},
|
||||
{LE, &type_integer},
|
||||
{GE, &type_integer},
|
||||
{LT, &type_integer},
|
||||
{GT, &type_integer},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static expr_type_t *string_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
string_string,
|
||||
0, // ev_float
|
||||
|
@ -414,9 +516,10 @@ static expr_type_t *string_x[] = {
|
|||
0, // ev_integer
|
||||
0, // ev_uinteger
|
||||
0, // ev_short
|
||||
0, // ev_double
|
||||
};
|
||||
|
||||
static expr_type_t *float_x[] = {
|
||||
static expr_type_t *float_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
float_float,
|
||||
|
@ -429,9 +532,10 @@ static expr_type_t *float_x[] = {
|
|||
float_integer,
|
||||
float_uinteger,
|
||||
float_short,
|
||||
float_double,
|
||||
};
|
||||
|
||||
static expr_type_t *vector_x[] = {
|
||||
static expr_type_t *vector_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
vector_float,
|
||||
|
@ -444,9 +548,10 @@ static expr_type_t *vector_x[] = {
|
|||
vector_integer,
|
||||
vector_uinteger,
|
||||
vector_short,
|
||||
vector_double,
|
||||
};
|
||||
|
||||
static expr_type_t *entity_x[] = {
|
||||
static expr_type_t *entity_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
0, // ev_float
|
||||
|
@ -459,9 +564,10 @@ static expr_type_t *entity_x[] = {
|
|||
0, // ev_integer
|
||||
0, // ev_uinteger
|
||||
0, // ev_short
|
||||
0, // ev_double
|
||||
};
|
||||
|
||||
static expr_type_t *field_x[] = {
|
||||
static expr_type_t *field_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
0, // ev_float
|
||||
|
@ -474,9 +580,10 @@ static expr_type_t *field_x[] = {
|
|||
0, // ev_integer
|
||||
0, // ev_uinteger
|
||||
0, // ev_short
|
||||
0, // ev_double
|
||||
};
|
||||
|
||||
static expr_type_t *func_x[] = {
|
||||
static expr_type_t *func_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
0, // ev_float
|
||||
|
@ -489,9 +596,10 @@ static expr_type_t *func_x[] = {
|
|||
0, // ev_integer
|
||||
0, // ev_uinteger
|
||||
0, // ev_short
|
||||
0, // ev_double
|
||||
};
|
||||
|
||||
static expr_type_t *pointer_x[] = {
|
||||
static expr_type_t *pointer_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
0, // ev_float
|
||||
|
@ -504,9 +612,10 @@ static expr_type_t *pointer_x[] = {
|
|||
pointer_integer,
|
||||
pointer_uinteger,
|
||||
pointer_short,
|
||||
0, // ev_double
|
||||
};
|
||||
|
||||
static expr_type_t *quat_x[] = {
|
||||
static expr_type_t *quat_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
quat_float,
|
||||
|
@ -519,9 +628,10 @@ static expr_type_t *quat_x[] = {
|
|||
quat_integer,
|
||||
quat_uinteger,
|
||||
quat_short,
|
||||
quat_double,
|
||||
};
|
||||
|
||||
static expr_type_t *integer_x[] = {
|
||||
static expr_type_t *integer_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
integer_float,
|
||||
|
@ -534,9 +644,10 @@ static expr_type_t *integer_x[] = {
|
|||
integer_integer,
|
||||
integer_uinteger,
|
||||
integer_short,
|
||||
integer_double,
|
||||
};
|
||||
|
||||
static expr_type_t *uinteger_x[] = {
|
||||
static expr_type_t *uinteger_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
uinteger_float,
|
||||
|
@ -549,9 +660,10 @@ static expr_type_t *uinteger_x[] = {
|
|||
uinteger_integer,
|
||||
uinteger_uinteger,
|
||||
uinteger_short,
|
||||
uinteger_double,
|
||||
};
|
||||
|
||||
static expr_type_t *short_x[] = {
|
||||
static expr_type_t *short_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
short_float,
|
||||
|
@ -564,9 +676,26 @@ static expr_type_t *short_x[] = {
|
|||
short_integer,
|
||||
short_uinteger,
|
||||
short_short,
|
||||
short_double,
|
||||
};
|
||||
|
||||
static expr_type_t **binary_expr_types[] = {
|
||||
static expr_type_t *double_x[ev_type_count] = {
|
||||
0, // ev_void
|
||||
0, // ev_string
|
||||
double_float,
|
||||
double_vector,
|
||||
0, // ev_entity
|
||||
0, // ev_field
|
||||
0, // ev_func
|
||||
0, // ev_pointer
|
||||
double_quat,
|
||||
double_integer,
|
||||
double_uinteger,
|
||||
double_short,
|
||||
double_double,
|
||||
};
|
||||
|
||||
static expr_type_t **binary_expr_types[ev_type_count] = {
|
||||
0, // ev_void
|
||||
string_x,
|
||||
float_x,
|
||||
|
@ -579,6 +708,7 @@ static expr_type_t **binary_expr_types[] = {
|
|||
integer_x,
|
||||
uinteger_x,
|
||||
short_x,
|
||||
double_x
|
||||
};
|
||||
|
||||
static expr_t *
|
||||
|
@ -609,6 +739,36 @@ inverse_multiply (int op, expr_t *e1, expr_t *e2)
|
|||
return binary_expr ('*', e1, binary_expr ('/', one, e2));
|
||||
}
|
||||
|
||||
static expr_t *
|
||||
double_compare (int op, expr_t *e1, expr_t *e2)
|
||||
{
|
||||
type_t *t1 = get_type (e1);
|
||||
type_t *t2 = get_type (e2);
|
||||
expr_t *e;
|
||||
|
||||
if ((is_double (t1) && is_float (t2))
|
||||
|| (is_float (t1) && is_double (t2))) {
|
||||
}
|
||||
if (is_double (t1)) {
|
||||
if (is_float (t2)) {
|
||||
warning (e2, "comparison between double and float");
|
||||
} else if (!is_constant (e2)) {
|
||||
warning (e2, "comparison between double and integer");
|
||||
}
|
||||
e2 = cast_expr (&type_double, e2);
|
||||
} else {
|
||||
if (is_float (t1)) {
|
||||
warning (e1, "comparison between float and double");
|
||||
} else if (!is_constant (e1)) {
|
||||
warning (e1, "comparison between integer and double");
|
||||
}
|
||||
e1 = cast_expr (&type_double, e1);
|
||||
}
|
||||
e = new_binary_expr (op, e1, e2);
|
||||
e->e.expr.type = &type_double;
|
||||
return e;
|
||||
}
|
||||
|
||||
static expr_t *
|
||||
invalid_binary_expr (int op, expr_t *e1, expr_t *e2)
|
||||
{
|
||||
|
@ -778,9 +938,9 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
|
|||
et1 = low_level_type (t1);
|
||||
et2 = low_level_type (t2);
|
||||
|
||||
if (et1 > ev_short || !binary_expr_types[et1])
|
||||
if (et1 >= ev_type_count || !binary_expr_types[et1])
|
||||
return invalid_binary_expr(op, e1, e2);
|
||||
if (et2 > ev_short || !binary_expr_types[et1][et2])
|
||||
if (et2 >= ev_type_count || !binary_expr_types[et1][et2])
|
||||
return invalid_binary_expr(op, e1, e2);
|
||||
expr_type = binary_expr_types[et1][et2];
|
||||
while (expr_type->op && expr_type->op != op)
|
||||
|
|
|
@ -58,11 +58,23 @@ test_progs_dat=\
|
|||
|
||||
fail_progs_dat=
|
||||
|
||||
test_build_errors=\
|
||||
double-int-compare.r \
|
||||
double-float-compare.r
|
||||
|
||||
fail_build_errors=
|
||||
|
||||
test_defspace_src=\
|
||||
tw-defspace.c tw-diagnostic.c tw-strpool.c
|
||||
|
||||
TESTS=$(test_bins) $(test_progs_dat:.dat=.run)
|
||||
XFAIL_TESTS=$(fail_bins) $(fail_progs_dat:.dat=.run)
|
||||
TESTS=\
|
||||
$(test_bins) \
|
||||
$(test_progs_dat:.dat=.run) \
|
||||
$(test_build_errors:.r=.run)
|
||||
XFAIL_TESTS=\
|
||||
$(fail_bins) \
|
||||
$(fail_progs_dat:.dat=.run) \
|
||||
$(fail_build_errors:.r=.run)
|
||||
|
||||
check_PROGRAMS=test-harness $(test_progs_dat) $(test_bins)
|
||||
|
||||
|
@ -121,6 +133,12 @@ double.run: Makefile build-run
|
|||
include ./$(DEPDIR)/double.Qo # am--include-marker
|
||||
r_depfiles_remade += ./$(DEPDIR)/double.Qo
|
||||
|
||||
double-int-compare.run$(EXEEXT): double-int-compare.r Makefile build-compile-fail-run
|
||||
$(srcdir)/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
|
||||
|
||||
double-float-compare.run$(EXEEXT): double-float-compare.r Makefile build-compile-fail-run
|
||||
$(srcdir)/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
|
||||
|
||||
enum_dat_SOURCES=enum.r
|
||||
enum_obj=$(enum_dat_SOURCES:.r=.qfo)
|
||||
enum.dat$(EXEEXT): $(enum_obj) $(QFCC_DEP)
|
||||
|
|
15
tools/qfcc/test/build-compile-fail-run
Executable file
15
tools/qfcc/test/build-compile-fail-run
Executable file
|
@ -0,0 +1,15 @@
|
|||
#! /bin/sh
|
||||
|
||||
script=$1
|
||||
shift
|
||||
|
||||
cat > $script <<EOF
|
||||
#! /bin/sh
|
||||
# compile must fail
|
||||
$@
|
||||
if test \$? != 1; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x $script
|
7
tools/qfcc/test/double-float-compare.r
Normal file
7
tools/qfcc/test/double-float-compare.r
Normal file
|
@ -0,0 +1,7 @@
|
|||
double a;
|
||||
float b;
|
||||
int main ()
|
||||
{
|
||||
int x = a == b;
|
||||
return 1; // test fails if compile succeeds
|
||||
}
|
7
tools/qfcc/test/double-int-compare.r
Normal file
7
tools/qfcc/test/double-int-compare.r
Normal file
|
@ -0,0 +1,7 @@
|
|||
double a;
|
||||
int b;
|
||||
int main ()
|
||||
{
|
||||
int x = a == b;
|
||||
return 1; // test fails if compile succeeds
|
||||
}
|
|
@ -12,7 +12,46 @@ test_format ()
|
|||
int fail = 0;
|
||||
type_pun.d = M_PI;
|
||||
printf ("%g %08x%08x\n", type_pun.d, type_pun.i[1], type_pun.i[0]);
|
||||
//printf ("%08x%08x\n", type_pun.i[1], type_pun.i[0]);
|
||||
// this will fail on big-endian systems
|
||||
fail = type_pun.i[0] != 0x54442d18 || type_pun.i[1] != 0x400921fb;
|
||||
return fail;
|
||||
}
|
||||
|
||||
int
|
||||
test_constant ()
|
||||
{
|
||||
int fail = 0;
|
||||
double a, b, c, d, e;
|
||||
a = 1;
|
||||
b = 2.0;
|
||||
c = 3.2f;
|
||||
d = 3.2d;
|
||||
e = 3.2;
|
||||
printf ("%.17g %.17g %.17g %.17g %.17g\n", a, b, c, d, e);
|
||||
// this will fail on big-endian systems
|
||||
fail |= c == d; // 3.2 is not exactly representable, so must be different
|
||||
fail |= c == e; // 3.2 is not exactly representable, so must be different
|
||||
fail |= d != e; // 3.2d and 3.2 are both double, so must be the same
|
||||
return fail;
|
||||
}
|
||||
|
||||
int
|
||||
test_ops ()
|
||||
{
|
||||
int fail = 0;
|
||||
double a = 6.25, b = 2.375;
|
||||
double c;
|
||||
|
||||
c = a + b;
|
||||
fail |= c != 8.625;
|
||||
c = a - b;
|
||||
fail |= c != 3.875;
|
||||
c = a * b;
|
||||
fail |= c != 14.84375;
|
||||
c = a / b;
|
||||
fail |= c != 50d/19d;
|
||||
c = a % b;
|
||||
fail |= c != 1.5;
|
||||
return fail;
|
||||
}
|
||||
|
||||
|
@ -21,5 +60,7 @@ main ()
|
|||
{
|
||||
int fail = 0;
|
||||
fail |= test_format ();
|
||||
fail |= test_constant ();
|
||||
fail |= test_ops ();
|
||||
return fail;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue