#1188 gcc -Wall fails with simple test module output

None
closed-out-of-date
Mark Gossage
lua (25)
5
2014-08-12
2011-08-19
Dwight Schauer
No

I updated a project recently (last I'd built it successfully was back in March) to the latest gcc and swig, and now my swig modules won't build (they use to build).

Rather than including my swig modules that won't build made a simple module example (attached) that demonstrates the problem.

$ swig -Wall -Werror -Wextra -includeall -small -c++ -lua -o foo_mod.c foo_mod.i
$ g++ -shared -o foo_mod.so foo_mod.c -rdynamic -fPIC -Wall -Werror -std=c++0x -O2 -fomit-frame-pointer
foo_mod.c: In function
int luaopen_foo_mod(lua_State*)
foo_mod.c:1841:27: error: array subscript is above array bounds [-Werror=array-bounds]
foo_mod.c:1847:27: error: array subscript is above array bounds [-Werror=array-bounds]
cc1plus: all warnings being treated as errors
$ swig -version
SWIG Version 2.0.4
Compiled with g++ [x86_64-unknown-linux-gnu]
Configured options: +pcre
$ g++ --version
g++ (GCC) 4.6.1

I always use -Wall -Werror, and I don't want to disable -Werror=array-bounds for any part of my project.

Discussion

  • Dwight Schauer
    Dwight Schauer
    2011-08-19

    Simple module interface

     
    Attachments
  • I can reproduce the problem (running g++ 4.6.1 as well), but the error message by the compiler is wrong.

    The code is like this:

    /* set up base class pointers (the hierachy) */
    for (i = 0; swig_types[i]; i++){
    if (swig_types[i]->clientdata){
    ...
    }
    }

    swig_types is an array of length 1, initialized as empty (so containing only a null pointer), therefore the loop body will never be entered. The same loop header is repeated leading to the second false error message.

    I can't see how this can be fixed in swig.

     
  • William Fulton
    William Fulton
    2011-08-20

    I can't replicate this with g++ 4.4, 4.5 or 4.6. Workarounds in compiler bugs are okay. Have you tried rewriting the code using a while loop instead as a workaround?

     
  • Dwight Schauer
    Dwight Schauer
    2014-08-10

    This is fixed now (not sure for how long). I'd moved onto other projects and forgot to check back on this. I just now verified that my included test case now has no issue with:

    SWIG Version 3.0.2
    g++ (GCC) 4.9.1

     
    Last edit: Dwight Schauer 2014-08-10
  • William Fulton
    William Fulton
    2014-08-12

    • status: open --> closed-out-of-date
    • Group: -->