This fixes the first testcase in the PR by removing the trap and instead annotating the listing.

I've tested Andrew's patch and pushed it.

Aldy

    Fix PR97315 (part 1 of 2)

    gcc/ChangeLog:

            PR tree-optimization/97315
            * gimple-ssa-evrp.c (hybrid_folder::choose_value): Removes the
            trap and instead annotates the listing.

    gcc/testsuite/ChangeLog:

            * gcc.dg/pr97315-1.c: New test.

diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index 363e2ab6816..7688e4aa4bd 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -258,37 +258,43 @@ hybrid_folder::value_of_stmt (gimple *stmt, tree op)
 tree
 hybrid_folder::choose_value (tree evrp_val, tree ranger_val)
 {
-  if (!ranger_val)
-    {
-      // If neither returned a value, return NULL_TREE.
-      if (!evrp_val)
-       return NULL_TREE;
+  // If both found the same value, just return it.
+  if (evrp_val && ranger_val && !compare_values (evrp_val, ranger_val))
+    return evrp_val;
+
+  // If neither returned a value, return NULL_TREE.
+  if (!ranger_val && !evrp_val)
+    return NULL_TREE;

-      // Otherwise EVRP found something.
-      if (dump_file)
+  // Otherwise there is a discrepancy to flag.
+  if (dump_file)
+    {
+      if (evrp_val && ranger_val)
+       fprintf (dump_file, "EVRP:hybrid: Disagreement\n");
+      if (evrp_val)
        {
          fprintf (dump_file, "EVRP:hybrid: EVRP found singleton ");
          print_generic_expr (dump_file, evrp_val);
          fprintf (dump_file, "\n");
        }
-      return evrp_val;
+      if (ranger_val)
+       {
+         fprintf (dump_file, "EVRP:hybrid: RVRP found singleton ");
+         print_generic_expr (dump_file, ranger_val);
+         fprintf (dump_file, "\n");
+       }
     }

-  // Otherwise ranger found a value, if they match we're good.
-  if (evrp_val && !compare_values (evrp_val, ranger_val))
+  // If one value was found, return it.
+  if (!evrp_val)
+    return ranger_val;
+  if (!ranger_val)
     return evrp_val;

-  // We should never get different singletons.
-  gcc_checking_assert (!evrp_val);
-
-  // Now ranger has found a value, but EVRP did not.
-  if (dump_file)
-    {
-      fprintf (dump_file, "EVRP:hybrid: RVRP found singleton ");
-      print_generic_expr (dump_file, ranger_val);
-      fprintf (dump_file, "\n");
-    }
-  return ranger_val;
+  // If values are different, return the first calculated value.
+  if ((param_evrp_mode & EVRP_MODE_RVRP_FIRST) == EVRP_MODE_RVRP_FIRST)
+    return ranger_val;
+  return evrp_val;
 }

/* Main entry point for the early vrp pass which is a simplified non-iterative diff --git a/gcc/testsuite/gcc.dg/pr97315-1.c b/gcc/testsuite/gcc.dg/pr97315-1.c
new file mode 100644
index 00000000000..250e0e9ecbb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97315-1.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+typedef struct tree_node *tree;
+enum tree_code { RECORD_TYPE, QUAL_UNION_TYPE };
+enum tree_code_class {};
+struct tree_base {
+  tree_code code : 16;
+};
+struct tree_node {
+  tree_base base;
+};
+extern tree_code_class tree_code_type[];
+void tree_check_failed() __attribute__((__noreturn__));
+tree tree_check3(tree __t, tree_code __c1, tree_code __c3) {
+  if (__t->base.code != __c1 && __t->base.code != __c3)
+    tree_check_failed();
+  return __t;
+}
+tree add_type_duplicate_type;
+void add_type_duplicate() {
+  if (tree_code_type[add_type_duplicate_type->base.code])
+    if (add_type_duplicate_type->base.code == RECORD_TYPE)
+      for (;
+ tree_check3(add_type_duplicate_type, RECORD_TYPE, QUAL_UNION_TYPE);)
+        tree_check3(add_type_duplicate_type, RECORD_TYPE, QUAL_UNION_TYPE);
+}

Reply via email to