Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork10.9k
MAINT: Avoid dereferencing/strict aliasing warnings#28892
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Ping@lysnikolaou - do you happen to remember why you spelled these accesses this way originally? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This looks good to me.
Initially the#ifdef
wasn't there, so casting to the corresponding type worked across all different complex types. Now that the#ifdef
is there, using the struct field makes more sense.
OK, in it goes. Thanks@ilayn! |
83a4e6a
intonumpy:mainUh oh!
There was an error while loading.Please reload this page.
…sts in `npy_math.h` for C++ runs (numpy#28892)* MAINT: Avoid type-punning complex casts in npy_math.h* MAINT: Add missing typecast in npy_cimagl
npy_math.h
for C++ runs…sts in `npy_math.h` for C++ runs (numpy#28892)* MAINT: Avoid type-punning complex casts in npy_math.h* MAINT: Add missing typecast in npy_cimagl
Uh oh!
There was an error while loading.Please reload this page.
I am aware that this file went through many iterations and complex support is a constant headache, and if there is any more appetite left, I'd like to offer another minor change.
We have been having some warnings coming from non-C99-compliant compilers and C++ runs over SciPy since NumPy 2.0. This is mainly due to the
npy_crealX
/npy_cimagX
functions, casting the inputstruct
first and then dereferencing it in the new type, causing the strict-aliasing (type punning) rule to fire.Here is a recent example how this manifests itself in the build processhttps://github.com/scipy/scipy/actions/runs/14770722795/job/41470198162#step:6:300
I don't know if the SciPy code is also commiting some C++ sins but the NumPy code can do better to avoid strange bugs. I don't claim to have the right solution but seems like the most obvious one to me to let the compiler handle the possible padding/endianness issues with a straight struct field access. However I don't have a strong opinion since I'm not a C++ expert.
This is also somewhat related to our ambition to be warning free at some point.