Message ID | 20170217183248.GN1849@tucnak |
---|---|
State | New |
Headers | show |
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
--- 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" } */ +}