Arithmetic exception flag and a plethora of tests.

This commit is contained in:
Dale Weiler 2014-05-24 10:38:02 -04:00
parent 2917d39ef1
commit bbeb2517c0
10 changed files with 51 additions and 0 deletions

View file

@ -581,6 +581,11 @@ breaks decompilers, but causes the output file to be better compressible.
In commutative instructions, always put the lower-numbered operand first.
This shaves off 1 byte of entropy from all these instructions, reducing
compressed size of the output file.
.It Fl f Ns Cm arithmetic-exceptions
Turn on arithmetic exception tests in the compiler. In constant expressions
which trigger exceptions like division by zero, overflow, underflow, etc,
the following flag will produce diagnostics for what triggered that
exception.
.El
.Sh OPTIMIZATIONS
.Bl -tag -width Ds

3
fold.c
View file

@ -820,6 +820,9 @@ static bool fold_check_except_float(sfloat_t (*callback)(sfloat_state_t *, sfloa
sfloat_cast_t ca;
sfloat_cast_t cb;
if (!OPTS_FLAG(ARITHMETIC_EXCEPTIONS))
return false;
s.roundingmode = SFLOAT_ROUND_NEAREST_EVEN;
s.tiny = SFLOAT_TBEFORE;
s.exceptionflags = 0;

View file

@ -310,6 +310,11 @@
SORT_OPERANDS = false
#Turn on arithmetic exception tests in the compiler. In constant expressions
#which trigger exceptions like division by zero, overflow, underflow, etc,
#the following flag will produce diagnostics for what triggered that
#exception.
ARITHMETIC_EXCEPTIONS = false
[warnings]
#Generate a warning about variables which are declared but never

View file

@ -56,6 +56,7 @@
GMQCC_DEFINE_FLAG(UNSAFE_VARARGS)
GMQCC_DEFINE_FLAG(TYPELESS_STORES)
GMQCC_DEFINE_FLAG(SORT_OPERANDS)
GMQCC_DEFINE_FLAG(ARITHMETIC_EXCEPTIONS)
#endif
/* warning flags */

13
tests/arithexcept.qc Normal file
View file

@ -0,0 +1,13 @@
const float huge = 340282346638528859811704183484516925440; // FLT_MAX
#ifdef DIVBYZERO
const float a = 1.0 / 0.0;
#endif
#ifdef OVERFLOW
const float a = huge * huge;
#endif
#ifdef UNDERFLOW
const float a = 1 / huge;
#endif

4
tests/arithexcept.tmpl Normal file
View file

@ -0,0 +1,4 @@
I: arithexcept.qc
D: arithmetic exceptions (divide by zero)
T: -fail
C: -std=fteqcc -farithmetic-exceptions -DDIVBYZERO

View file

@ -0,0 +1,4 @@
I: arithexcept.qc
D: arithmetic exceptions (overflow)
T: -fail
C: -std=ftqcc -farithmetic-exceptions -DOVERFLOW

View file

@ -0,0 +1,4 @@
I: arithexcept.qc
D: arithmetic exceptions (underflow)
T: -fail
C: -std=ftqcc -farithmetic-exceptions -DUNDERFLOW

8
tests/inexact.qc Normal file
View file

@ -0,0 +1,8 @@
void main() {
const float a = 1.0 / 3.0;
const float b = 0.3333333333333;
if (a == b) {
// Should trigger warning
}
}

4
tests/inexact.tmpl Normal file
View file

@ -0,0 +1,4 @@
I: inexact.qc
D: inexact comparisons
T: -fail
C: -std=gmqcc -Winexact-compares -Wall -Werror