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

[BUG]: Strict aliasing error on MinGW #5244

Open
2 of 3 tasks
markuspi opened this issue Jul 15, 2024 · 0 comments
Open
2 of 3 tasks

[BUG]: Strict aliasing error on MinGW #5244

markuspi opened this issue Jul 15, 2024 · 0 comments
Labels
triage New bug, unverified

Comments

@markuspi
Copy link

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.13.1

Problem description

Compiling code that uses pybind11/eigen.h on MinGW 6.3.0 fails with the following error:

dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]

I noticed that in gil_safe_call_once.h, there already is a conditional suppression of this warning, but it seems that MinGW is not yet covered by it.

PYBIND11_WARNING_PUSH
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5
// Needed for gcc 4.8.5
PYBIND11_WARNING_DISABLE_GCC("-Wstrict-aliasing")
#endif
return *reinterpret_cast<T *>(storage_);

Relevant compiler log output:

D:\dev\tmp\pybindmingw>C:\tools\mingw-w64\bin\g++.exe -ID:\\.conan\data\pybind11\2.13.1\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include -isystem D://.conan/data/dyna4-python-embedded/3.9.19.20240423/pnd28/testing/package/a57cdd79732bacf1f842fc7d97f3485af7cbc563/include -isystem D://.conan/data/eigen/3.3.8/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/eigen3 -Wall -O2 -c .\mysource.cpp
In file included from D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/pybind11.h:17:0,
                 from D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/numpy.h:12,
                 from D:\\.conan\data\pybind11\2.13.1\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include/pybind11/eigen/matrix.h:12,
                 from D:\\.conan\data\pybind11\2.13.1\_\_\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\include/pybind11/eigen.h:12,
                 from .\mysource.cpp:3:
D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/gil_safe_call_once.h: In instantiation of 'T& pybind11::gil_safe_call_once_and_store<T>::get_stored() [with T = pybind11::detail::npy_api]':
D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/numpy.h:272:70:   required from here
D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/gil_safe_call_once.h:75:16: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         return *reinterpret_cast<T *>(storage_);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/gil_safe_call_once.h: In instantiation of 'T& pybind11::gil_safe_call_once_and_store<T>::get_stored() [with T = pybind11::object]':
D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/numpy.h:771:25:   required from here
D://.conan/data/pybind11/2.13.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/gil_safe_call_once.h:75:16: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
$ C:\tools\mingw-w64\bin\g++.exe --version
g++ (x86_64-posix-seh-rev2, Built by MinGW-W64 project) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.

Related to #4877

Reproducible example code

// compile using `-Wall -O2` flags

#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

int main() {}

Is this a regression? Put the last known working version here if it is.

Not a regression

@markuspi markuspi added the triage New bug, unverified label Jul 15, 2024
@markuspi markuspi changed the title [BUG]: [BUG]: Strict aliasing error on MinGW Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

1 participant