diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2021-10-18 09:49:05 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2021-10-18 09:49:05 +0200 |
commit | 017665f63047ce47b087b0b283548a60e5abf3d2 (patch) | |
tree | 5403224f6c3336a461883cb8719614f9fac07c20 /gcc/fortran | |
parent | f5b37435968bc76498481177593121d238f854fb (diff) | |
download | gcc-017665f63047ce47b087b0b283548a60e5abf3d2.zip gcc-017665f63047ce47b087b0b283548a60e5abf3d2.tar.gz gcc-017665f63047ce47b087b0b283548a60e5abf3d2.tar.bz2 |
Fortran: Fix CLASS conversion check [PR102745]
PR fortran/102745
gcc/fortran/ChangeLog
* intrinsic.c (gfc_convert_type_warn): Fix checks by checking CLASS
and do typcheck in correct order for type extension.
* misc.c (gfc_typename): Print proper not internal CLASS type name.
gcc/testsuite/ChangeLog
* gfortran.dg/class_72.f90: New.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/intrinsic.c | 7 | ||||
-rw-r--r-- | gcc/fortran/misc.c | 10 |
2 files changed, 9 insertions, 8 deletions
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 219f04f..f5c88d9 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -5237,12 +5237,13 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag, /* In building an array constructor, gfortran can end up here when no conversion is required for an intrinsic type. We need to let derived types drop through. */ - if (from_ts.type != BT_DERIVED + if (from_ts.type != BT_DERIVED && from_ts.type != BT_CLASS && (from_ts.type == ts->type && from_ts.kind == ts->kind)) return true; - if (expr->ts.type == BT_DERIVED && ts->type == BT_DERIVED - && gfc_compare_types (&expr->ts, ts)) + if ((expr->ts.type == BT_DERIVED || expr->ts.type == BT_CLASS) + && (ts->type == BT_DERIVED || ts->type == BT_CLASS) + && gfc_compare_types (ts, &expr->ts)) return true; /* If array is true then conversion is in an array constructor where diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c index 3d449ae1..e6402e8 100644 --- a/gcc/fortran/misc.c +++ b/gcc/fortran/misc.c @@ -130,7 +130,6 @@ gfc_typename (gfc_typespec *ts, bool for_hash) static char buffer2[GFC_MAX_SYMBOL_LEN + 8]; static int flag = 0; char *buffer; - gfc_typespec *ts1; gfc_charlen_t length = 0; buffer = flag ? buffer1 : buffer2; @@ -180,16 +179,17 @@ gfc_typename (gfc_typespec *ts, bool for_hash) sprintf (buffer, "TYPE(%s)", ts->u.derived->name); break; case BT_CLASS: - if (ts->u.derived == NULL) + if (!ts->u.derived || !ts->u.derived->components + || !ts->u.derived->components->ts.u.derived) { sprintf (buffer, "invalid class"); break; } - ts1 = ts->u.derived->components ? &ts->u.derived->components->ts : NULL; - if (ts1 && ts1->u.derived && ts1->u.derived->attr.unlimited_polymorphic) + if (ts->u.derived->components->ts.u.derived->attr.unlimited_polymorphic) sprintf (buffer, "CLASS(*)"); else - sprintf (buffer, "CLASS(%s)", ts->u.derived->name); + sprintf (buffer, "CLASS(%s)", + ts->u.derived->components->ts.u.derived->name); break; case BT_ASSUMED: sprintf (buffer, "TYPE(*)"); |