On Wed, May 21, 2025 at 3:44 AM Andrew Pinski <quic_apin...@quicinc.com> wrote:
>
> This was introduced by r15-1797-gd8fe4f05ef448e . I had missed that
> the LHS of the cabs call could be NULL. This seems to only happen at -O0,
> I tried to produce one that happens at -O1 but needed many different
> options to prevent the removal of the call.
> Anyways the fix is just keep around the call if the LHS is null.
>
> Bootstrapped and tested on x86_64-linux-gnu.

OK

>         PR middle-end/120369
>
> gcc/ChangeLog:
>
>         * tree-complex.cc (gimple_expand_builtin_cabs): Return early
>         if the LHS of cabs is null.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/torture/pr120369-1.c: New test.
>
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
>  gcc/testsuite/gcc.dg/torture/pr120369-1.c | 9 +++++++++
>  gcc/tree-complex.cc                       | 4 ++++
>  2 files changed, 13 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/torture/pr120369-1.c
>
> diff --git a/gcc/testsuite/gcc.dg/torture/pr120369-1.c 
> b/gcc/testsuite/gcc.dg/torture/pr120369-1.c
> new file mode 100644
> index 00000000000..4c20fb0932f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr120369-1.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* PR middle-end/120369 */
> +
> +/* Make sure cabs without a lhs does not cause an ICE. */
> +void f()
> +{
> +  double _Complex z = 1.0;
> +  __builtin_cabs(z);
> +}
> diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc
> index 8a812d4bf9b..e339b3a5b37 100644
> --- a/gcc/tree-complex.cc
> +++ b/gcc/tree-complex.cc
> @@ -1715,6 +1715,10 @@ gimple_expand_builtin_cabs (gimple_stmt_iterator *gsi, 
> gimple *old_stmt)
>
>    tree lhs = gimple_call_lhs (old_stmt);
>
> +  /* If there is not a LHS, then just keep the statement around.  */
> +  if (!lhs)
> +    return;
> +
>    real_part = extract_component (gsi, arg, false, true);
>    imag_part = extract_component (gsi, arg, true, true);
>    location_t loc = gimple_location (old_stmt);
> --
> 2.43.0
>

Reply via email to