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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note while we've tried to enforce this strict rules I don't think any checking
code ever come to fruit actually verifying that calling fold_* (.., type, ...)
produces a tree of TREE_TYPE () == type.

So it would be probably better for the Fortran FE to relax this assert
to test for equal TYPE_MAIN_VARIANT.

Checking code like the following (here only applying to match.pd foldings):

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c    (revision 245908)
+++ gcc/fold-const.c    (working copy)
@@ -7617,7 +7617,10 @@ fold_unary_loc (location_t loc, enum tre

   tem = generic_simplify (loc, code, type, op0);
   if (tem)
-    return tem;
+    {
+      gcc_checking_assert (TREE_TYPE (tem) == type);
+      return tem;
+    }

   if (TREE_CODE_CLASS (code) == tcc_unary)
     {
@@ -9156,7 +9159,10 @@ fold_binary_loc (location_t loc,

   tem = generic_simplify (loc, code, type, op0, op1);
   if (tem)
-    return tem;
+    {
+      gcc_checking_assert (TREE_TYPE (tem) == type);
+      return tem;
+    }

   /* ARG0 is the first operand of EXPR, and ARG1 is the second operand.

@@ -11260,7 +11266,10 @@ fold_ternary_loc (location_t loc, enum t

   tem = generic_simplify (loc, code, type, op0, op1, op2);
   if (tem)
-    return tem;
+    {
+      gcc_checking_assert (TREE_TYPE (tem) == type);
+      return tem;
+    }

   /* Strip any conversions that don't change the mode.  This is safe
      for every expression, except for a comparison expression because

Reply via email to