diff mbox series

[arm] PR target/82975: Guard against reg_renumber being NULL in arm.h

Message ID 5A39453D.5080906@foss.arm.com
State New
Headers show
Series [arm] PR target/82975: Guard against reg_renumber being NULL in arm.h | expand

Commit Message

Kyrill Tkachov Dec. 19, 2017, 4:58 p.m. UTC
Hi all,

In this bug we ICE when checking REGNO_OK_FOR_INDEX_P on arm during 
pre-IRA scheduling.
This is because REGNO_OK_FOR_INDEX_P ends up checking the reg_renumber 
array.
Before IRA reg_renumber is NULL and thus we segfault.

The fix is to guard the use of reg_renumber in the logic in TEST_REGNO 
in arm.h.
On aarch64, for example, we also guard against the reg_renumber == NULL 
case.
This fixes the ICE. I also remove the part of the comment that muses on 
when reg_renumber
is available as with this patch it should now be safe to use at any point.

Bootstrapped and tested on arm-none-linux-gnueabihf.

Committed to trunk as r255830.

Thanks,
Kyrill

2017-12-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     PR target/82975
     * config/arm/arm.h (TEST_REGNO): Check reg_renumber is set before
     accessing it.  Adjust comment.

2017-12-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     PR target/82975
     * gcc.dg/pr82975.c: New test.

Comments

Jakub Jelinek Dec. 19, 2017, 9:56 p.m. UTC | #1
On Tue, Dec 19, 2017 at 04:58:37PM +0000, Kyrill Tkachov wrote:
> 2017-12-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
> 
>     PR target/82975
>     * gcc.dg/pr82975.c: New test.

The testcase FAILs on x86_64-linux/i686-linux and probably on all
non-arm/aarch64 targets.

Fixed thusly, committed to trunk as obvious.

2017-12-19  Jakub Jelinek  <jakub@redhat.com>

	PR target/82975
	* gcc.dg/pr82975.c: Only add -mtune=cortex-a57 on arm*/aarch64*
	targets.

--- gcc/testsuite/gcc.dg/pr82975.c.jj	2017-12-19 18:07:33.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr82975.c	2017-12-19 22:53:36.383901451 +0100
@@ -1,6 +1,7 @@
 /* PR target/82975.  */
 /* { dg-do compile } */
-/* { dg-options "-mtune=cortex-a57 -fno-sched-pressure -O2" } */
+/* { dg-options "-fno-sched-pressure -O2" } */
+/* { dg-additional-options "-mtune=cortex-a57" { target arm*-*-* aarch64*-*-* } } */
 
 typedef __SIZE_TYPE__ size_t;
 

	Jakub
Kyrill Tkachov Dec. 20, 2017, 9:22 a.m. UTC | #2
On 19/12/17 21:56, Jakub Jelinek wrote:
> On Tue, Dec 19, 2017 at 04:58:37PM +0000, Kyrill Tkachov wrote:
>> 2017-12-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
>>
>>      PR target/82975
>>      * gcc.dg/pr82975.c: New test.
> The testcase FAILs on x86_64-linux/i686-linux and probably on all
> non-arm/aarch64 targets.
>
> Fixed thusly, committed to trunk as obvious.

Thank you for fixing this. I had committed an older version of the 
testcase accidentally :(
My proper testcase did have the target guard.

Kyrill

> 2017-12-19  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR target/82975
> 	* gcc.dg/pr82975.c: Only add -mtune=cortex-a57 on arm*/aarch64*
> 	targets.
>
> --- gcc/testsuite/gcc.dg/pr82975.c.jj	2017-12-19 18:07:33.000000000 +0100
> +++ gcc/testsuite/gcc.dg/pr82975.c	2017-12-19 22:53:36.383901451 +0100
> @@ -1,6 +1,7 @@
>   /* PR target/82975.  */
>   /* { dg-do compile } */
> -/* { dg-options "-mtune=cortex-a57 -fno-sched-pressure -O2" } */
> +/* { dg-options "-fno-sched-pressure -O2" } */
> +/* { dg-additional-options "-mtune=cortex-a57" { target arm*-*-* aarch64*-*-* } } */
>   
>   typedef __SIZE_TYPE__ size_t;
>   
>
> 	Jakub
Kyrill Tkachov Dec. 20, 2017, 9:30 a.m. UTC | #3
On 20/12/17 09:22, Kyrill Tkachov wrote:
>
> On 19/12/17 21:56, Jakub Jelinek wrote:
> > On Tue, Dec 19, 2017 at 04:58:37PM +0000, Kyrill Tkachov wrote:
> >> 2017-12-19  Kyrylo Tkachov <kyrylo.tkachov@arm.com>
> >>
> >>      PR target/82975
> >>      * gcc.dg/pr82975.c: New test.
> > The testcase FAILs on x86_64-linux/i686-linux and probably on all
> > non-arm/aarch64 targets.
> >
> > Fixed thusly, committed to trunk as obvious.
>
> Thank you for fixing this. I had committed an older version of the
> testcase accidentally :(
> My proper testcase did have the target guard.
>

In fact, here is the patch I meant to commit.
Committed the missing comment change to arm.h.

Kyrill

> Kyrill
>
> > 2017-12-19  Jakub Jelinek  <jakub@redhat.com>
> >
> >        PR target/82975
> >        * gcc.dg/pr82975.c: Only add -mtune=cortex-a57 on arm*/aarch64*
> >        targets.
> >
> > --- gcc/testsuite/gcc.dg/pr82975.c.jj 2017-12-19 18:07:33.000000000 
> +0100
> > +++ gcc/testsuite/gcc.dg/pr82975.c    2017-12-19 22:53:36.383901451 
> +0100
> > @@ -1,6 +1,7 @@
> >   /* PR target/82975.  */
> >   /* { dg-do compile } */
> > -/* { dg-options "-mtune=cortex-a57 -fno-sched-pressure -O2" } */
> > +/* { dg-options "-fno-sched-pressure -O2" } */
> > +/* { dg-additional-options "-mtune=cortex-a57" { target arm*-*-* 
> aarch64*-*-* } } */
> >
> >   typedef __SIZE_TYPE__ size_t;
> >
> >
> >        Jakub
>
commit d0469b43a85de253444f36702090219521e65f54
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date:   Mon Dec 18 12:06:55 2017 +0000

    [arm] PR target/82975: Guard against reg_renumber being NULL in arm.h

diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index ac51412..c46fd60 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -1615,12 +1615,10 @@ enum arm_auto_incmodes
 
 /* These assume that REGNO is a hard or pseudo reg number.
    They give nonzero only if REGNO is a hard reg of the suitable class
-   or a pseudo reg currently allocated to a suitable hard reg.
-   Since they use reg_renumber, they are safe only once reg_renumber
-   has been allocated, which happens in reginfo.c during register
-   allocation.  */
+   or a pseudo reg currently allocated to a suitable hard reg.  */
 #define TEST_REGNO(R, TEST, VALUE) \
-  ((R TEST VALUE) || ((unsigned) reg_renumber[R] TEST VALUE))
+  ((R TEST VALUE)	\
+    || (reg_renumber && ((unsigned) reg_renumber[R] TEST VALUE)))
 
 /* Don't allow the pc to be used.  */
 #define ARM_REGNO_OK_FOR_BASE_P(REGNO)			\
diff --git a/gcc/testsuite/gcc.dg/pr82975.c b/gcc/testsuite/gcc.dg/pr82975.c
new file mode 100644
index 0000000..f4c15fa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82975.c
@@ -0,0 +1,20 @@
+/* PR target/82975.  */
+/* { dg-do compile } */
+/* { dg-options "-fno-sched-pressure -O2" } */
+/* { dg-options "-mtune=cortex-a57 -fno-sched-pressure -O2" { target arm*-*-* } } */
+
+typedef __SIZE_TYPE__ size_t;
+
+struct S1
+{
+  char pad1;
+  char val;
+  short pad2;
+};
+
+extern char t[256];
+
+void foo (struct S1 a, size_t i)
+{
+  t[i] = a.val;
+}
diff mbox series

Patch

commit 57beb9c5faf502ef6fb5a40bc0fa54541238b0c1
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date:   Mon Dec 18 12:06:55 2017 +0000

    [arm] PR target/82975: Guard against reg_renumber being NULL in arm.h

diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 47931e1..90478fc 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -1626,7 +1626,8 @@  enum arm_auto_incmodes
    has been allocated, which happens in reginfo.c during register
    allocation.  */
 #define TEST_REGNO(R, TEST, VALUE) \
-  ((R TEST VALUE) || ((unsigned) reg_renumber[R] TEST VALUE))
+  ((R TEST VALUE)	\
+    || (reg_renumber && ((unsigned) reg_renumber[R] TEST VALUE)))
 
 /* Don't allow the pc to be used.  */
 #define ARM_REGNO_OK_FOR_BASE_P(REGNO)			\
diff --git a/gcc/testsuite/gcc.dg/pr82975.c b/gcc/testsuite/gcc.dg/pr82975.c
new file mode 100644
index 0000000..e6c13bc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82975.c
@@ -0,0 +1,19 @@ 
+/* PR target/82975.  */
+/* { dg-do compile } */
+/* { dg-options "-mtune=cortex-a57 -fno-sched-pressure -O2" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+struct S1
+{
+  char pad1;
+  char val;
+  short pad2;
+};
+
+extern char t[256];
+
+void foo (struct S1 a, size_t i)
+{
+  t[i] = a.val;
+}