vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
982 stars 118 forks source link

gcc-13 runtime error #461

Closed apelloni closed 8 months ago

apelloni commented 8 months ago

I was building (t)form on my machine which is currently using gcc (GCC) 13.2.1 20230801 and found an error. The compilation is completed without any issues (except some warnings see form_build_gcc13.log)

Most programs run just fine, but I get an error with tables. By running

Table sparse,C(1);
.end

I get

test.frm Line 1 --> Illegal option in table definition: 'sparse,C(1)'

I've tried to build form-5.0.0, form-4.3.1, form-4.3.0 but the issue is consistent.

It all disappear when I compile with gcc-12 (GCC) 12.3.0 by running CC=gcc-12 CXX=g++-12 ./configure Then the program runs as expected.

I've also tried to enable debugging but then vorm runs without issues. So I've tried to compile with a lower optimization level and I found that -O2 and -O3 are the ones producing the issue

I'm unsure if this is a problem in the gcc compiler or something being exposed only at this level. It could also be that the version I'm using is not completely stable. I also didn't have the opportunity to try to reproduce it on another machine

I'm attaching also the output from make form using both gcc-12 and gcc-13: form_build_gcc13.log form_build_gcc12.log

tueda commented 8 months ago

Thank you for your report! I have confirmed the same FORM runtime error with GCC 13.2.0.

I am not sure whether GCC 13 finds a pitfall in the FORM code (e.g., legal optimization with undefined behaviour) or it is just a bug of GCC, but it seems that making c volatile somehow removes the issue:

diff --git a/sources/names.c b/sources/names.c
index fd01e89..9ae586f 100644
--- a/sources/names.c
+++ b/sources/names.c
@@ -1666,7 +1666,8 @@ static int nwarntab = 1;
 int DoTable(UBYTE *s, int par)
 {
        GETIDENTITY
-       UBYTE *name, *p, *inp, c;
+       UBYTE *name, *p, *inp;
+       volatile UBYTE c;
        int i, j, k, sparseflag = 0, rflag = 0, checkflag = 0;
        int error = 0, ret, oldcbufnum, oldEside;
        WORD funnum, type, *OldWork, *w, *ww, *t, *tt, *flags1, oldnumrhs,oldnumlhs;

Maybe we need C (and/or GCC) experts...

tueda commented 8 months ago

Posted a related question on StackOverflow.

tueda commented 8 months ago

To summarize the discussion on StackOverflow, this is a GCC 13 bug and will be fixed in 13.3.0. So, I close this issue.

Meanwhile, we must not forget to run make check (test_Issue135_3 catches this issue).

apelloni commented 8 months ago

I've run make check but didn't show any error. I've looked into the check files and saw that check-help.sh calls for ruby which I didn't have installed. Now I can also see the failed check.

Thanks for looking into it.