From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D64B23858401; Thu, 7 Mar 2024 05:19:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D64B23858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709788758; bh=lovpCiyzWNVG2bqNqsG3u2bamxrMkg9443KkDW3OuIA=; h=From:To:Subject:Date:From; b=nSR38vUc1oBXGga2/JVnvMO7xW/Z6tcghNJj7B4Ne9iMkgCtaSkmO9O5O4/Q73Ee9 pU7sIRnzM7WK+S0aF5/6G8DukhbIfVsUBjt10qyB2mebP1wbcH96zjqE1kwwiDq7ZF GzMuxlVeG+s9y51xGkkInNrlaPMoqrStER5AGfiM= From: "obaines at nvidia dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug lto/114263] New: LTO generating incorrect code with -O2 -std=c++20 -fno-strict-aliasing flags in GCC13 Date: Thu, 07 Mar 2024 05:19:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: obaines at nvidia dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114263 Bug ID: 114263 Summary: LTO generating incorrect code with -O2 -std=3Dc++20 -fno-strict-aliasing flags in GCC13 Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: obaines at nvidia dot com Target Milestone: --- I have a minimized test case where LTO seems to be generating incorrect cod= e. ### Sources ### A.cpp ``` #include #include struct A { A(uint64_t _x, uint8_t _y) : x(_x), y(_y) {} uint64_t x; uint8_t y; }; void doA() { std::vector v; v.emplace_back(0x1111111111111111ULL, 0x2); v.emplace_back(0x3333333333333333ULL, 0x4); } ``` B.cpp ``` #include #include #include struct B { B(uint64_t _x, uint64_t _y) : x(_x), y(_y) {} uint64_t x; uint64_t y; }; void doB() { std::vector v; v.emplace_back(0x5555555555555555ULL, 0x6666666666666666ULL); v.emplace_back(0x7777777777777777ULL, 0x8888888888888888ULL); std::cout << std::hex << "expected: " << 0x6666666666666666ULL << " act= ual: " << v[0].y << std::endl; } ``` AB.cpp ``` void doA(); void doB(); int main() { doA(); doB(); } ``` ### Build Command ### g++ -flto -g -O2 -std=3Dc++20 -fno-strict-aliasing -Wall -Wextra -c *.cpp g++ -flto -g -O2 -std=3Dc++20 -fno-strict-aliasing -Wall -Wextra *.o ### Notes ### The code doesn't generate any warnings during compilation. The output of the program is usually `expected: 6666666666666666 actual: 6666666666666666`, but with these optimization flags the output is `expecte= d: 6666666666666666 actual: 66`. The bug won't reproduce if I specify C++ stan= dard before C++20, or if I don't disable strict-aliasing optimization. Changing the size of A::y affects the number of bytes that are correctly co= pied in the output. The bug reproduces in gcc 13.2.0 and from the latest releases/gcc-13 branch (g++ (GCC) 13.2.1 20240306), but does not reproduce = in gcc-12.3.0 or with the latest trunk branch (g++ (GCC) 14.0.1 20240306 (experimental)).=20 So, as far as I can tell the bug is exclusive to GCC13.=