From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E8FB83858D20; Thu, 10 Nov 2022 20:11:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8FB83858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668111064; bh=PYJ1Fj5oriA91ipI44pHiDhMCGSgGRHBTcR0rLYuGsU=; h=From:To:Subject:Date:From; b=iZdTJog7vJ955W1hXKODkyI1JgX4EJlth4gQ38adc5M8zHcNObSCzT4/afEdHe46V D2+CyAXyH7U/GQY4HM6QcqqwA4PvQGqUuKjJ/9tCqxNTG1iOlxFApmW1uWBxspaWV8 5ZOaGWnaaMeNGTisrBEYaFftDiRYs8KiYnL+0D98= From: "klaus.doldinger64 at googlemail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: klaus.doldinger64 at googlemail 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=3D107622 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 (unneccessar= y) 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 =3D 10; break; case State::B: o =3D 11; break; case State::C: o =3D 12; break; default: // std::unreachable(); // __builtin_unreachable(); break; } }=