public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "klaus.doldinger64 at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/107622] New: Missing optimization of switch-statement
Date: Thu, 10 Nov 2022 20:11:04 +0000	[thread overview]
Message-ID: <bug-107622-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107622

            Bug ID: 107622
           Summary: Missing optimization of switch-statement
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: klaus.doldinger64 at googlemail dot com
  Target Milestone: ---

In the following example the default-case could not be reached. Therefore
introducing std::unreachable() should be useless. But the compiler produces
slightly better code with std::unreachable() as it removes one (unneccessary)
comparison (tested for x86 and avr targets).

volatile uint8_t o;

enum class State : uint8_t {A, B, C};

void g(const State s) {
    switch(s) {
    case State::A:
        o = 10;
        break;
    case State::B:
        o = 11;
        break;
    case State::C:
        o = 12;
        break;
    default:
//        std::unreachable(); // __builtin_unreachable();
        break;
    }
}

             reply	other threads:[~2022-11-10 20:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 20:11 klaus.doldinger64 at googlemail dot com [this message]
2022-11-10 20:20 ` [Bug c++/107622] " pinskia at gcc dot gnu.org
2022-11-10 21:31 ` pinskia at gcc dot gnu.org
2022-11-11  4:57 ` klaus.doldinger64 at googlemail dot com
2022-11-11  5:01 ` klaus.doldinger64 at googlemail dot com
2022-11-11  9:20 ` rguenth at gcc dot gnu.org
2022-11-11 10:16 ` klaus.doldinger64 at googlemail dot com
2022-11-11 15:07 ` glisse at gcc dot gnu.org
2022-11-21 10:32 ` marxin at gcc dot gnu.org
2022-12-02 14:17 ` marxin at gcc dot gnu.org
2022-12-02 14:45 ` jakub at gcc dot gnu.org
2023-04-16 21:55 ` klaus.doldinger64 at googlemail dot com
2023-04-17  6:50 ` klaus.doldinger64 at googlemail dot com

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-107622-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: link
Be 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).