diff options
author | Harald Anlauf <anlauf@gmx.de> | 2021-12-27 23:06:18 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2021-12-29 18:27:39 +0100 |
commit | d8f6c48ccb85ecc0d97a84c32b7a1b8f43c64fe4 (patch) | |
tree | dea966826379a1cb42a526f2273eb0d30856e8e1 /gcc/fortran/resolve.c | |
parent | ad964f7eaef9c03ce68a01cfdd7fde9d56524868 (diff) | |
download | gcc-d8f6c48ccb85ecc0d97a84c32b7a1b8f43c64fe4.zip gcc-d8f6c48ccb85ecc0d97a84c32b7a1b8f43c64fe4.tar.gz gcc-d8f6c48ccb85ecc0d97a84c32b7a1b8f43c64fe4.tar.bz2 |
Fortran: avoid several NULL pointer dereferences during error recovery
gcc/fortran/ChangeLog:
PR fortran/102332
* expr.c (gfc_get_variable_expr): Avoid NULL pointer dereferences
during handling of errors with invalid uses of CLASS variables.
* match.c (select_type_set_tmp): Likewise.
* primary.c (gfc_match_varspec): Likewise.
* resolve.c (resolve_variable): Likewise.
(resolve_select_type): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/102332
* gfortran.dg/pr102332.f90: New test.
Diffstat (limited to 'gcc/fortran/resolve.c')
-rw-r--r-- | gcc/fortran/resolve.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index bff1b35..591e818 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5736,6 +5736,8 @@ resolve_variable (gfc_expr *e) can't be translated that way. */ if (sym->assoc && e->rank == 0 && e->ref && sym->ts.type == BT_CLASS && sym->assoc->target && sym->assoc->target->ts.type == BT_CLASS + && sym->assoc->target->ts.u.derived + && CLASS_DATA (sym->assoc->target) && CLASS_DATA (sym->assoc->target)->as) { gfc_ref *ref = e->ref; @@ -5799,7 +5801,8 @@ resolve_variable (gfc_expr *e) /* Like above, but for class types, where the checking whether an array ref is present is more complicated. Furthermore make sure not to add the full array ref to _vptr or _len refs. */ - if (sym->assoc && sym->ts.type == BT_CLASS + if (sym->assoc && sym->ts.type == BT_CLASS && sym->ts.u.derived + && CLASS_DATA (sym) && CLASS_DATA (sym)->attr.dimension && (e->ts.type != BT_DERIVED || !e->ts.u.derived->attr.vtype)) { @@ -9432,6 +9435,7 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) /* Check F03:C815. */ if ((c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS) + && selector_type && !selector_type->attr.unlimited_polymorphic && !gfc_type_is_extensible (c->ts.u.derived)) { @@ -9442,7 +9446,8 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) } /* Check F03:C816. */ - if (c->ts.type != BT_UNKNOWN && !selector_type->attr.unlimited_polymorphic + if (c->ts.type != BT_UNKNOWN + && selector_type && !selector_type->attr.unlimited_polymorphic && ((c->ts.type != BT_DERIVED && c->ts.type != BT_CLASS) || !gfc_type_is_extension_of (selector_type, c->ts.u.derived))) { |