https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121942
Bug ID: 121942 Summary: printed bool value is not what if-statement uses Product: gcc Version: 13.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: linasvepstas at gmail dot com Target Milestone: --- Multiple compiler versions affected. Different compilers behave differently, but still badly. A bool value is computed. The printed value is correct. When used in an if-statement, it is incorrect. i.e. what is printed, and what is used, do not match. Full description in the cc file. // Bug: boolean values seem to be mis-handled with -O2 optimization. // Caution: yes, there are floats in this bug report. No, that's not // "really" the problem, although they are entangled into it. // // The following attempts to compare vectors of floats. // The compare is done by casting the floats to int64_t. // Yes, there is reason to "hate this", but its not unusual. // At any rate, that's not what this bug is about. // The int64_t (and uint64_t)'s behave as expected. // A bool is computed. The printed value of the bool is correct. // Despite the bool being "true", the if-statement treats it as false. // And not just once, but consistently. // // g++ -O2 insane-more-O2.cc -o insane-more-O2-bad -save-temps // g++ -O1 insane-more-O2.cc -o insane-more-O2-good // // Offending compiler, linker, runtime loader: // gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 // GNU ld (GNU Binutils for Ubuntu) 2.42 // ldd (Ubuntu GLIBC 2.39-0ubuntu8.5) 2.39 // // Also affected: // gcc (Debian 12.2.0-14+deb12u1) 12.2.0 // GNU ld (GNU Binutils for Debian) 2.40 // ldd (Debian GLIBC 2.36-9+deb12u10) 2.36