https://gcc.gnu.org/g:ecc9af31a706e3cb2f3740c223478649e2bb2a93

commit r16-4661-gecc9af31a706e3cb2f3740c223478649e2bb2a93
Author: Jakub Jelinek <[email protected]>
Date:   Mon Oct 27 17:40:47 2025 +0100

    phiopt: Fix up DEBUG_EXPR_DECL creation in spaceship_replacement [PR122394]
    
    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.
    
    On the trunk only the testcase is being added.
    
    2025-10-27  Jakub Jelinek  <[email protected]>
    
            PR tree-optimization/122394
            * g++.dg/opt/pr122394.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/opt/pr122394.C | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/gcc/testsuite/g++.dg/opt/pr122394.C 
b/gcc/testsuite/g++.dg/opt/pr122394.C
new file mode 100644
index 000000000000..1f84bebd74c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr122394.C
@@ -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 ();
+}

Reply via email to