public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742)
@ 2018-03-08 18:19 Jakub Jelinek
  2018-03-08 20:43 ` Jeff Law
  2018-03-12 11:18 ` H.J. Lu
  0 siblings, 2 replies; 4+ messages in thread
From: Jakub Jelinek @ 2018-03-08 18:19 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

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'" } */
+}
--- gcc/testsuite/gcc.target/i386/pr84742-2.c.jj	2018-03-08 14:12:37.205499976 +0100
+++ gcc/testsuite/gcc.target/i386/pr84742-2.c	2018-03-08 14:12:52.150506968 +0100
@@ -0,0 +1,10 @@
+/* PR inline-asm/84742 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void 
+foo ()
+{
+  char b = 1;
+  asm volatile ("" : "+gT,m" (b));	/* { dg-error "impossible constraint in 'asm'" } */
+}

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742)
  2018-03-08 18:19 [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742) Jakub Jelinek
@ 2018-03-08 20:43 ` Jeff Law
  2018-03-12 11:18 ` H.J. Lu
  1 sibling, 0 replies; 4+ messages in thread
From: Jeff Law @ 2018-03-08 20:43 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches

On 03/08/2018 11:19 AM, Jakub Jelinek 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.
OK.
jeff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742)
  2018-03-08 18:19 [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742) Jakub Jelinek
  2018-03-08 20:43 ` Jeff Law
@ 2018-03-12 11:18 ` H.J. Lu
  2018-03-12 11:49   ` H.J. Lu
  1 sibling, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2018-03-12 11:18 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, Jeff Law, GCC Patches

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742)
  2018-03-12 11:18 ` H.J. Lu
@ 2018-03-12 11:49   ` H.J. Lu
  0 siblings, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2018-03-12 11:49 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, Jeff Law, GCC Patches

On Mon, Mar 12, 2018 at 4:18 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> 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]$
>
>

I opened;

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84831


-- 
H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-12 11:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-08 18:19 [PATCH] Diagnose earlier invalid inline asm constraints (PR inline-asm/84742) Jakub Jelinek
2018-03-08 20:43 ` Jeff Law
2018-03-12 11:18 ` H.J. Lu
2018-03-12 11:49   ` H.J. Lu

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).