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

            Bug ID: 81564
           Summary: ICE in group_case_labels_stmt()
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bergner at gcc dot gnu.org
  Target Milestone: ---

Yet another fallout from the switch changes.

bergner@pike:~/gcc/BUGS/$ cat bug.i
struct a {
    int b;
    int c;
};

void
foo (void)
{
  struct a *e;
  switch (e->c)
  {
    case 7:
    case 3:
      if (__builtin_expect(!0, 0))
        __builtin_unreachable();
  }
}
bergner@pike:~/gcc/BUGS/$
/home/bergner/gcc/build/gcc-fsf-mainline-debug/gcc/xgcc
-B/home/bergner/gcc/build/gcc-fsf-mainline-debug/gcc -O2 -S bug.i
during GIMPLE pass: cfg
bug.i: In function ‘foo’:
bug.i:7:1: internal compiler error: Segmentation fault
 foo (void)
 ^~~
0x10e70e77 crash_signal
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/toplev.c:338
0x10ee1508 group_case_labels_stmt(gswitch*)
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfg.c:1740
0x10edf98b end_recording_case_labels()
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfg.c:1255
0x10f0b9af cleanup_tree_cfg_1
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfgcleanup.c:748
0x10f0bdab cleanup_tree_cfg_noloop
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfgcleanup.c:843
0x10f0bfcf cleanup_tree_cfg()
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfgcleanup.c:899
0x10edcbcf execute_build_cfg
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfg.c:405
0x10edcca7 execute
        /home/bergner/gcc/gcc-fsf-mainline-base/gcc/tree-cfg.c:434
Please submit a full bug report,
with preprocessed source if appropriate.

Program received signal SIGSEGV, Segmentation fault.
0x0000000010ee1508 in group_case_labels_stmt (stmt=0x3fffb59e7940)
    at /home/bergner/gcc/gcc-fsf-mainline-pr72804-base/gcc/tree-cfg.c:1740
1740          if (EDGE_COUNT (base_bb->succs) == 0
(gdb) p base_bb
$2 = (basic_block) 0x0
(gdb) p base_case
$1 = (tree) 0x3fffb5a80000
(gdb) ptree base_case
 <case_label_expr 0x3fffb5a80000
    type <void_type 0x3fffb58d0f18 void VOID
        align 8 symtab 0 alias set -1 canonical type 0x3fffb58d0f18
        pointer_to_this <pointer_type 0x3fffb58d1068>>
    side-effects
    arg 0 <integer_cst 0x3fffb57f9750 type <integer_type 0x3fffb58d05e8 int>
constant 7>
    arg 2 <label_decl 0x3fffb5a50380 L.5 type <void_type 0x3fffb58d0f18 void>
        ignored VOID file (null) line 0 col 0
        align 1 context <function_decl 0x3fffb5a13400 foo>>
    bug.i:12:5 start: bug.i:12:5 finish: bug.i:12:8>
(gdb) p CASE_LABEL(base_case)
$3 = (tree) 0x3fffb5a50380
(gdb) ptree $3
 <label_decl 0x3fffb5a50380 L.5
    type <void_type 0x3fffb58d0f18 void VOID
        align 8 symtab 0 alias set -1 canonical type 0x3fffb58d0f18
        pointer_to_this <pointer_type 0x3fffb58d1068>>
    ignored VOID file (null) line 0 col 0
    align 1 context <function_decl 0x3fffb5a13400 foo>>
(gdb) pcfg
;; basic block 2, loop depth 0
;;  pred:       ENTRY
;;  succ:       5
;; basic block 5, loop depth 0
;;  pred:       2
;;  succ:       EXIT
(gdb) pbb 2
;; basic block 2, loop depth 0
;;  pred:       ENTRY
_1 = e->c;
switch (_1) <default: <L3> [INV] [count: INV], case 3: <L5>, case 7: <L5>>
;;  succ:       5

(gdb) pbb 5
;; basic block 5, loop depth 0
;;  pred:       2
<L3> [0.00%] [count: INV]:
return;
;;  succ:       EXIT

So it seems the block that the case labels point to has been deleted, which is
confirmed in the bug.i.011t.cfg dump file:

Removing basic block 3
;; basic block 3, loop depth 0
;;  pred:      
<L0> [0.00%] [count: INV]:
;;  succ:       4


Removing basic block 4
;; basic block 4, loop depth 0
;;  pred:       2
<L5> [0.00%] [count: INV]:
__builtin_unreachable ();
;;  succ:      


EMERGENCY DUMP:

foo ()
{
  struct a * eD.2678;

;;   basic block 2, loop depth 0, freq 0, maybe hot
;;    prev block 0, next block 5, flags: (NEW, REACHABLE)
;;    pred:       ENTRY (FALLTHRU)
  _1 = eD.2678->cD.2674;
  switch (_1) <default: <L3> [INV] [count: INV], case 3: <L5>, case 7: <L5>>
;;    succ:       5

;;   basic block 5, loop depth 0, freq 0, maybe hot
;;    prev block 2, next block 1, flags: (NEW, REACHABLE)
;;    pred:       2
<L3> [0.00%] [count: INV]:
  return;
;;    succ:       EXIT

}

In this base, we should probably discard these case statements similarly to how
we discard cases that have the same label as the default case.

Reply via email to