hugomg/lua-aot-5.4

Integer overflow warning in generated C code

hishamhm opened this issue · 1 comments

Compiling the C file generated from tl.lua, I get these warnings from GCC:

gcc -c -o tl.o -I /Users/hisham/projects/tl/_binary/deps/lua-aot-5.4/src tl_module.c
tl_module.c: In function ‘magic_implementation_00’:
tl_module.c:18048:41: warning: integer overflow in expression [-Woverflow]
           last += GETARG_Ax(0xa4a35110) * (MAXARG_C + 1);
                                         ^
tl_module.c:18162:41: warning: integer overflow in expression [-Woverflow]
           last += GETARG_Ax(0xa4a35110) * (MAXARG_C + 1);
                                         ^
tl_module.c:19229:41: warning: integer overflow in expression [-Woverflow]
           last += GETARG_Ax(0xa8a75310) * (MAXARG_C + 1);
                                  

tl.lua is a pretty big module containing some pretty long functions (due to nested functions), so it might have to do with that?

This should be fixed by 1308b44, hopefully.

I think the problem here is that the SETLIST bytecode doesn't always have an extra argument. But LuaAOT wasn't aware of that, and generated code for the extra argument even when it did not exist. Basically, the we were generating code that looked like this:

if (0) {
    last += GETARG_Ax(OVERFLOW)
}

The fix I'm trying is to put this if statement in the code generator, instead of in the generated code.