* [PATCH] Don't ICE on invalid operands in i?86 inline asm (PR target/79559)
@ 2017-02-17 18:34 Jakub Jelinek
2017-02-18 8:38 ` Uros Bizjak
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-02-17 18:34 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc-patches
Hi!
Asserts don't work really well on something we can't control in inline asm.
output_operand_lossage takes care to ICE outside of inline asm and error out
inside inline asm.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2017-02-17 Jakub Jelinek <jakub@redhat.com>
PR target/79559
* config/i386/i386.c (ix86_print_operand): Use output_operand_lossage
instead of gcc_assert for K, r and R code checks. Formatting fixes.
* gcc.target/i386/pr79559.c: New test.
--- gcc/config/i386/i386.c.jj 2017-02-14 20:34:49.000000000 +0100
+++ gcc/config/i386/i386.c 2017-02-17 11:11:27.636114439 +0100
@@ -17844,8 +17844,8 @@ ix86_print_operand (FILE *file, rtx x, i
break;
default:
- output_operand_lossage
- ("invalid operand size for operand code 'O'");
+ output_operand_lossage ("invalid operand size for operand "
+ "code 'O'");
return;
}
@@ -17879,15 +17879,14 @@ ix86_print_operand (FILE *file, rtx x, i
return;
default:
- output_operand_lossage
- ("invalid operand size for operand code 'z'");
+ output_operand_lossage ("invalid operand size for operand "
+ "code 'z'");
return;
}
}
if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
- warning
- (0, "non-integer operand used with operand code 'z'");
+ warning (0, "non-integer operand used with operand code 'z'");
/* FALLTHRU */
case 'Z':
@@ -17949,13 +17948,12 @@ ix86_print_operand (FILE *file, rtx x, i
}
else
{
- output_operand_lossage
- ("invalid operand type used with operand code 'Z'");
+ output_operand_lossage ("invalid operand type used with "
+ "operand code 'Z'");
return;
}
- output_operand_lossage
- ("invalid operand size for operand code 'Z'");
+ output_operand_lossage ("invalid operand size for operand code 'Z'");
return;
case 'd':
@@ -18154,7 +18152,12 @@ ix86_print_operand (FILE *file, rtx x, i
break;
case 'K':
- gcc_assert (CONST_INT_P (x));
+ if (!CONST_INT_P (x))
+ {
+ output_operand_lossage ("operand is not an integer, invalid "
+ "operand code 'K'");
+ return;
+ }
if (INTVAL (x) & IX86_HLE_ACQUIRE)
#ifdef HAVE_AS_IX86_HLE
@@ -18177,8 +18180,12 @@ ix86_print_operand (FILE *file, rtx x, i
return;
case 'r':
- gcc_assert (CONST_INT_P (x));
- gcc_assert (INTVAL (x) == ROUND_SAE);
+ if (!CONST_INT_P (x) || INTVAL (x) != ROUND_SAE)
+ {
+ output_operand_lossage ("operand is not a specific integer, "
+ "invalid operand code 'r'");
+ return;
+ }
if (ASSEMBLER_DIALECT == ASM_INTEL)
fputs (", ", file);
@@ -18191,7 +18198,12 @@ ix86_print_operand (FILE *file, rtx x, i
return;
case 'R':
- gcc_assert (CONST_INT_P (x));
+ if (!CONST_INT_P (x))
+ {
+ output_operand_lossage ("operand is not an integer, invalid "
+ "operand code 'R'");
+ return;
+ }
if (ASSEMBLER_DIALECT == ASM_INTEL)
fputs (", ", file);
@@ -18306,7 +18318,7 @@ ix86_print_operand (FILE *file, rtx x, i
return;
default:
- output_operand_lossage ("invalid operand code '%c'", code);
+ output_operand_lossage ("invalid operand code '%c'", code);
}
}
--- gcc/testsuite/gcc.target/i386/pr79559.c.jj 2017-02-17 11:16:18.949176256 +0100
+++ gcc/testsuite/gcc.target/i386/pr79559.c 2017-02-17 11:17:10.514479159 +0100
@@ -0,0 +1,11 @@
+/* PR target/79559 */
+/* { dg-do compile } */
+
+void
+foo (int x)
+{
+ __asm__ volatile ("# %K0" : : "r" (x)); /* { dg-error "invalid operand code" } */
+ __asm__ volatile ("# %r0" : : "r" (x)); /* { dg-error "invalid operand code" } */
+ __asm__ volatile ("# %r0" : : "n" (129)); /* { dg-error "invalid operand code" } */
+ __asm__ volatile ("# %R0" : : "r" (x)); /* { dg-error "invalid operand code" } */
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Don't ICE on invalid operands in i?86 inline asm (PR target/79559)
2017-02-17 18:34 [PATCH] Don't ICE on invalid operands in i?86 inline asm (PR target/79559) Jakub Jelinek
@ 2017-02-18 8:38 ` Uros Bizjak
0 siblings, 0 replies; 2+ messages in thread
From: Uros Bizjak @ 2017-02-18 8:38 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Fri, Feb 17, 2017 at 7:32 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> Asserts don't work really well on something we can't control in inline asm.
> output_operand_lossage takes care to ICE outside of inline asm and error out
> inside inline asm.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2017-02-17 Jakub Jelinek <jakub@redhat.com>
>
> PR target/79559
> * config/i386/i386.c (ix86_print_operand): Use output_operand_lossage
> instead of gcc_assert for K, r and R code checks. Formatting fixes.
>
> * gcc.target/i386/pr79559.c: New test.
OK for trunk and branches.
Thanks,
Uros.
> --- gcc/config/i386/i386.c.jj 2017-02-14 20:34:49.000000000 +0100
> +++ gcc/config/i386/i386.c 2017-02-17 11:11:27.636114439 +0100
> @@ -17844,8 +17844,8 @@ ix86_print_operand (FILE *file, rtx x, i
> break;
>
> default:
> - output_operand_lossage
> - ("invalid operand size for operand code 'O'");
> + output_operand_lossage ("invalid operand size for operand "
> + "code 'O'");
> return;
> }
>
> @@ -17879,15 +17879,14 @@ ix86_print_operand (FILE *file, rtx x, i
> return;
>
> default:
> - output_operand_lossage
> - ("invalid operand size for operand code 'z'");
> + output_operand_lossage ("invalid operand size for operand "
> + "code 'z'");
> return;
> }
> }
>
> if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
> - warning
> - (0, "non-integer operand used with operand code 'z'");
> + warning (0, "non-integer operand used with operand code 'z'");
> /* FALLTHRU */
>
> case 'Z':
> @@ -17949,13 +17948,12 @@ ix86_print_operand (FILE *file, rtx x, i
> }
> else
> {
> - output_operand_lossage
> - ("invalid operand type used with operand code 'Z'");
> + output_operand_lossage ("invalid operand type used with "
> + "operand code 'Z'");
> return;
> }
>
> - output_operand_lossage
> - ("invalid operand size for operand code 'Z'");
> + output_operand_lossage ("invalid operand size for operand code 'Z'");
> return;
>
> case 'd':
> @@ -18154,7 +18152,12 @@ ix86_print_operand (FILE *file, rtx x, i
> break;
>
> case 'K':
> - gcc_assert (CONST_INT_P (x));
> + if (!CONST_INT_P (x))
> + {
> + output_operand_lossage ("operand is not an integer, invalid "
> + "operand code 'K'");
> + return;
> + }
>
> if (INTVAL (x) & IX86_HLE_ACQUIRE)
> #ifdef HAVE_AS_IX86_HLE
> @@ -18177,8 +18180,12 @@ ix86_print_operand (FILE *file, rtx x, i
> return;
>
> case 'r':
> - gcc_assert (CONST_INT_P (x));
> - gcc_assert (INTVAL (x) == ROUND_SAE);
> + if (!CONST_INT_P (x) || INTVAL (x) != ROUND_SAE)
> + {
> + output_operand_lossage ("operand is not a specific integer, "
> + "invalid operand code 'r'");
> + return;
> + }
>
> if (ASSEMBLER_DIALECT == ASM_INTEL)
> fputs (", ", file);
> @@ -18191,7 +18198,12 @@ ix86_print_operand (FILE *file, rtx x, i
> return;
>
> case 'R':
> - gcc_assert (CONST_INT_P (x));
> + if (!CONST_INT_P (x))
> + {
> + output_operand_lossage ("operand is not an integer, invalid "
> + "operand code 'R'");
> + return;
> + }
>
> if (ASSEMBLER_DIALECT == ASM_INTEL)
> fputs (", ", file);
> @@ -18306,7 +18318,7 @@ ix86_print_operand (FILE *file, rtx x, i
> return;
>
> default:
> - output_operand_lossage ("invalid operand code '%c'", code);
> + output_operand_lossage ("invalid operand code '%c'", code);
> }
> }
>
> --- gcc/testsuite/gcc.target/i386/pr79559.c.jj 2017-02-17 11:16:18.949176256 +0100
> +++ gcc/testsuite/gcc.target/i386/pr79559.c 2017-02-17 11:17:10.514479159 +0100
> @@ -0,0 +1,11 @@
> +/* PR target/79559 */
> +/* { dg-do compile } */
> +
> +void
> +foo (int x)
> +{
> + __asm__ volatile ("# %K0" : : "r" (x)); /* { dg-error "invalid operand code" } */
> + __asm__ volatile ("# %r0" : : "r" (x)); /* { dg-error "invalid operand code" } */
> + __asm__ volatile ("# %r0" : : "n" (129)); /* { dg-error "invalid operand code" } */
> + __asm__ volatile ("# %R0" : : "r" (x)); /* { dg-error "invalid operand code" } */
> +}
>
> Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-18 8:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17 18:34 [PATCH] Don't ICE on invalid operands in i?86 inline asm (PR target/79559) Jakub Jelinek
2017-02-18 8:38 ` Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).