https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97025
Bug ID: 97025 Summary: In -m32 mode the alignment of pointers returned by malloc or operator new is less than alignof(std::max_align_t) Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: officesamurai at gmail dot com Target Milestone: --- Created attachment 49210 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49210&action=edit The failing code The attached code fails when compiled with -m32: ------------------------ $ g++-10.2.0 gcc_alignment_issue_in_m32_mode.cpp -o test -std=c++17 -m32 && ./test test: gcc_alignment_issue_in_m32_mode.cpp:23: int main(): Assertion `UIntPtr(p2.get()) % alignof(Type) == 0' failed. Aborted ------------------------ And if I remove the Type's default constructor, it just crashes: ------------------------ $ g++-10.2.0 gcc_alignment_issue_in_m32_mode.cpp -o test -std=c++17 -m32 -DNO_CTOR && ./test Segmentation fault ------------------------ This happens with any version of GCC that I have in my system starting from 7.x, while 6.x works fine. As I can see, alignof(std::max_align_t) equals 8 in 6.x and 16 in 7.x and later versions, so this seems to be the root of the problem. The system and compiler info: ------------------------ $ cat /etc/issue Linux Mint 17.3 Rosa \n \l $ g++-10.2.0 -v Using built-in specs. COLLECT_GCC=g++-10.2.0 COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-10.2.0/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --prefix=/home/brd/soft/gcc-10.2.0 Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.2.0 (GCC) ------------------------