On Mon, Nov 21, 2022 at 12:57:15PM +0300, Yuri Gribov wrote:
> From 4729f2db3f1b6b40ef0124e4a645788d7f66f426 Mon Sep 17 00:00:00 2001
> From: Yuri Gribov <y.gri...@samsung.com>
> Date: Sun, 14 Aug 2022 08:42:44 +0300
> Subject: [PATCH] asan: fix unsafe optimization of Asan checks.
> 
> gcc/
>         PR sanitizer/106558
>         * sanopt.c: Do not optimize out checks for non-SSA addresses.
> 
> gcc/testsuite/
>         PR sanitizer/106558
>         * c-c++-common/asan/pr106558.c: New test.
> ---
>  gcc/sanopt.cc                              | 40 +++++++++++++++++-----
>  gcc/testsuite/c-c++-common/asan/pr106558.c | 23 +++++++++++++
>  2 files changed, 54 insertions(+), 9 deletions(-)
>  create mode 100644 gcc/testsuite/c-c++-common/asan/pr106558.c
> 
> diff --git a/gcc/sanopt.cc b/gcc/sanopt.cc
> index e9d188d7889..13942a0b1da 100644
> --- a/gcc/sanopt.cc
> +++ b/gcc/sanopt.cc
> @@ -80,16 +80,16 @@ struct sanopt_info
>  
>  /* If T has a single definition of form T = T2, return T2.  */
>  
> -static tree
> +static gimple *
>  maybe_get_single_definition (tree t)
>  {
>    if (TREE_CODE (t) == SSA_NAME)
>      {
>        gimple *g = SSA_NAME_DEF_STMT (t);
>        if (gimple_assign_single_p (g))
> -     return gimple_assign_rhs1 (g);
> +     return g;
>      }
> -  return NULL_TREE;
> +  return NULL;
>  }
>  
>  /* Tree triplet for vptr_check_map.  */
> @@ -618,11 +618,30 @@ maybe_optimize_ubsan_vptr_ifn (class sanopt_ctx *ctx, 
> gimple *stmt)
>    return true;
>  }
>  
> +/* Checks whether value of T in CHECK and USE is the same.  */
> +
> +static bool same_value_p (gimple *check, gimple *use, tree t)

Formatting.  Function name should be on another line:
static bool
same_value_p (gimple *check, gimple *use, tree t)

Otherwise LGTM.  Thanks and sorry for the review delay.

        Jakub

Reply via email to