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

            Bug ID: 87883
           Summary: [ARM] ICE: Segmentation fault in arm_regno_class
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jozef.l at mittosystems dot com
  Target Milestone: ---

Querying REGNO_REG_CLASS, from reginfo.c init_reg_sets, with an argument > 15
causes a segfault for arm-unknown-eabi.

For example, after applying the following contrived patch, a build of GCC seg
faults when running self-tests.

diff --git a/gcc/reginfo.c b/gcc/reginfo.c
index 33befa5..3fce076 100644
--- a/gcc/reginfo.c
+++ b/gcc/reginfo.c
@@ -165,6 +165,8 @@ init_reg_sets (void)
        if (int_reg_class_contents[i][j / 32]
            & ((unsigned) 1 << (j % 32)))
          SET_HARD_REG_BIT (reg_class_contents[i], j);
+       else
+         gcc_assert (REGNO_REG_CLASS (j) > -1);
     }

   /* Sanity check: make sure the target macros FIXED_REGISTERS and

> ./gcc/xgcc -B./gcc/ -xc -nostdinc /dev/null -S -o /dev/null 
> -fself-test=../../gcc/testsuite/selftests
> cc1: internal compiler error: Segmentation fault
> cc1: internal compiler error: Segmentation fault
> 0xc33ebf crash_signal
>                               ../../gcc/toplev.c:325
> 0xc33ebf crash_signal
>                               ../../gcc/toplev.c:325
> 0xfc3fba bitmap_check_index
>                               ../../gcc/sbitmap.h:105
> 0xfc3fba bitmap_bit_p
>                               ../../gcc/sbitmap.h:120
> 0xfc3fba arm_regno_class(int)
>                               ../../gcc/config/arm/arm.c:23757
> 0xfc3fba bitmap_check_index
>                               ../../gcc/sbitmap.h:105
> 0xfc3fba bitmap_bit_p
>                               ../../gcc/sbitmap.h:120
> 0xfc3fba arm_regno_class(int)
>                               ../../gcc/config/arm/arm.c:23757
> 0xb986a3 init_reg_sets()
>                               ../../gcc/reginfo.c:169
> 0x616b7d general_init
>                               ../../gcc/toplev.c:1171

This can also be observed when debugging the failing self-test invocation in
GDB

> ./gcc/xgcc -B./gcc/ -xc -nostdinc /dev/null -S -o /dev/null \
>   -fself-test=../../gcc/testsuite/selftests -wrapper gdb,--args

Breakpoint 2, init_reg_sets () at ../../gcc/reginfo.c:153
153     {
(gdb) call arm_regno_class(15)
$1 = NO_REGS
(gdb) call arm_regno_class(16)                                                  

Program received signal SIGSEGV, Segmentation fault.
arm_regno_class (regno=16) at ../../gcc/config/arm/arm.c:23757
23757     if (IS_VFP_REGNUM (regno))

Observed on current trunk, gcc-8-branch and gcc-7-branch.
Bootstrap for x86_64-pc-linux-gnu, and a regular build for msp430-elf complete
successfully with the above patch.

Reply via email to