Commit 04f1c830 by Janus Weil

re PR fortran/66227 ([OOP] EXTENDS_TYPE_OF n returns wrong result for…

re PR fortran/66227 ([OOP] EXTENDS_TYPE_OF n returns wrong result for polymorphic variable allocated to extended type)

2016-11-17  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/66227
	* simplify.c (gfc_simplify_extends_type_of): Fix missed optimization.
	Prevent over-simplification. Fix a comment. Add a comment.

2016-11-17  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/66227
	* gfortran.dg/extends_type_of_3.f90: Fix and extend the test case.

From-SVN: r242535
parent 9bd99cce
2016-11-17 Janus Weil <janus@gcc.gnu.org>
PR fortran/66227
* simplify.c (gfc_simplify_extends_type_of): Fix missed optimization.
Prevent over-simplification. Fix a comment. Add a comment.
2016-11-16 Steven G. Kargl <kargl@gcc.gnu.org> 2016-11-16 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/58001 PR fortran/58001
......
...@@ -2517,7 +2517,7 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold) ...@@ -2517,7 +2517,7 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold)
if (UNLIMITED_POLY (a) || UNLIMITED_POLY (mold)) if (UNLIMITED_POLY (a) || UNLIMITED_POLY (mold))
return NULL; 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 if ((a->ts.type == BT_CLASS && mold->ts.type == BT_CLASS
&& !gfc_type_is_extension_of && !gfc_type_is_extension_of
(mold->ts.u.derived->components->ts.u.derived, (mold->ts.u.derived->components->ts.u.derived,
...@@ -2527,18 +2527,19 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold) ...@@ -2527,18 +2527,19 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold)
mold->ts.u.derived->components->ts.u.derived)) mold->ts.u.derived->components->ts.u.derived))
|| (a->ts.type == BT_DERIVED && mold->ts.type == BT_CLASS || (a->ts.type == BT_DERIVED && mold->ts.type == BT_CLASS
&& !gfc_type_is_extension_of && !gfc_type_is_extension_of
(a->ts.u.derived,
mold->ts.u.derived->components->ts.u.derived)
&& !gfc_type_is_extension_of
(mold->ts.u.derived->components->ts.u.derived, (mold->ts.u.derived->components->ts.u.derived,
a->ts.u.derived)) a->ts.u.derived))
|| (a->ts.type == BT_CLASS && mold->ts.type == BT_DERIVED || (a->ts.type == BT_CLASS && mold->ts.type == BT_DERIVED
&& !gfc_type_is_extension_of && !gfc_type_is_extension_of
(mold->ts.u.derived, (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); return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, false);
if (mold->ts.type == BT_DERIVED /* Return .true. if the dynamic type is guaranteed to be an extension. */
if (a->ts.type == BT_CLASS && mold->ts.type == BT_DERIVED
&& gfc_type_is_extension_of (mold->ts.u.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))
return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, true); return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, true);
......
2016-11-17 Janus Weil <janus@gcc.gnu.org>
PR fortran/66227
* gfortran.dg/extends_type_of_3.f90: Fix and extend the test case.
2016-11-16 Marek Polacek <polacek@redhat.com> 2016-11-16 Marek Polacek <polacek@redhat.com>
PR c/78285 PR c/78285
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
! !
! PR fortran/41580 ! PR fortran/41580
! !
! Compile-time simplification of SAME_TYPE_AS ! Compile-time simplification of SAME_TYPE_AS and EXTENDS_TYPE_OF.
! and EXTENDS_TYPE_OF.
!
implicit none implicit none
type t1 type t1
...@@ -37,6 +35,8 @@ logical, parameter :: p6 = same_type_as(a1,a1) ! T ...@@ -37,6 +35,8 @@ logical, parameter :: p6 = same_type_as(a1,a1) ! T
if (p1 .or. p2 .or. p3 .or. p4 .or. .not. p5 .or. .not. p6) call should_not_exist() if (p1 .or. p2 .or. p3 .or. p4 .or. .not. p5 .or. .not. p6) call should_not_exist()
if (same_type_as(b1,b1) .neqv. .true.) call should_not_exist()
! Not (trivially) compile-time simplifiable: ! Not (trivially) compile-time simplifiable:
if (same_type_as(b1,a1) .neqv. .true.) call abort() if (same_type_as(b1,a1) .neqv. .true.) call abort()
if (same_type_as(b1,a11) .neqv. .false.) call abort() if (same_type_as(b1,a11) .neqv. .false.) call abort()
...@@ -49,6 +49,7 @@ if (same_type_as(b1,a1) .neqv. .false.) call abort() ...@@ -49,6 +49,7 @@ if (same_type_as(b1,a1) .neqv. .false.) call abort()
if (same_type_as(b1,a11) .neqv. .true.) call abort() if (same_type_as(b1,a11) .neqv. .true.) call abort()
deallocate(b1) deallocate(b1)
! .true. -> same type ! .true. -> same type
if (extends_type_of(a1,a1) .neqv. .true.) call should_not_exist() if (extends_type_of(a1,a1) .neqv. .true.) call should_not_exist()
if (extends_type_of(a11,a11) .neqv. .true.) call should_not_exist() if (extends_type_of(a11,a11) .neqv. .true.) call should_not_exist()
...@@ -78,33 +79,47 @@ if (extends_type_of(a2,b11) .neqv. .false.) call should_not_exist() ...@@ -78,33 +79,47 @@ if (extends_type_of(a2,b11) .neqv. .false.) call should_not_exist()
! type extension possible, compile-time checkable ! type extension possible, compile-time checkable
if (extends_type_of(a1,a11) .neqv. .false.) call should_not_exist() if (extends_type_of(a1,a11) .neqv. .false.) call should_not_exist()
if (extends_type_of(a11,a1) .neqv. .true.) call should_not_exist() if (extends_type_of(a11,a1) .neqv. .true.) call should_not_exist()
if (extends_type_of(a1,a11) .neqv. .false.) call should_not_exist()
if (extends_type_of(b1,a1) .neqv. .true.) call should_not_exist() if (extends_type_of(b1,a1) .neqv. .true.) call should_not_exist()
if (extends_type_of(b11,a1) .neqv. .true.) call should_not_exist() if (extends_type_of(b11,a1) .neqv. .true.) call should_not_exist()
if (extends_type_of(b11,a11) .neqv. .true.) call should_not_exist() if (extends_type_of(b11,a11) .neqv. .true.) call should_not_exist()
if (extends_type_of(b1,a11) .neqv. .false.) call should_not_exist()
if (extends_type_of(a1,b11) .neqv. .false.) call abort() if (extends_type_of(a1,b11) .neqv. .false.) call should_not_exist()
! Special case, simplified at tree folding: ! Special case, simplified at tree folding:
if (extends_type_of(b1,b1) .neqv. .true.) call abort() if (extends_type_of(b1,b1) .neqv. .true.) call abort()
! All other possibilities are not compile-time checkable ! All other possibilities are not compile-time checkable
if (extends_type_of(b11,b1) .neqv. .true.) call abort() if (extends_type_of(b11,b1) .neqv. .true.) call abort()
!if (extends_type_of(b1,b11) .neqv. .false.) call abort() ! FAILS due to PR 47189 if (extends_type_of(b1,b11) .neqv. .false.) call abort()
if (extends_type_of(a11,b11) .neqv. .true.) call abort() if (extends_type_of(a11,b11) .neqv. .true.) call abort()
allocate(t11 :: b11) allocate(t11 :: b11)
if (extends_type_of(a11,b11) .neqv. .true.) call abort() if (extends_type_of(a11,b11) .neqv. .true.) call abort()
deallocate(b11) deallocate(b11)
allocate(t111 :: b11) allocate(t111 :: b11)
if (extends_type_of(a11,b11) .neqv. .false.) call abort() if (extends_type_of(a11,b11) .neqv. .false.) call abort()
deallocate(b11) deallocate(b11)
allocate(t11 :: b1) allocate(t11 :: b1)
if (extends_type_of(a11,b1) .neqv. .true.) call abort() if (extends_type_of(a11,b1) .neqv. .true.) call abort()
deallocate(b1) deallocate(b1)
allocate(t11::b1)
if (extends_type_of(b1,a11) .neqv. .true.) call abort()
deallocate(b1)
allocate(b1,source=a11)
if (extends_type_of(b1,a11) .neqv. .true.) call abort()
deallocate(b1)
allocate( b1,source=a1)
if (extends_type_of(b1,a11) .neqv. .false.) call abort()
deallocate(b1)
end end
! { dg-final { scan-tree-dump-times "abort" 13 "original" } } ! { dg-final { scan-tree-dump-times "abort" 16 "original" } }
! { dg-final { scan-tree-dump-times "should_not_exist" 0 "original" } } ! { dg-final { scan-tree-dump-times "should_not_exist" 0 "original" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment