https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118538
Bug ID: 118538 Summary: Miscompilation on at -O0 on ARM Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: disservin.social at gmail dot com Target Milestone: --- Created attachment 60196 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60196&action=edit reproduction.cpp The attached reproduction seems to miscompile on ARM, more specifically on a Raspberry Pi 5. g++-14 -O0 -std=c++17 -Wall -Wextra -Wpedantic -Wuninitialized -fno-strict-aliasing -fwrapv -g3 test.cpp && ./a.out test.cpp: In function ‘int main()’: test.cpp:55:10: warning: variable ‘reader’ set but not used [-Wunused-but-set-variable] 55 | auto reader = Reader("file", 1); | ^~~~~~ [1] 473461 segmentation fault (core dumped) ./a.out g++-14 -v Using built-in specs. COLLECT_GCC=g++-14 COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-linux-gnu/14/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: aarch64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 14.2.0-4ubuntu2~24.04' --with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr --with-gcc-major-version-only --program-suffix=-14 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-offload-targets=nvptx-none=/build/gcc-14-KI9fgC/gcc-14-14.2.0/debian/tmp-nvptx/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.2.0 (Ubuntu 14.2.0-4ubuntu2~24.04) Running the executable with valgrind mentions an uninitialised value in the constructor list? valgrind --track-origins=yes --leak-check=full ./a.out ==476927== Memcheck, a memory error detector ==476927== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==476927== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==476927== Command: ./a.out ==476927== ==476927== Conditional jump or move depends on uninitialised value(s) ==476927== at 0x4B65D44: ??? (in /usr/lib/aarch64-linux-gnu/libgcc_s.so.1) ==476927== by 0x4B67697: _Unwind_RaiseException (in /usr/lib/aarch64-linux-gnu/libgcc_s.so.1) ==476927== by 0x496A8FB: __cxa_throw (in /usr/lib/aarch64-linux-gnu/libstdc++.so.6.0.33) ==476927== by 0x1096F3: Reader::Reader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) (test.cpp:43) ==476927== by 0x0: ??? ==476927== Uninitialised value was created by a stack allocation ==476927== at 0x109638: Reader::Reader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) (test.cpp:39) Removing the file open check from the constructor no longer causes a segmentation fault... if (!file.is_open()) { throw 42; }