Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MAINT: Avoid dereferencing/strict aliasing warnings#28915

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

Merged
charris merged 1 commit intonumpy:maintenance/2.2.xfromcharris:backport-28892
May 6, 2025

Conversation

charris
Copy link
Member

Backport of#28892.

Happens innpy_math.h during complex casts in for C++ runs

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 thenpy_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

[snip] In file included from ..\scipy\_build_utils\src/npy_2_complexcompat.h:4,                 from ../scipy/special/xsf_wrappers.h:13,                 from ../scipy/special/xsf_wrappers.cpp:1:C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\site-packages\numpy\_core\include/numpy/npy_math.h: Infunction'npy_longdouble npy_creall(npy_clongdouble)':C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\site-packages\numpy\_core\include/numpy/npy_math.h:422:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]  422 |     return ((longdouble_t *) &z)[0];      |            ~^~~~~~~~~~~~~~~~~~~~[snip]

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.

  • MAINT: Avoid type-punning complex casts in npy_math.h

  • MAINT: Add missing typecast in npy_cimagl

…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
@charrischarris added this to the2.2.6 release milestoneMay 6, 2025
@charrischarris added 03 - Maintenance 08 - BackportUsed to tag backport PRs labelsMay 6, 2025
@charrischarris merged commit6c42775 intonumpy:maintenance/2.2.xMay 6, 2025
70 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
03 - Maintenance08 - BackportUsed to tag backport PRs
Projects
None yet
Milestone
2.2.6 release
Development

Successfully merging this pull request may close these issues.

2 participants
@charris@ilayn

[8]ページ先頭

©2009-2025 Movatter.jp