https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123818

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Anyway, for the casts, I haven't succeeded making a testcase that would be
miscompiled.

This particular bug is in the CONSTRUCTOR handling,
--- gcc/tree.cc.jj      2026-01-17 14:37:22.171617643 +0100
+++ gcc/tree.cc 2026-02-03 16:16:02.637247532 +0100
@@ -6826,13 +6826,27 @@ simple_cst_equal (const_tree t1, const_t
        vec<constructor_elt, va_gc> *v2 = CONSTRUCTOR_ELTS (t2);

        if (vec_safe_length (v1) != vec_safe_length (v2))
-         return false;
+         return 0;

         for (idx = 0; idx < vec_safe_length (v1); ++idx)
-         /* ??? Should we handle also fields here? */
-         if (!simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value))
-           return false;
-       return true;
+         {
+           if ((*v1)[idx].index
+               && TREE_CODE ((*v1)[idx].index) == FIELD_DECL)
+             {
+               if ((*v1)[idx].index != (*v2)[idx].index)
+                 return 0;
+             }
+           else
+             {
+               cmp = simple_cst_equal ((*v1)[idx].index, (*v2)[idx].index);
+               if (cmp <= 0)
+                 return cmp;
+             }
+           cmp = simple_cst_equal ((*v1)[idx].value, (*v2)[idx].value);
+           if (cmp <= 0)
+             return cmp;
+         }
+       return 1;
       }

     case SAVE_EXPR:
should fix that.  The index stuff isn't strictly necessary for this bug, I've
just included it because the comment mentioned that.
The actual bug was that simple_cst_equal returns tristate rather than bool, 1
for known to be equal, 0 for known to be not equal and -1 for don't know,
contains stuff I don't understand (which is here AGGR_INIT_EXPR).  The cmp =
simple_cst_equal (...); if (cmp <= 0) return cmp; is what is used elsewhere for
calls which aren't tail recursions.

Reply via email to