codereport / jsource

J Language Source Code. Livestream links ⬇️
https://www.youtube.com/playlist?list=PLVFrD1dmDdvfVhYLU_iKkV67X9XqCJLWe
Other
38 stars 20 forks source link

Release build fail, debug build warn, GCC11 #215

Open willwray opened 3 years ago

willwray commented 3 years ago

Guessing that these are GCC11 related, but haven't checked other versions. gcc --version gcc (GCC) 11.0.0 20210225 (Red Hat 11.0.0-0)

ninja -C build -f build-Release.ninja

In file included from ../jsrc/j.h:1019,
                 from ../jsrc/conjunctions/cu.c:6:
../jsrc/conjunctions/cu.c: In function ‘jtevery’:
../jsrc/jtype.h:167:19: error: array subscript ‘AD[0]’ is partly outside array bounds of ‘I[7]’
                                               {aka ‘long long int[7]’} [-Werror=array-bounds]
  167 | #define AK(x) ((x)->kchain.k)            // offset of ravel wrt x
      |                   ^~
../jsrc/ja.h:105:13: note: in expansion of macro ‘AK’
  105 |             AK((A)(v))    = (CAV(w) - (C *)(v));
      |             ^~
../jsrc/conjunctions/cu.c:55:9: note: in expansion of macro ‘fauxvirtual’
   55 |         fauxvirtual(virtw, virtblockw, w, 0, ACUC1);
      |         ^~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

The debug build gives a different warning of possible UB

[55/133] Building C object jsrc/CMakeFiles/j.dir/Debug/verbs/vfrom.c.o
In file included from ../jsrc/j.h:1017,
                 from ../jsrc/verbs/vfrom.c:6:
../jsrc/verbs/vfrom.c: In function ‘jtafrom’:
../jsrc/j.h:644:16: warning: operation on ‘jt->ranks’ may be undefined [-Wsequence-point]
  644 |      jt->ranks = (RANK2T)(I)z,                  \
../jsrc/ja.h:21:77: note: in definition of macro ‘df2’
   21 | #define df2(r, x, y, z) (r = ((r = (z)) ? (FAV(r)->valencefns[1])(jt, (x), (y), r) : r))
      |                                                                             ^
../jsrc/j.h:648:31: note: in expansion of macro ‘IRS1COMMON’
  648 | #define IRS1(w, fs, r, f1, z) IRS1COMMON(jt, w, fs, r, f1, z)           // nonneg rank
      |                               ^~~~~~~~~~
../jsrc/verbs/vfrom.c:484:22: note: in expansion of macro ‘IRS1’
  484 |                      IRS1(w, 0L, wcr, jtbox, ind),
      |                      ^~~~
herwinw commented 3 years ago

That first one looks very much as what I've experienced/written down in #183, I've tried writing down some ideas on how to fix this, but I haven't gotten around to try those. I don't think we've really changed that code compared to the vanilla jsource. Does the original source still compile with GCC 11?

I've seen those warnings for the debug build as well on GCC 10.2, I tried to have a quick look at them but didn't really see an easy fix.

willwray commented 3 years ago

Does the original source still compile with GCC 11?

Not sure which commit to pick from this repo, so tried this:

git clone https://github.com/jsoftware/jsource.git
cd jsource/make2
./build_all.sh

and it gives an error in one file only

../../../../jsrc/viavx.c: In function ‘jtindexofsub’:
cc1: error: function may return address of local variable [-Werror=return-local-addr]
In file included from ../../../../jsrc/j.h:1597,
                 from ../../../../jsrc/viavx.c:8:
../../../../jsrc/viavx.c:1789:69: note: declared here
 1789 | A jtindexofsub(J jt,I mode,A a,A w){PROLOG(0079);A h=0;fauxblockINT(zfaux,1,0);
      |                                                                     ^~~~~
../../../../jsrc/ja.h:365:31: note: in definition of macro ‘fauxblockINT’
  365 | #define fauxblockINT(z,n,r) I z[(AKXR(r)>>LGSZI)+(n)]   // define a block, big enough to hold n atoms at rank r, for use in fauxINT
      |                               ^
../../../../jsrc/viavx.c: At top level:
cc1: all warnings being treated as errors
make: *** [makefile-libj:167: viavx.o] Error 1