Hello!

Attached patch:

a) warns for 64-bit values in GR asm operand on 32bit targets

It is impossible to pass 64-bit (long long) value in 32bit register.
We should warn for this situation, since only 32bit lowpart value is
passed. The warning can be omitted by explicitly casting asm operand
to int.

b) errors out for 8-bit values in invalid GR asm operand

We can detect invalid %sil, %dil and %bpl asm operands early, and
terminate compilation in the compiler, not later in the assembler.

2017-02-28  Uros Bizjak  <ubiz...@gmail.com>

    * config/i386/i386.c (print_reg): Warn for values of 64-bit size
    in integer register on 32-bit targets.  Error out for values of
    8-bit size in invalid integer register.

testsuite/ChangeLog:

2017-02-28  Uros Bizjak  <ubiz...@gmail.com>

    * gcc.target/i386/invsize-1.c: New test.
    * gcc.target/i386/invsize-2.c: Ditto.

OK for mainline in stage 4?

Uros.

--cut here--
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 14ac189..e64bbe7 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -17641,6 +17641,9 @@ print_reg (rtx x, int code, FILE *file)
   switch (msize)
     {
     case 8:
+      if (LEGACY_INT_REGNO_P (regno) && !TARGET_64BIT)
+       warning (0, "unsupported size for integer register in 32-bit mode");
+      /* FALLTHRU */
     case 4:
       if (LEGACY_INT_REGNO_P (regno))
        putc (msize == 8 && TARGET_64BIT ? 'r' : 'e', file);
@@ -17654,6 +17657,8 @@ print_reg (rtx x, int code, FILE *file)
     case 1:
       if (regno >= ARRAY_SIZE (qi_reg_name))
        goto normal;
+      if (!ANY_QI_REGNO_P (regno))
+       error ("unsupported size for integer register in 32-bit mode");
       reg = qi_reg_name[regno];
       break;
     case 0:
--cut here--

/* { dg-do compile { target ia32 } } */

void foo (long long x)
{
  __asm__ volatile ("# %0" : : "r" (x));   /* { dg-warning
"unsupported size" }  */
}

/* { dg-do compile { target ia32 } } */

void foo (char x)
{
  register char rx  __asm ("si") = x;

  __asm__ volatile ("# %0" : : "r" (rx));   /* { dg-error "unsupported
size" }  */
}

Reply via email to