mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
Arithmetic exception flag and a plethora of tests.
This commit is contained in:
parent
2917d39ef1
commit
bbeb2517c0
10 changed files with 51 additions and 0 deletions
|
@ -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
3
fold.c
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
1
opts.def
1
opts.def
|
@ -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
13
tests/arithexcept.qc
Normal 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
4
tests/arithexcept.tmpl
Normal file
|
@ -0,0 +1,4 @@
|
|||
I: arithexcept.qc
|
||||
D: arithmetic exceptions (divide by zero)
|
||||
T: -fail
|
||||
C: -std=fteqcc -farithmetic-exceptions -DDIVBYZERO
|
4
tests/arithexcept_of.tmpl
Normal file
4
tests/arithexcept_of.tmpl
Normal file
|
@ -0,0 +1,4 @@
|
|||
I: arithexcept.qc
|
||||
D: arithmetic exceptions (overflow)
|
||||
T: -fail
|
||||
C: -std=ftqcc -farithmetic-exceptions -DOVERFLOW
|
4
tests/arithexcept_uf.tmpl
Normal file
4
tests/arithexcept_uf.tmpl
Normal 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
8
tests/inexact.qc
Normal 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
4
tests/inexact.tmpl
Normal file
|
@ -0,0 +1,4 @@
|
|||
I: inexact.qc
|
||||
D: inexact comparisons
|
||||
T: -fail
|
||||
C: -std=gmqcc -Winexact-compares -Wall -Werror
|
Loading…
Reference in a new issue