]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix ICE and clear incorrect error messages [PR114739]
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 6 May 2024 07:21:14 +0000 (08:21 +0100)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 6 May 2024 07:21:14 +0000 (08:21 +0100)
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

gcc/fortran/primary.cc
gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
gcc/testsuite/gfortran.dg/nullify_4.f90
gcc/testsuite/gfortran.dg/pointer_init_6.f90
gcc/testsuite/gfortran.dg/pr107397.f90
gcc/testsuite/gfortran.dg/pr114739.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr88138.f90

index edbd162ed13bb9346b7d2fd099f1a0328653e488..a1b6b74765aaae4847f52db52a7d00eb8e48b69d 100644 (file)
@@ -2199,6 +2199,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;
index 739f4adfb789dac2460fb9ba74b94ff0d287d7c3..22dfdc668a66af3bf9e2309c485e50fa216cec01 100644 (file)
@@ -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" }
index 0fd5056ee07e76ff0c66f143fba05fde11ece72d..240110fabf815827747f00ece58df01a5deddf53 100644 (file)
@@ -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
index 3abad4ae1795f5dc739651a8f83987cdd6622a74..477626e66bb3e5c614d9da4bcd379d3e5e7b977a 100644 (file)
@@ -21,7 +21,7 @@ end module m1
 
 
 module m2
-
+ implicit none
  type :: t
    procedure(s), pointer, nopass :: ppc
  end type
index fd59bf1600701edb2efaec4545fc63603f095403..f77b4b00d00ad042109b433a51bdb249ad34db6f 100644 (file)
@@ -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 (file)
index 0000000..eb82cb3
--- /dev/null
@@ -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
index c4019a6ca2e344b8f5c2d8ff8acb421954e41554..f1130cf2babef4fe784e0bb16095cceb3401405b 100644 (file)
@@ -1,5 +1,6 @@
 ! { dg-do compile }
 program p
+   implicit none
    type t
       character :: c = 'c'
    end type