public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield
@ 2021-12-25  0:26 blubban at gmail dot com
  2021-12-25  0:56 ` [Bug c++/103825] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: blubban at gmail dot com @ 2021-12-25  0:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103825
           Summary: [12 Regression] ICE on switch on enum class in
                    bitfield
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

enum class Type { Pawn };
struct Piece {
  Type type : 4;
};
void foo() {
  switch (Piece().type)
    case Type::Pawn:;
}


The above causes an ICE on GCC 12.0.0 20211222, no compile flags needed. It
compiles without warnings on GCC 11, Clang, and MSVC.

Compiler Explorer: https://godbolt.org/z/GdG6ovEzz


<source>: In function 'void foo()':
<source>:5:6: error: type precision mismatch in switch statement
    5 | void foo() {
      |      ^~~
switch (retval.0) <default: <D.2160>, case 0: <D.2157>>
<source>:5:6: internal compiler error: 'verify_gimple' failed
0x2115089 internal_error(char const*, ...)
        ???:0
0x11603ed verify_gimple_in_seq(gimple*)
        ???:0
0xdda0d1 gimplify_body(tree_node*, bool)
        ???:0
0xdda397 gimplify_function_tree(tree_node*)
        ???:0
0xbe6a57 cgraph_node::analyze()
        ???:0
0xbeaf6d symbol_table::finalize_compilation_unit()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/103825] ICE on switch on enum class in bitfield
  2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
@ 2021-12-25  0:56 ` pinskia at gcc dot gnu.org
  2024-03-24 22:55 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-25  0:56 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-12-25
             Status|UNCONFIRMED                 |NEW
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=98043

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, the ICE is not a regression or rather it is hard to tell if it is a
regression or not just using godbolt as it even ICEs in GCC 6.1.0 with
-fchecking, GCC 5 didn't have -fchecking.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/103825] ICE on switch on enum class in bitfield
  2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
  2021-12-25  0:56 ` [Bug c++/103825] " pinskia at gcc dot gnu.org
@ 2024-03-24 22:55 ` pinskia at gcc dot gnu.org
  2024-03-26 15:48 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-24 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Alexandre.BUSTICO at enac dot fr

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 114451 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/103825] ICE on switch on enum class in bitfield
  2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
  2021-12-25  0:56 ` [Bug c++/103825] " pinskia at gcc dot gnu.org
  2024-03-24 22:55 ` pinskia at gcc dot gnu.org
@ 2024-03-26 15:48 ` mpolacek at gcc dot gnu.org
  2024-04-02 18:19 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-03-26 15:48 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r5-3726-g083e891e69429f, so mine.

commit 083e891e69429f93b958f6c18e2d52f515bae572
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Sep 24 17:23:56 2014 +0000

    re PR c/61405 (Not emitting "enumeration value not handled in switch"
warning for bit-field enums)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/103825] ICE on switch on enum class in bitfield
  2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
                   ` (2 preceding siblings ...)
  2024-03-26 15:48 ` mpolacek at gcc dot gnu.org
@ 2024-04-02 18:19 ` cvs-commit at gcc dot gnu.org
  2024-04-02 18:26 ` cvs-commit at gcc dot gnu.org
  2024-04-02 18:27 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-02 18:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:daa2e7c7ffe49b788357f7f2c9ef1c9b125c1f8c

commit r14-9758-gdaa2e7c7ffe49b788357f7f2c9ef1c9b125c1f8c
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Mar 29 16:59:37 2024 -0400

    c++: ICE with scoped enum in switch condition [PR103825]

    Here we ICE when gimplifying

      enum class Type { Pawn };
      struct Piece {
        Type type : 4;
      };
      void foo() {
        switch (Piece().type)
          case Type::Pawn:;
      }

    because we ended up with TYPE_PRECISION (cond) < TYPE_PRECISION (case).
    That's because the case expr type here is the unlowered type Type,
    whereas the conditional's type is the lowered <unnamed-signed:4>.  This
    is not supposed to happen: see the comment in pop_switch around the
    is_bitfield_expr_with_lowered_type check.

    But here we did not revert to the lowered SWITCH_STMT_TYPE, because
    the conditional contains a TARGET_EXPR, which has side-effects, which
    means that finish_switch_cond -> maybe_cleanup_point_expr wraps it
    in a CLEANUP_POINT_EXPR.  And is_bitfield_expr_with_lowered_type does
    not see through those.

            PR c++/103825

    gcc/cp/ChangeLog:

            * typeck.cc (is_bitfield_expr_with_lowered_type): Handle
            CLEANUP_POINT_EXPR.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/enum44.C: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/103825] ICE on switch on enum class in bitfield
  2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
                   ` (3 preceding siblings ...)
  2024-04-02 18:19 ` cvs-commit at gcc dot gnu.org
@ 2024-04-02 18:26 ` cvs-commit at gcc dot gnu.org
  2024-04-02 18:27 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-02 18:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:22510e4a68aa9ca850db34ae62c21c58442d8ab3

commit r13-8560-g22510e4a68aa9ca850db34ae62c21c58442d8ab3
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Mar 29 16:59:37 2024 -0400

    c++: ICE with scoped enum in switch condition [PR103825]

    Here we ICE when gimplifying

      enum class Type { Pawn };
      struct Piece {
        Type type : 4;
      };
      void foo() {
        switch (Piece().type)
          case Type::Pawn:;
      }

    because we ended up with TYPE_PRECISION (cond) < TYPE_PRECISION (case).
    That's because the case expr type here is the unlowered type Type,
    whereas the conditional's type is the lowered <unnamed-signed:4>.  This
    is not supposed to happen: see the comment in pop_switch around the
    is_bitfield_expr_with_lowered_type check.

    But here we did not revert to the lowered SWITCH_STMT_TYPE, because
    the conditional contains a TARGET_EXPR, which has side-effects, which
    means that finish_switch_cond -> maybe_cleanup_point_expr wraps it
    in a CLEANUP_POINT_EXPR.  And is_bitfield_expr_with_lowered_type does
    not see through those.

            PR c++/103825

    gcc/cp/ChangeLog:

            * typeck.cc (is_bitfield_expr_with_lowered_type): Handle
            CLEANUP_POINT_EXPR.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/enum44.C: New test.

    (cherry picked from commit daa2e7c7ffe49b788357f7f2c9ef1c9b125c1f8c)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/103825] ICE on switch on enum class in bitfield
  2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
                   ` (4 preceding siblings ...)
  2024-04-02 18:26 ` cvs-commit at gcc dot gnu.org
@ 2024-04-02 18:27 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-04-02 18:27 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for 14/13.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-02 18:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-25  0:26 [Bug c++/103825] New: [12 Regression] ICE on switch on enum class in bitfield blubban at gmail dot com
2021-12-25  0:56 ` [Bug c++/103825] " pinskia at gcc dot gnu.org
2024-03-24 22:55 ` pinskia at gcc dot gnu.org
2024-03-26 15:48 ` mpolacek at gcc dot gnu.org
2024-04-02 18:19 ` cvs-commit at gcc dot gnu.org
2024-04-02 18:26 ` cvs-commit at gcc dot gnu.org
2024-04-02 18:27 ` mpolacek at gcc dot gnu.org

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).