public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "luc.briand35 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-102490-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102490 Bug ID: 102490 Summary: Erroneous optimization of default constexpr operator== 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==(). 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==(const A&) const = default; }; int main() { A a{}, b{}; a.bar = 0b1; return a == b; } With the options "-std=c++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==(const A&) const = default; }; void change(A& a); int main() { A a{}, b{}; change(a); return a == b; } The assembly for gcc version 10.X and 11.X is a bit different, but have the same problem.
next reply other threads:[~2021-09-26 11:31 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-26 11:31 luc.briand35 at gmail dot com [this message] 2021-09-27 10:16 ` [Bug c++/102490] " jakub at gcc dot gnu.org 2021-09-27 11:33 ` jakub at gcc dot gnu.org 2021-09-27 11:37 ` pinskia at gcc dot gnu.org 2021-09-27 12:38 ` jakub at gcc dot gnu.org 2021-10-05 17:15 ` jakub at gcc dot gnu.org 2021-10-06 2:41 ` cvs-commit at gcc dot gnu.org 2022-11-03 21:18 ` ppalka at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102490-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).