grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.55k stars 320 forks source link

Compile error with C export, GCC >= 14.2.x and fastmath (-fm def) #1055

Open SpotlightKid opened 10 hours ago

SpotlightKid commented 10 hours ago

Using the -fm def option when exporting to C produces the following error:

error: initializer element is not constant

This started to appear after I updated GCC to version 14.2.1 (Manjaro, x64-64).

$ LC_ALL=C gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240910 (GCC) 

To reproduce:

#!/bin/sh -x

cat > lpf.dsp <<__EOF__
import("stdfaust.lib");
cutoff = hslider("Cutoff", 15000, 16, 15000, 0.1) : si.smoo;
process = fi.lowpass(2, cutoff);
__EOF__

faust -lang c -a minimal.c -cn faustlpf lpf.dsp > lpf_minimal.c
faust -lang c -a minimal.c -cn faustlpf -fm def lpf.dsp > lpf_minimal_fm.c

LDFLAGS="-lm" make lpf_minimal
LDFLAGS="-lm" make lpf_minimal_fm

Output:

$ LC_ALL=C ./test.sh
+ cat
+ faust -lang c -a minimal.c -cn faustlpf lpf.dsp
+ faust -lang c -a minimal.c -cn faustlpf -fm def lpf.dsp
+ LDFLAGS=-lm
+ make lpf_minimal
cc   -lm  lpf_minimal.c   -o lpf_minimal
+ LDFLAGS=-lm
+ make lpf_minimal_fm
cc   -lm  lpf_minimal_fm.c   -o lpf_minimal_fm
In file included from lpf_minimal_fm.c:80:
/usr/include/faust/dsp/fastmath.cpp:212:33: error: initializer element is not constant
  212 | static uint32_t log_precision = log2i(fast_log_precision);
      |                                 ^~~~~
/usr/include/faust/dsp/fastmath.cpp:214:33: error: initializer element is not constant
  214 | static uint32_t pow_precision = log2i(fast_pow_precision);
      |                                 ^~~~~
/usr/include/faust/dsp/fastmath.cpp: In function 'fast_log10f':
/usr/include/faust/dsp/fastmath.cpp:244:52: error: expected expression before 'float'
  244 |     return icsi_log(x, log_table, log_precision) / float(M_LN10);
      |                                                    ^~~~~
/usr/include/faust/dsp/fastmath.cpp: In function 'fast_log2f':
/usr/include/faust/dsp/fastmath.cpp:250:52: error: expected expression before 'float'
  250 |     return icsi_log(x, log_table, log_precision) / float(M_LN2);
      |                                                    ^~~~~
make: *** [<builtin>: lpf_minimal_fm] Error 1
sletz commented 3 hours ago

ChatGPT answer, can you try and report ? https://chatgpt.com/share/66fe3c6c-7060-8013-a2b2-638b7b4ed1e2