scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 5042ac1a04b0b0e797f20fb56d9e377870d513c7
parent 8b3404606cd8120322ef7816442a7fb938e7b513
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Mon, 16 Feb 2026 16:46:00 +0100

cc1: Add unary - folding for floats

This is required for static initializers.

Diffstat:
Msrc/cmd/scc-cc/cc1/fold.c | 3+++
Atests/cc/execute/0247-float.c | 10++++++++++
Mtests/cc/execute/scc-tests.lst | 1+
3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/cmd/scc-cc/cc1/fold.c b/src/cmd/scc-cc/cc1/fold.c @@ -258,6 +258,7 @@ foldldouble(int op, Symbol *res, long double l, long double r) case OSUB: f = l - r; break; case OMUL: f = l * r; break; case ODIV: f = l / r; break; + case OSNEG: f = -l; break; case OLT: i = l < r; goto comparison; case OGT: i = l > r; goto comparison; case OGE: i = l >= r; goto comparison; @@ -301,6 +302,7 @@ folddouble(int op, Symbol *res, double l, double r) case OSUB: f = l - r; break; case OMUL: f = l * r; break; case ODIV: f = l / r; break; + case OSNEG: f = -l; break; case OLT: i = l < r; goto comparison; case OGT: i = l > r; goto comparison; case OGE: i = l >= r; goto comparison; @@ -344,6 +346,7 @@ foldfloat(int op, Symbol *res, float l, float r) case OSUB: f = l - r; break; case OMUL: f = l * r; break; case ODIV: f = l / r; break; + case OSNEG: f = -l; break; case OLT: i = l < r; goto comparison; case OGT: i = l > r; goto comparison; case OGE: i = l >= r; goto comparison; diff --git a/tests/cc/execute/0247-float.c b/tests/cc/execute/0247-float.c @@ -0,0 +1,10 @@ +double vec[] = { + -0.7, + +0.7, +}; + +int +main(void) +{ + return vec[0] == 0.0 || vec[1] == 0.0; +} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -237,3 +237,4 @@ 0244-logic.c 0245-comma.c 0246-branch.c +0247-float.c