[Bug fortran/106121] ICE in gfc_simplify_extends_type_of, at fortran/simplify.cc:3109

anlauf at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jun 28 19:43:39 GMT 2022


anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #3 from anlauf at gcc dot gnu.org ---
(In reply to kargl from comment #2)
> Infamous NULL pointer dereference.


Shorter fix:

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index e8e3ec63669..b5112da441a 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -3096,6 +3096,10 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr
     return NULL;

+  if ((a->ts.type == BT_CLASS && !gfc_expr_attr (a).class_ok)
+      || (mold->ts.type == BT_CLASS && !gfc_expr_attr (mold).class_ok))
+    return NULL;
   /* Return .false. if the dynamic type can never be an extension.  */
   if ((a->ts.type == BT_CLASS && mold->ts.type == BT_CLASS
        && !gfc_type_is_extension_of

I think we need a good (better) set of macros to concisely handle problems
like the above to improve error recovery.

More information about the Gcc-bugs mailing list