On Fri, Apr 25, 2025 at 1:57 AM Andrew Pinski <quic_apin...@quicinc.com> wrote:
>
> While working on PR 119903, I noticed that there is code in 
> replace_stmt_with_simplification
> which makes sure that the comparison of a GIMPLE_COND does not throw
> (non-call exceptions and trapping math) but the gimple verifier does not
> verify this. So let's add it.
>
> Bootstrapped and tested on x86_64-linux-gnu.

OK.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         * tree-cfg.cc (verify_gimple_cond): Error out if the comparison
>         throws.
>
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
>  gcc/tree-cfg.cc | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
> index 6a29a56ca9a..712bda1f8ca 100644
> --- a/gcc/tree-cfg.cc
> +++ b/gcc/tree-cfg.cc
> @@ -5113,6 +5113,19 @@ verify_gimple_cond (gcond *stmt)
>        return true;
>      }
>
> +  tree lhs = gimple_cond_lhs (stmt);
> +
> +  /* GIMPLE_CONDs condition may not throw.  */
> +  if (flag_exceptions
> +      && cfun->can_throw_non_call_exceptions
> +      && operation_could_trap_p (gimple_cond_code (stmt),
> +                                FLOAT_TYPE_P (TREE_TYPE (lhs)),
> +                                false, NULL_TREE))
> +    {
> +      error ("gimple cond condition cannot throw");
> +      return true;
> +    }
> +
>    return verify_gimple_comparison (boolean_type_node,
>                                    gimple_cond_lhs (stmt),
>                                    gimple_cond_rhs (stmt),
> --
> 2.43.0
>

Reply via email to