microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
44 stars 25 forks source link

mpy-cross: error: variable 'xxx' set but not used [-Werror,-Wunused-but-set-variable] #154

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago
../py/objgenerator.c:102:66: error: variable 'n_kwonly_args' set but not used [-Werror,-Wunused-but-set-variable]
    size_t n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args;
                                                                 ^
../py/objgenerator.c:102:54: error: variable 'n_pos_args' set but not used [-Werror,-Wunused-but-set-variable]
    size_t n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args;
                                                     ^
../py/objgenerator.c:102:21: error: variable 'n_exc_stack_unused' set but not used [-Werror,-Wunused-but-set-variable]
    size_t n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args;
                    ^
../py/objgenerator.c:102:81: error: variable 'n_def_args' set but not used [-Werror,-Wunused-but-set-variable]
    size_t n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args;
                                                                                ^
../py/objgenerator.c:102:41: error: variable 'scope_flags' set but not used [-Werror,-Wunused-but-set-variable]
    size_t n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args;
                                        ^
5 errors generated.
make: *** [build/py/objgenerator.o] Error 1

Haven't had a chance to look at this properly, but I've updated the Xcode toolchain a few weeks ago and I'm guessing a new version of clang might be throwing these error/warnings now.

$ clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
microbit-carlos commented 1 year ago

Based on this it should have been fixed in the MicroPython commit used in this repo?: https://github.com/micropython/micropython/issues/8805#issuecomment-1163834651

Looks related to this:

And manually applying this patch fixes that issue, but then it encounters more:

CC ../py/vm.c
../py/vm.c:730:25: error: array index -3 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements) [-Werror,-Warray-bounds]
                        sp[-MP_OBJ_ITER_BUF_NSLOTS + 1] = MP_OBJ_NULL;
                        ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../py/vm.c:257:13: note: array 'sp' declared here
            mp_obj_t *sp = code_state->sp;
            ^
../py/vm.c:731:25: error: array index -2 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements) [-Werror,-Warray-bounds]
                        sp[-MP_OBJ_ITER_BUF_NSLOTS + 2] = obj;
                        ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../py/vm.c:257:13: note: array 'sp' declared here
            mp_obj_t *sp = code_state->sp;
            ^
../py/vm.c:742:25: error: array index -3 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements) [-Werror,-Warray-bounds]
                    if (sp[-MP_OBJ_ITER_BUF_NSLOTS + 1] == MP_OBJ_NULL) {
                        ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../py/vm.c:257:13: note: array 'sp' declared here
            mp_obj_t *sp = code_state->sp;
            ^
../py/vm.c:743:31: error: array index -2 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements) [-Werror,-Warray-bounds]
                        obj = sp[-MP_OBJ_ITER_BUF_NSLOTS + 2];
                              ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../py/vm.c:257:13: note: array 'sp' declared here
            mp_obj_t *sp = code_state->sp;
            ^
4 errors generated.
make: *** [build/py/vm.o] Error 1

Which can then be fixed by applying this patch:

dpgeorge commented 1 year ago

We should update the MicroPython submodule that this repository uses. MicroPython v1.20.0 was released a few weeks ago and I suggest using this version.

Such an update will bring in bug fixes, more Python compatibility (eg bytes.fromhex and friends) and optimisations. But it shouldn't break any existing micro:bit scripts.

microbit-carlos commented 1 year ago

Sounds good 👍

dpgeorge commented 1 year ago

Fixed by 16fe526d88175ab79a21cba8cc449ffea190f8d3 and 5176ffd761ecdcce9836f9a7e1f835710fb9e85c

microbit-carlos commented 1 year ago

Thanks Damien! I can confirm I don't have mpy-cross compilation errors with the latest commit.