[i386] : Fix PR79804, ICE in print_reg

Submitted by Uros Bizjak on April 20, 2017, 8:29 p.m.

Details

Message ID CAFULd4axcY04e7x5T9w5AF87_oNaauDntY2mfc4+PZ4Em14eaQ@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak April 20, 2017, 8:29 p.m.
2017-04-20  Uros Bizjak  <ubizjak@gmail.com>

    PR target/79804
    * config/i386/i386.c (print_reg): Remove assert for disalowed
    regno values, call output_operand_lossage instead.

testsuite/ChangeLog:

2017-04-20  Uros Bizjak  <ubizjak@gmail.com>

    PR target/79804
    * gcc.target/i386/pr79804.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

Uros.

Comments

Markus Trippelsdorf April 21, 2017, 5:15 a.m.
On 2017.04.20 at 22:29 +0200, Uros Bizjak wrote:
> 
>     PR target/79804
>     * gcc.target/i386/pr79804.c: New test.
> 
> Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
> 
> Committed to mainline SVN.
> --- testsuite/gcc.target/i386/pr79804.c	(nonexistent)
> +++ testsuite/gcc.target/i386/pr79804.c	(working copy)
> @@ -0,0 +1,10 @@
> +/* PR target/79804 */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +void foo (void)
> +{
> +  register int r20 asm ("20");
> +
> +  asm volatile ("# %0" : "=r"(r20));  /* { dg-error "invalid use of register" } */
> +}

The test fails without optimizations:

gcc/testsuite/gcc.target/i386/pr79804.c: In function ‘foo’:
gcc/testsuite/gcc.target/i386/pr79804.c:10:1: error: frame cannot be used in asm here
 }
 ^
gcc/testsuite/gcc.target/i386/pr79804.c:9:3: error: invalid 'asm': invalid use of register 'frame'
   asm volatile ("# %0" : "=r"(r20));  /* { dg-error "invalid use of register" } */
   ^~~

Patch hide | download patch | download mbox

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 246382)
+++ config/i386/i386.c	(working copy)
@@ -17637,13 +17637,17 @@  print_reg (rtx x, int code, FILE *file)
 
   regno = REGNO (x);
 
-  gcc_assert (regno != ARG_POINTER_REGNUM
-	      && regno != FRAME_POINTER_REGNUM
-	      && regno != FPSR_REG
-	      && regno != FPCR_REG);
-
-  if (regno == FLAGS_REG)
+  if (regno == ARG_POINTER_REGNUM
+      || regno == FRAME_POINTER_REGNUM
+      || regno == FPSR_REG
+      || regno == FPCR_REG)
     {
+      output_operand_lossage
+	("invalid use of register '%s'", reg_names[regno]);
+      return;
+    }
+  else if (regno == FLAGS_REG)
+    {
       output_operand_lossage ("invalid use of asm flag output");
       return;
     }
Index: testsuite/gcc.target/i386/pr79804.c
===================================================================
--- testsuite/gcc.target/i386/pr79804.c	(nonexistent)
+++ testsuite/gcc.target/i386/pr79804.c	(working copy)
@@ -0,0 +1,10 @@ 
+/* PR target/79804 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void foo (void)
+{
+  register int r20 asm ("20");
+
+  asm volatile ("# %0" : "=r"(r20));  /* { dg-error "invalid use of register" } */
+}