diff mbox series

Add further VEC_SELECT verification

Message ID 20171011205631.GO14653@tucnak
State New
Headers show
Series Add further VEC_SELECT verification | expand

Commit Message

Jakub Jelinek Oct. 11, 2017, 8:56 p.m. UTC
Hi!

This patch adds verification that vec_select in *.md files
doesn't have any out of bounds indices in the selector.

Bootstrapped/regtested on x86_64-linux and i686-linux, tested
by building cc1 of aarch64, arm, powerpc64le and s390x cross,
and tested by hacking up sse.md to have an out of bounds access there,
ok for trunk?

2017-10-11  Jakub Jelinek  <jakub@redhat.com>

	* genrecog.c (validate_pattern): For VEC_SELECT verify that
	CONST_INT selectors are 0 to GET_MODE_NUNITS (imode) - 1.


	Jakub

Comments

Richard Biener Oct. 12, 2017, 11:59 a.m. UTC | #1
On Wed, 11 Oct 2017, Jakub Jelinek wrote:

> Hi!
> 
> This patch adds verification that vec_select in *.md files
> doesn't have any out of bounds indices in the selector.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, tested
> by building cc1 of aarch64, arm, powerpc64le and s390x cross,
> and tested by hacking up sse.md to have an out of bounds access there,
> ok for trunk?

Ok.

Richard.

> 2017-10-11  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* genrecog.c (validate_pattern): For VEC_SELECT verify that
> 	CONST_INT selectors are 0 to GET_MODE_NUNITS (imode) - 1.
> 
> --- gcc/genrecog.c.jj	2017-09-01 09:25:40.000000000 +0200
> +++ gcc/genrecog.c	2017-10-11 17:53:20.107198630 +0200
> @@ -751,6 +751,21 @@ validate_pattern (rtx pattern, md_rtx_in
>  		error_at (info->loc,
>  			  "vec_select parallel with %d elements, expected %d",
>  			  XVECLEN (XEXP (pattern, 1), 0), expected);
> +	      else if (VECTOR_MODE_P (imode))
> +		{
> +		  unsigned int nelems = GET_MODE_NUNITS (imode);
> +		  int i;
> +		  for (i = 0; i < expected; ++i)
> +		    if (CONST_INT_P (XVECEXP (XEXP (pattern, 1), 0, i))
> +			&& (UINTVAL (XVECEXP (XEXP (pattern, 1), 0, i))
> +			    >= nelems))
> +		      error_at (info->loc,
> +				"out of bounds selector %u in vec_select, "
> +				"expected at most %u",
> +				(unsigned)
> +				UINTVAL (XVECEXP (XEXP (pattern, 1), 0, i)),
> +				nelems - 1);
> +		}
>  	    }
>  	  if (imode != VOIDmode && !VECTOR_MODE_P (imode))
>  	    error_at (info->loc, "%smode of first vec_select operand is not a "
diff mbox series

Patch

--- gcc/genrecog.c.jj	2017-09-01 09:25:40.000000000 +0200
+++ gcc/genrecog.c	2017-10-11 17:53:20.107198630 +0200
@@ -751,6 +751,21 @@  validate_pattern (rtx pattern, md_rtx_in
 		error_at (info->loc,
 			  "vec_select parallel with %d elements, expected %d",
 			  XVECLEN (XEXP (pattern, 1), 0), expected);
+	      else if (VECTOR_MODE_P (imode))
+		{
+		  unsigned int nelems = GET_MODE_NUNITS (imode);
+		  int i;
+		  for (i = 0; i < expected; ++i)
+		    if (CONST_INT_P (XVECEXP (XEXP (pattern, 1), 0, i))
+			&& (UINTVAL (XVECEXP (XEXP (pattern, 1), 0, i))
+			    >= nelems))
+		      error_at (info->loc,
+				"out of bounds selector %u in vec_select, "
+				"expected at most %u",
+				(unsigned)
+				UINTVAL (XVECEXP (XEXP (pattern, 1), 0, i)),
+				nelems - 1);
+		}
 	    }
 	  if (imode != VOIDmode && !VECTOR_MODE_P (imode))
 	    error_at (info->loc, "%smode of first vec_select operand is not a "