vect: fix out-of-bound access in supports_vec_convert_optab_p [PR 104851]

Message ID 2a4f73f067275a669c841722d66b274768d21851.camel@mengyan1223.wang
State Committed
Commit 1c7b110e1e44da0c93d0d011f5109c5d09bf4399
Headers
Series vect: fix out-of-bound access in supports_vec_convert_optab_p [PR 104851] |

Commit Message

Xi Ruoyao March 9, 2022, 4:05 a.m. UTC
  This should be obvious, OK for trunk?

-- >8 --

Calling VECTOR_MODE_P with MAX_MACHINE_MODE has caused out-of-bound
access.

gcc/

	PR tree-optimization/104851
	* optabs-query.cc (supports_vec_convert_optab_p): Fix off-by-one
	error.
---
 gcc/optabs-query.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Richard Biener March 9, 2022, 8:37 a.m. UTC | #1
On Wed, Mar 9, 2022 at 5:06 AM Xi Ruoyao via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This should be obvious, OK for trunk?

OK.

> -- >8 --
>
> Calling VECTOR_MODE_P with MAX_MACHINE_MODE has caused out-of-bound
> access.
>
> gcc/
>
>         PR tree-optimization/104851
>         * optabs-query.cc (supports_vec_convert_optab_p): Fix off-by-one
>         error.
> ---
>  gcc/optabs-query.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc
> index 713c098ba4e..68dc679cc6a 100644
> --- a/gcc/optabs-query.cc
> +++ b/gcc/optabs-query.cc
> @@ -720,7 +720,7 @@ static bool
>  supports_vec_convert_optab_p (optab op, machine_mode mode)
>  {
>    int start = mode == VOIDmode ? 0 : mode;
> -  int end = mode == VOIDmode ? MAX_MACHINE_MODE : mode;
> +  int end = mode == VOIDmode ? MAX_MACHINE_MODE - 1 : mode;
>    for (int i = start; i <= end; ++i)
>      if (VECTOR_MODE_P ((machine_mode) i))
>        for (int j = MIN_MODE_VECTOR_INT; j < MAX_MODE_VECTOR_INT; ++j)
> --
> 2.35.1
>
>
  
Xi Ruoyao March 9, 2022, 10:57 a.m. UTC | #2
On Wed, 2022-03-09 at 09:37 +0100, Richard Biener wrote:
> On Wed, Mar 9, 2022 at 5:06 AM Xi Ruoyao via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> > 
> > This should be obvious, OK for trunk?
> 
> OK.

Committed r12-7559.

> > -- >8 --
> > 
> > Calling VECTOR_MODE_P with MAX_MACHINE_MODE has caused out-of-bound
> > access.

/* snip */

> > -  int end = mode == VOIDmode ? MAX_MACHINE_MODE : mode;
> > +  int end = mode == VOIDmode ? MAX_MACHINE_MODE - 1 : mode;
  

Patch

diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc
index 713c098ba4e..68dc679cc6a 100644
--- a/gcc/optabs-query.cc
+++ b/gcc/optabs-query.cc
@@ -720,7 +720,7 @@  static bool
 supports_vec_convert_optab_p (optab op, machine_mode mode)
 {
   int start = mode == VOIDmode ? 0 : mode;
-  int end = mode == VOIDmode ? MAX_MACHINE_MODE : mode;
+  int end = mode == VOIDmode ? MAX_MACHINE_MODE - 1 : mode;
   for (int i = start; i <= end; ++i)
     if (VECTOR_MODE_P ((machine_mode) i))
       for (int j = MIN_MODE_VECTOR_INT; j < MAX_MODE_VECTOR_INT; ++j)