From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id DD8123858C55; Sun, 3 Jul 2022 20:13:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD8123858C55 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10106] Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 000b61056e6772876a95ec0891c373f0b4b6cea8 X-Git-Newrev: 19f6e8ddfc447ac3b6198ab4b0176323e75a65cc Message-Id: <20220703201338.DD8123858C55@sourceware.org> Date: Sun, 3 Jul 2022 20:13:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jul 2022 20:13:39 -0000 https://gcc.gnu.org/g:19f6e8ddfc447ac3b6198ab4b0176323e75a65cc commit r11-10106-g19f6e8ddfc447ac3b6198ab4b0176323e75a65cc Author: Harald Anlauf Date: Tue Jun 28 22:29:28 2022 +0200 Fortran: improve error recovery for EXTENDS_TYPE_OF() [PR106121] gcc/fortran/ChangeLog: PR fortran/106121 * simplify.c (gfc_simplify_extends_type_of): Do not attempt to simplify when one of the arguments is a CLASS variable that was not properly declared. gcc/testsuite/ChangeLog: PR fortran/106121 * gfortran.dg/extends_type_of_4.f90: New test. Co-authored-by: Steven G. Kargl (cherry picked from commit b8f284d3673004dffae714b56ed663467c2a52a7) Diff: --- gcc/fortran/simplify.c | 4 ++++ gcc/testsuite/gfortran.dg/extends_type_of_4.f90 | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index c9334b9b725..85ea1311c7e 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -3092,6 +3092,10 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold) if (UNLIMITED_POLY (a) || UNLIMITED_POLY (mold)) 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 diff --git a/gcc/testsuite/gfortran.dg/extends_type_of_4.f90 b/gcc/testsuite/gfortran.dg/extends_type_of_4.f90 new file mode 100644 index 00000000000..64373322387 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/extends_type_of_4.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } +! PR fortran/106121 - ICE in gfc_simplify_extends_type_of +! Contributed by G.Steinmetz + +program p + type t + end type + type(t) :: x + class(t) :: y ! { dg-error "dummy, allocatable or pointer" } + print *, extends_type_of (x, y) +end + +subroutine s + type t + integer :: i + end type + type(t) :: x + class(t) :: y ! { dg-error "dummy, allocatable or pointer" } + stop extends_type_of (x, y) ! { dg-error "STOP code" } +end