Skip to content

py/vm: Prevent array bound warning when using -MP_OBJ_ITER_BUF_NSLOTS. #6231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2022

Conversation

jepler
Copy link

@jepler jepler commented Apr 4, 2022

This warning can happen on clang 13.0.1 building mpy-cross:

../py/vm.c:748: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;
                        ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using pointer access instead of array access works around this warning.

This is a cherry-pick of micropython@bb70874

Closes: #6215

This warning can happen on clang 13.0.1 building mpy-cross:

../py/vm.c:748: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;
                        ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using pointer access instead of array access works around this warning.

Fixes issue adafruit#8467.

Signed-off-by: Damien George <[email protected]>
@jepler
Copy link
Author

jepler commented Apr 4, 2022

Personally I don't get why the change makes the diagnostic disappear (x[y] and *(x+y) refer to the same thing and are valid at the same times) but probably @dpgeorge knows better than me :) :)

@dhalbert
Copy link
Collaborator

dhalbert commented Apr 4, 2022

I think this is related but not exactly the same as the discussion in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578, about using offsets from fixed addresses, and a compiler thinking it knows better than you about whether you are addressing something out of bounds.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@dpgeorge
Copy link

dpgeorge commented Apr 5, 2022

Yeah, I'm not sure why this worked, but it did!

We also had other, similar problems that I could only fix with pragmas: micropython@dc91024

@dhalbert dhalbert added this to the 7.2.x milestone Apr 5, 2022
@dhalbert dhalbert merged commit 204a1d3 into adafruit:7.2.x Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants