Skip to content
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

invalid-shift-base UndefinedBehaviorSanitizer error #2072

Closed
omkardandekar opened this issue Nov 13, 2023 · 3 comments · Fixed by #2083
Closed

invalid-shift-base UndefinedBehaviorSanitizer error #2072

omkardandekar opened this issue Nov 13, 2023 · 3 comments · Fixed by #2083

Comments

@omkardandekar
Copy link

np.bitwise_xor(hashable, column << (offset * precision), out=hashable)

We use trimesh and with Python 3.10. And, during testing, UndefinedBehaviorSanitizer (UBSAN) threw an error with this operation when the contents of the column are negative values. I see that this is an optimization put in place in case "array is 2D and smallish", but is there a way to accomplish this efficiently while not triggering UndefinedBehaviorSanitizer error? I would greatly appreciate and thoughts and suggestions. Thank you.

numpy/core/src/npymath/npy_math_internal.h.src:657:18: runtime error: left shift of negative value -2
#0 0x7f4188a47bca in npy_lshiftl numpy/core/src/npymath/npy_math_internal.h.src:657
#1 0x7f4188a7e11f in LONG_left_shift_avx2

SUMMARY: UndefinedBehaviorSanitizer: invalid-shift-base numpy/core/src/npymath/npy_math_internal.h.src:657:18 in
@omkardandekar
Copy link
Author

Just following up on this. @mikedh or others: Do you have any suggestions or advice? Thank you!

@mikedh
Copy link
Owner

mikedh commented Dec 5, 2023

Seems like we can offset to the minimum there, which I just PR'd. Looking at that function there's probably a faster way to do the grouping but this is ok for now.

How were you running the tests? It doesn't look like there's an easy way to run that behavior checker via pytest.

@omkardandekar
Copy link
Author

omkardandekar commented Dec 6, 2023

Thank you, so much for looking at this @mikedh! Much appreciated. Yes, it is a bit complicated to test in isolation -- we have this integrated in a larger codebase and running sanitizer checks on that. However, I tried your fix and invalid-shift-base error is now resolved. However, this has triggered another sanitizer error:

numpy/core/src/umath/loops.c.src:640:9: runtime error: signed integer overflow: 1790832976 - -365581955 cannot be represented in type 'int

So perhaps we are going over the 32-bit representation while applying the offset? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants