[PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742)
H.J. Lu
hjl.tools@gmail.com
Mon Mar 12 11:18:00 GMT 2018
On Thu, Mar 8, 2018 at 10:19 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> We have many loops that use CONSTRAINT_LEN to skip over various constraint
> characters, but we assume the constraints have valid length and don't walk
> the individual characters to double check this.
>
> If that is not the case, when e.g. 2 character constraint starting letter
> is followed by '\0', we'd reject it early (during vregs pass, through
> asm_operand_ok). The PR has different testcase (that fails randomly based
> on ASLR), where a 2 character constraint starting letter is followed by ',',
> and several spots expect that not to happen (they count number of
> alternatives and then for each alternative walk with skipping CONSTRAINT_LEN
> characters).
>
> This patch diagnoses this problematic case early as well.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-03-08 Jakub Jelinek <jakub@redhat.com>
>
> PR inline-asm/84742
> * recog.c (asm_operand_ok): Return 0 if multi-character constraint
> has ',' character inside of it.
>
> * gcc.target/i386/pr84742-1.c: New test.
> * gcc.target/i386/pr84742-2.c: New test.
>
> --- gcc/recog.c.jj 2018-01-16 09:53:47.000000000 +0100
> +++ gcc/recog.c 2018-03-08 14:04:35.889274871 +0100
> @@ -1825,7 +1825,7 @@ asm_operand_ok (rtx op, const char *cons
> len = CONSTRAINT_LEN (c, constraint);
> do
> constraint++;
> - while (--len && *constraint);
> + while (--len && *constraint && *constraint != ',');
> if (len)
> return 0;
> }
> --- gcc/testsuite/gcc.target/i386/pr84742-1.c.jj 2018-03-08 14:11:20.155463943 +0100
> +++ gcc/testsuite/gcc.target/i386/pr84742-1.c 2018-03-08 14:12:28.453495882 +0100
> @@ -0,0 +1,10 @@
> +/* PR inline-asm/84742 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +void
> +foo ()
> +{
> + char b = 1;
> + asm volatile ("" : "+T,Y" (b)); /* { dg-error "impossible constraint in 'asm'" } */
> +}
This test fails at random on 32-bit hosts (i686 and x32). Sometimes I got
spawn -ignore SIGHUP
/export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/xgcc
-B/export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c
-m32 -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -S -o
pr84742-1.s
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:
In function 'foo':
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:9:3:
error: matching constraint not valid in output operand
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:9:3:
error: matching constraint not valid in output operand
FAIL: gcc.target/i386/pr84742-1.c (test for errors, line 9)
FAIL: gcc.target/i386/pr84742-1.c (test for excess errors)
But when I ran it by hand:
[hjl@gnu-skx-1 gcc]$
/export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/xgcc
-B/export/build/gnu/gcc-32bit-all-test/build-i686-linux/gcc/
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c
-m32 -fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -S -o
pr84742-1.s
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:
In function \u2018foo\u2019:
/export/gnu/import/git/sources/gcc/gcc/testsuite/gcc.target/i386/pr84742-1.c:9:3:
error: impossible constraint in \u2018asm\u2019
[hjl@gnu-skx-1 gcc]$
--
H.J.
More information about the Gcc-patches
mailing list