Skip to content

Commit 094f8a3

Browse files
author
Paul Thomas
committed
Fortran: Fix ICE and clear incorrect error messages [PR114739]
2024-05-06 Paul Thomas <pault@gcc.gnu.org> 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
1 parent 991f865 commit 094f8a3

File tree

7 files changed

+25
-1
lines changed

7 files changed

+25
-1
lines changed

gcc/fortran/primary.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
21992199
match mm;
22002200
old_loc = gfc_current_locus;
22012201
mm = gfc_match_name (name);
2202+
2203+
/* Check to see if this has a default type. */
2204+
if (sym->ts.type == BT_UNKNOWN && tgt_expr == NULL
2205+
&& gfc_get_default_type (sym->name, sym->ns)->type != BT_UNKNOWN)
2206+
{
2207+
gfc_set_default_type (sym, 0, sym->ns);
2208+
primary->ts = sym->ts;
2209+
}
2210+
22022211
if (mm == MATCH_YES && is_inquiry_ref (name, &tmp))
22032212
inquiry = true;
22042213
gfc_current_locus = old_loc;

gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
!
33
! PR fortran/52325
44
!
5+
implicit none
56
real :: f
67
cc%a = 5 ! { dg-error "Symbol 'cc' at .1. has no IMPLICIT type" }
78
f%a = 5 ! { dg-error "Unexpected '%' for nonderived-type variable 'f' at" }

gcc/testsuite/gfortran.dg/nullify_4.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
!
44
! Check error recovery; was crashing before.
55
!
6+
implicit none
67
real, pointer :: ptr
78
nullify(ptr, mesh%coarser) ! { dg-error "Symbol 'mesh' at .1. has no IMPLICIT type" }
89
end

gcc/testsuite/gfortran.dg/pointer_init_6.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end module m1
2121

2222

2323
module m2
24-
24+
implicit none
2525
type :: t
2626
procedure(s), pointer, nopass :: ppc
2727
end type

gcc/testsuite/gfortran.dg/pr107397.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
!{ dg-do compile }
22
!
33
program p
4+
implicit none
45
type t
56
real :: a = 1.0
67
end type
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! { dg-do compile }
2+
! The fix here was triggered by an ICE prior to r14-9489-g3fd46d859cda10
3+
! Before that gfortran gave an incorrect "no implicit type" error for all
4+
! three statements.
5+
program main
6+
implicit complex(z)
7+
implicit character(c)
8+
z2%re = 1.
9+
z2%im = 2.
10+
print *, z2, c%kind
11+
end

gcc/testsuite/gfortran.dg/pr88138.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
! { dg-do compile }
22
program p
3+
implicit none
34
type t
45
character :: c = 'c'
56
end type

0 commit comments

Comments
 (0)