From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1431) id D48753858D28; Mon, 6 May 2024 07:45:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D48753858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714981534; bh=FWF3cV3KpB7oTML7gubqfEoHz3Jru6/LasEN72EJAvI=; h=From:To:Subject:Date:From; b=dI43jDY0btg/PpKy41PIb1LJpQ5SMYt0yAgcNkc7SPPEqW+h+TO8VIYedeDlg5TUH 6MyBBgRBu0CxqkLgSYwycZTvJNmiWwC1g/9Kk7ZooiG1XDCjc+PWPxXpa6iO8o+KwO /VtFW5vQke1l2avorgq99xH1NdNvTGKEAiMDemVc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Paul Thomas To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-10415] Fortran: Fix ICE and clear incorrect error messages [PR114739] X-Act-Checkin: gcc X-Git-Author: Paul Thomas X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: c2a574785f491f88c3970976d30ae19e78c9ec7f X-Git-Newrev: 3a5acd2583056e8cd0e5fda83e7c34be65415c62 Message-Id: <20240506074534.D48753858D28@sourceware.org> Date: Mon, 6 May 2024 07:45:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3a5acd2583056e8cd0e5fda83e7c34be65415c62 commit r12-10415-g3a5acd2583056e8cd0e5fda83e7c34be65415c62 Author: Paul Thomas Date: Mon May 6 08:21:14 2024 +0100 Fortran: Fix ICE and clear incorrect error messages [PR114739] 2024-05-06 Paul Thomas gcc/fortran PR fortran/114739 * primary.cc (gfc_match_varspec): Check for default type before checking for derived types with the right component name. gcc/testsuite/ PR fortran/114739 * gfortran.dg/pr114739.f90: New test. * gfortran.dg/derived_comp_array_ref_8.f90: Add 'implicit none' for consistency with expected error message. * gfortran.dg/nullify_4.f90: ditto * gfortran.dg/pointer_init_6.f90: ditto * gfortran.dg/pr107397.f90: ditto * gfortran.dg/pr88138.f90: ditto (cherry picked from commit 094f8a36dffea52fe6a64596203b82648a3f6121) Diff: --- gcc/fortran/primary.cc | 9 +++++++++ gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 | 1 + gcc/testsuite/gfortran.dg/nullify_4.f90 | 1 + gcc/testsuite/gfortran.dg/pointer_init_6.f90 | 2 +- gcc/testsuite/gfortran.dg/pr107397.f90 | 1 + gcc/testsuite/gfortran.dg/pr114739.f90 | 11 +++++++++++ gcc/testsuite/gfortran.dg/pr88138.f90 | 1 + 7 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 78295c54b6c..4f8bd129ee9 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -2207,6 +2207,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, match mm; old_loc = gfc_current_locus; mm = gfc_match_name (name); + + /* Check to see if this has a default type. */ + if (sym->ts.type == BT_UNKNOWN && tgt_expr == NULL + && gfc_get_default_type (sym->name, sym->ns)->type != BT_UNKNOWN) + { + gfc_set_default_type (sym, 0, sym->ns); + primary->ts = sym->ts; + } + if (mm == MATCH_YES && is_inquiry_ref (name, &tmp)) inquiry = true; gfc_current_locus = old_loc; diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 index 739f4adfb78..22dfdc668a6 100644 --- a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 +++ b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 @@ -2,6 +2,7 @@ ! ! PR fortran/52325 ! +implicit none real :: f cc%a = 5 ! { dg-error "Symbol 'cc' at .1. has no IMPLICIT type" } f%a = 5 ! { dg-error "Unexpected '%' for nonderived-type variable 'f' at" } diff --git a/gcc/testsuite/gfortran.dg/nullify_4.f90 b/gcc/testsuite/gfortran.dg/nullify_4.f90 index 0fd5056ee07..240110fabf8 100644 --- a/gcc/testsuite/gfortran.dg/nullify_4.f90 +++ b/gcc/testsuite/gfortran.dg/nullify_4.f90 @@ -3,6 +3,7 @@ ! ! Check error recovery; was crashing before. ! +implicit none real, pointer :: ptr nullify(ptr, mesh%coarser) ! { dg-error "Symbol 'mesh' at .1. has no IMPLICIT type" } end diff --git a/gcc/testsuite/gfortran.dg/pointer_init_6.f90 b/gcc/testsuite/gfortran.dg/pointer_init_6.f90 index 3abad4ae179..477626e66bb 100644 --- a/gcc/testsuite/gfortran.dg/pointer_init_6.f90 +++ b/gcc/testsuite/gfortran.dg/pointer_init_6.f90 @@ -21,7 +21,7 @@ end module m1 module m2 - + implicit none type :: t procedure(s), pointer, nopass :: ppc end type diff --git a/gcc/testsuite/gfortran.dg/pr107397.f90 b/gcc/testsuite/gfortran.dg/pr107397.f90 index fd59bf16007..f77b4b00d00 100644 --- a/gcc/testsuite/gfortran.dg/pr107397.f90 +++ b/gcc/testsuite/gfortran.dg/pr107397.f90 @@ -1,6 +1,7 @@ !{ dg-do compile } ! program p + implicit none type t real :: a = 1.0 end type diff --git a/gcc/testsuite/gfortran.dg/pr114739.f90 b/gcc/testsuite/gfortran.dg/pr114739.f90 new file mode 100644 index 00000000000..eb82cb3f65b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr114739.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! The fix here was triggered by an ICE prior to r14-9489-g3fd46d859cda10 +! Before that gfortran gave an incorrect "no implicit type" error for all +! three statements. +program main + implicit complex(z) + implicit character(c) + z2%re = 1. + z2%im = 2. + print *, z2, c%kind +end diff --git a/gcc/testsuite/gfortran.dg/pr88138.f90 b/gcc/testsuite/gfortran.dg/pr88138.f90 index c4019a6ca2e..f1130cf2bab 100644 --- a/gcc/testsuite/gfortran.dg/pr88138.f90 +++ b/gcc/testsuite/gfortran.dg/pr88138.f90 @@ -1,5 +1,6 @@ ! { dg-do compile } program p + implicit none type t character :: c = 'c' end type