On Tue, Apr 15, 2014 at 1:53 PM, Richard Sandiford
<rdsandif...@googlemail.com> wrote:
> As Robert pointed out here:
>
>     http://gcc.gnu.org/ml/gcc-patches/2014-04/msg00416.html
>
> we're a bit too eager when folding stuff into an 'X' constraint.
> The value at expand time is sensible, but after that asm_operand_ok
> allows arbitrary rtx expressions, including any number of registers
> as well as MEMs with unchecked addresses.
>
> This is a target-independent problem, as shown by the testcase below.
> Reload would give bogus "impossible constraint in asm" errors
> while LRA ICEs.
>
> Tested on x86_64-linux-gnu.  OK to install?

AARCH64 ran into something similar and we did a similar patch though
rejecting only mems which are invalid:
http://gcc.gnu.org/ml/gcc-patches/2012-12/msg00765.html
(http://gcc.gnu.org/ml/gcc-patches/2013-01/msg01128.html)

Thanks,
Andrew Pinski

>
> Thanks,
> Richard
>
>
> gcc/
>         * recog.c (asm_operand_ok): Tighten MEM validity for 'X'.
>
> gcc/testsuite/
>         * gcc.dg/torture/asm-x-constraint-1.c: New test.
>
> Index: gcc/recog.c
> ===================================================================
> --- gcc/recog.c 2014-04-12 22:43:54.729854903 +0100
> +++ gcc/recog.c 2014-04-15 21:47:32.139873570 +0100
> @@ -1840,7 +1840,17 @@ asm_operand_ok (rtx op, const char *cons
>           break;
>
>         case 'X':
> -         result = 1;
> +         /* Although the asm itself doesn't impose any restrictions on
> +            the operand, we still need to restrict it to something that
> +            can be reloaded and printed.
> +
> +            MEM operands are always reloaded to make them legitimate,
> +            regardless of the constraint, so we need to handle them
> +            in the same way as for 'm' and 'g'.  Since 'X' is not treated
> +            as an address constraint, the only other valid operand types
> +            are constants and registers.  */
> +         result = (CONSTANT_P (op)
> +                   || general_operand (op, VOIDmode));
>           break;
>
>         case 'g':
> Index: gcc/testsuite/gcc.dg/torture/asm-x-constraint-1.c
> ===================================================================
> --- /dev/null   2014-04-15 08:10:27.294524132 +0100
> +++ gcc/testsuite/gcc.dg/torture/asm-x-constraint-1.c   2014-04-15 
> 19:11:29.830962008 +0100
> @@ -0,0 +1,27 @@
> +void
> +noprop1 (int **x, int y, int z)
> +{
> +  int *ptr = *x + y * z / 11;
> +  __asm__ __volatile__ ("noprop1 %0" : : "X" (*ptr));
> +}
> +
> +void
> +noprop2 (int **x, int y, int z)
> +{
> +  int *ptr = *x + y * z / 11;
> +  __asm__ __volatile__ ("noprop2 %0" : : "X" (ptr));
> +}
> +
> +int *global_var;
> +
> +void
> +const1 (void)
> +{
> +  __asm__ __volatile__ ("const1 %0" : : "X" (global_var));
> +}
> +
> +void
> +const2 (void)
> +{
> +  __asm__ __volatile__ ("const2 %0" : : "X" (*global_var));
> +}

Reply via email to