[Bug fortran/107217] ICE in gfc_arith_times, at fortran/arith.cc:715/704

anlauf at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 11 19:41:08 GMT 2022


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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-10-11
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

Testing the following patch:

diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index 9e079e42995..c224cd30a54 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -692,6 +692,9 @@ gfc_arith_times (gfc_expr *op1, gfc_expr *op2, gfc_expr
**resultp)
   gfc_expr *result;
   arith rc;

+  if (op1->ts.type != op2->ts.type)
+    return ARITH_INVALID_TYPE;
+
   result = gfc_get_constant_expr (op1->ts.type, op1->ts.kind, &op1->where);

   switch (op1->ts.type)
@@ -712,7 +715,8 @@ gfc_arith_times (gfc_expr *op1, gfc_expr *op2, gfc_expr
**resultp)
       break;

     default:
-      gfc_internal_error ("gfc_arith_times(): Bad basic type");
+      gfc_free_expr (result);
+      return ARITH_INVALID_TYPE;
     }

   rc = gfc_range_check (result);


More information about the Gcc-bugs mailing list