]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Arithmetic exception flag and a plethora of tests.
authorDale Weiler <weilercdale@gmail.com>
Sat, 24 May 2014 14:38:02 +0000 (10:38 -0400)
committerDale Weiler <weilercdale@gmail.com>
Sat, 24 May 2014 14:38:02 +0000 (10:38 -0400)
doc/gmqcc.1
fold.c
gmqcc.ini.example
opts.def
tests/arithexcept.qc [new file with mode: 0644]
tests/arithexcept.tmpl [new file with mode: 0644]
tests/arithexcept_of.tmpl [new file with mode: 0644]
tests/arithexcept_uf.tmpl [new file with mode: 0644]
tests/inexact.qc [new file with mode: 0644]
tests/inexact.tmpl [new file with mode: 0644]

index e88acd9882f33134845987a3e6ac4faf525886a6..33a0eff3fbedef27673b700dc9511176e3be2029 100644 (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
diff --git a/fold.c b/fold.c
index 6d5d37ad403a4130e0fc8a989077c778f93e4831..98bbdb745ec27a48fe7e44a45f9c0f2070e0bc89 100644 (file)
--- a/fold.c
+++ b/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;
index a12628e5c1fc34c7334ed1880521f5c311a8014b..f7f391396c9d61dc96f0f4e86a388a4294db9799 100644 (file)
     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
index 5aa52ab53075579162b81dff598d9f652a4b43d7..669e734801846565eab654e46f671b6fc19754b8 100644 (file)
--- a/opts.def
+++ b/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 */
diff --git a/tests/arithexcept.qc b/tests/arithexcept.qc
new file mode 100644 (file)
index 0000000..10476e6
--- /dev/null
@@ -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
diff --git a/tests/arithexcept.tmpl b/tests/arithexcept.tmpl
new file mode 100644 (file)
index 0000000..3055e98
--- /dev/null
@@ -0,0 +1,4 @@
+I: arithexcept.qc
+D: arithmetic exceptions (divide by zero)
+T: -fail
+C: -std=fteqcc -farithmetic-exceptions -DDIVBYZERO
diff --git a/tests/arithexcept_of.tmpl b/tests/arithexcept_of.tmpl
new file mode 100644 (file)
index 0000000..94b7d7d
--- /dev/null
@@ -0,0 +1,4 @@
+I: arithexcept.qc
+D: arithmetic exceptions (overflow)
+T: -fail
+C: -std=ftqcc -farithmetic-exceptions -DOVERFLOW
diff --git a/tests/arithexcept_uf.tmpl b/tests/arithexcept_uf.tmpl
new file mode 100644 (file)
index 0000000..ed0a817
--- /dev/null
@@ -0,0 +1,4 @@
+I: arithexcept.qc
+D: arithmetic exceptions (underflow)
+T: -fail
+C: -std=ftqcc -farithmetic-exceptions -DUNDERFLOW
diff --git a/tests/inexact.qc b/tests/inexact.qc
new file mode 100644 (file)
index 0000000..873d7cc
--- /dev/null
@@ -0,0 +1,8 @@
+void main() {
+    const float a = 1.0 / 3.0;
+    const float b = 0.3333333333333;
+
+    if (a == b) {
+        // Should trigger warning
+    }
+}
diff --git a/tests/inexact.tmpl b/tests/inexact.tmpl
new file mode 100644 (file)
index 0000000..9808f7d
--- /dev/null
@@ -0,0 +1,4 @@
+I: inexact.qc
+D: inexact comparisons
+T: -fail
+C: -std=gmqcc -Winexact-compares -Wall -Werror