[Patch, Fortran] PR 66227: [5/6/7 Regression] [OOP] EXTENDS_TYPE_OF n returns wrong result for polymorphic variable allocated to extended type
Mikael Morin
morin-mikael@orange.fr
Tue Nov 15 22:36:00 GMT 2016
Le 15/11/2016 à 21:19, Janus Weil a écrit :
> Hi all,
>
> the attached patch fixes a wrong-code problem with the intrinsic
> function EXTENDS_TYPE_OF. The simplification function which tries to
> reduce calls to EXTENDS_TYPE_OF to a compile-time constant (if
> possible) was a bit over-zealous and simplified cases that were
> actually not decidable at compile-time, thus causing wrong code.
>
> The patch fixes the simplification function and also the corresponding
> test case (which unfortunately was wrong as well) and regtests
> cleanly. Ok for trunk and the release branches?
>
> Cheers,
> Janus
>
>
>
> 2016-11-15 Janus Weil <janus@gcc.gnu.org>
>
> PR fortran/66227
> * simplify.c (gfc_simplify_extends_type_of): Prevent over-
> simplification. Fix a comment. Add a comment.
>
> 2016-11-15 Janus Weil <janus@gcc.gnu.org>
>
> PR fortran/66227
> * gfortran.dg/extends_type_of_3.f90: Fix and extend the test case.
>
>
> Index: gcc/fortran/simplify.c
> ===================================================================
> --- gcc/fortran/simplify.c (Revision 242447)
> +++ gcc/fortran/simplify.c (Arbeitskopie)
> @@ -2517,7 +2517,7 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_exp
> if (UNLIMITED_POLY (a) || UNLIMITED_POLY (mold))
> return NULL;
>
> - /* Return .false. if the dynamic type can never be the same. */
> + /* 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
> (mold->ts.u.derived->components->ts.u.derived,
> @@ -2535,10 +2535,14 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_exp
> || (a->ts.type == BT_CLASS && mold->ts.type == BT_DERIVED
> && !gfc_type_is_extension_of
> (mold->ts.u.derived,
> - a->ts.u.derived->components->ts.u.derived)))
> + a->ts.u.derived->components->ts.u.derived)
> + && !gfc_type_is_extension_of
> + (a->ts.u.derived->components->ts.u.derived,
> + mold->ts.u.derived)))
> return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, false);
Hello,
this doesnât catch the case where «mold» is of a base type and «a» of
extended class.
I believe gfc_type_is_extension is misused here. The original code
intended meaning was probably that «a» is known not to be an extension
of «mold», but the negation of gfc_type_is_extension only gives that
itâs not known to be, which is weaker.
Mikael
More information about the Fortran
mailing list