On Mon, 27 Oct 2025, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase ICEs in gcc 15 (and is at least latent in 12-14 too),
> because the DEBUG_EXPR_DECL has incorrect mode.  It has
> TREE_TYPE (orig_use_lhs) type, but TYPE_MODE (type) rather than
> TYPE_MODE (TREE_TYPE (orig_use_lhs)) where the two types are sometimes
> the same, but sometimes different (same if !has_cast_debug_uses, different
> otherwise).
> 
> Though, there wouldn't be the this issue if it used the proper API to create
> the DEBUG_EXPR_DECL which takes care of everything.  This is the sole
> spot that doesn't use that API.
> 
> Doesn't affect the trunk because the code has been removed and replaced with
> different stuff after the libstdc++ ABI change in r16-3474.
> Before r15-5557 the mode has been always wrong because this was done only
> for has_cast_debug_uses.  And the bug has been introduced with r12-5490.
> 
> Enough archeology, while it could be fixed by changing the second
> SET_DECL_MODE argument, I think it is better to use build_debug_expr_decl.
> 
> Bootstrapped/regtested on 15 branch on x86_64-linux and i686-linux, ok
> for 15 and later 14/13 (and the testcase for trunk too)?

OK.

Thanks,
Richard.

> 2025-10-27  Jakub Jelinek  <[email protected]>
> 
>       PR tree-optimization/122394
>       * tree-ssa-phiopt.cc (spaceship_replacement): Use
>       build_debug_expr_decl instead of manually building DEBUG_EXPR_DECL
>       and getting SET_DECL_MODE wrong.
> 
>       * g++.dg/opt/pr122394.C: New test.
> 
> --- gcc/tree-ssa-phiopt.cc.jj 2025-06-13 09:54:21.445964888 +0200
> +++ gcc/tree-ssa-phiopt.cc    2025-10-25 23:30:28.733458360 +0200
> @@ -2995,10 +2995,8 @@ spaceship_replacement (basic_block cond_
>             if (has_cast_debug_uses
>                 || (HONOR_NANS (TREE_TYPE (lhs1)) && !is_cast))
>               {
> -               tree temp3 = make_node (DEBUG_EXPR_DECL);
> -               DECL_ARTIFICIAL (temp3) = 1;
> -               TREE_TYPE (temp3) = TREE_TYPE (orig_use_lhs);
> -               SET_DECL_MODE (temp3, TYPE_MODE (type));
> +               tree temp3
> +                 = build_debug_expr_decl (TREE_TYPE (orig_use_lhs));
>                 if (has_cast_debug_uses)
>                   t = fold_convert (TREE_TYPE (temp3), temp2);
>                 else
> --- gcc/testsuite/g++.dg/opt/pr122394.C.jj    2025-10-25 23:33:21.375040391 
> +0200
> +++ gcc/testsuite/g++.dg/opt/pr122394.C       2025-10-25 23:33:07.589233474 
> +0200
> @@ -0,0 +1,20 @@
> +// PR tree-optimization/122394
> +// { dg-do compile { target c++23 } }
> +// { dg-options "-O1 -g" }
> +
> +#include <compare>
> +
> +struct A {
> +  friend auto operator<=> (A, A) = default;
> +  double a;
> +};
> +void foo ();
> +A b, c;
> +
> +void
> +bar ()
> +{
> +  bool d = c >= b;
> +  if (d)
> +    foo ();
> +}
> 
>       Jakub
> 
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to