From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D1BAD3858C60; Sun, 26 Sep 2021 11:31:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1BAD3858C60 From: "luc.briand35 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102490] New: Erroneous optimization of default constexpr operator== of struct with bitfields Date: Sun, 26 Sep 2021 11:31:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: luc.briand35 at gmail 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Sep 2021 11:31:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102490 Bug ID: 102490 Summary: Erroneous optimization of default constexpr operator=3D= =3D of struct with bitfields Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: luc.briand35 at gmail dot com Target Milestone: --- Hello, For the following code, gcc version 10 and up wrongly optimizes the default operator=3D=3D(). This occurs for O1 and up. Removing the 'constexpr' qualifier fixes everything. The size of the bitfields doesn't matter. No warnings are appear with "-Wall -Wextra". Godbolt link: https://gcc.godbolt.org/z/j4fG3sKze struct A { unsigned char foo : 1; unsigned char bar : 1; constexpr bool operator=3D=3D(const A&) const =3D default; }; int main() { A a{}, b{}; a.bar =3D 0b1; return a =3D=3D b; } With the options "-std=3Dc++2a -O1", the assembly generated is simply: main: mov eax, 1 ret In this similar example, we can see that the generated assembly for the equality operator ignores the 'bar' bitfield (Godbolt link: https://gcc.godbolt.org/z/3K75xx1on) : struct A { unsigned char foo : 3; unsigned char bar : 1; constexpr bool operator=3D=3D(const A&) const =3D default; }; void change(A& a); int main() { A a{}, b{}; change(a); return a =3D=3D b; } The assembly for gcc version 10.X and 11.X is a bit different, but have the same problem.=