]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix error recovery after missing END BLOCK [PR103508]
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 22 Sep 2025 06:33:07 +0000 (07:33 +0100)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 22 Sep 2025 06:33:07 +0000 (07:33 +0100)
2025-09-22  Steve Kargl  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/103508
* decl.cc (gfc_match_end): Remove only the current partial
rather than removing the entire sibling chain.

gcc/testsuite/
PR fortran/103508
* gfortran.dg/pr103508.f90: New test.

gcc/fortran/decl.cc
gcc/testsuite/gfortran.dg/pr103508.f90 [new file with mode: 0644]

index 99644939056371b1b3b73ebc31cbde4d88b21e7b..102c6a8e8df8dea18b497c74314d1125bb9afe5a 100644 (file)
@@ -8986,7 +8986,7 @@ cleanup:
   /* If we are missing an END BLOCK, we created a half-ready namespace.
      Remove it from the parent namespace's sibling list.  */
 
-  while (state == COMP_BLOCK && !got_matching_end)
+  if (state == COMP_BLOCK && !got_matching_end)
     {
       parent_ns = gfc_current_ns->parent;
 
diff --git a/gcc/testsuite/gfortran.dg/pr103508.f90 b/gcc/testsuite/gfortran.dg/pr103508.f90
new file mode 100644 (file)
index 0000000..541b9b2
--- /dev/null
@@ -0,0 +1,22 @@
+! { dg-do compile }
+!
+! Check the fix for PR103508. As noted in comment 6 of the PR, the bug
+! has nothing to do with PDTs. However, the contributor's test has been
+! retained.
+!
+! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
+!
+program p
+   type t
+      integer :: n = 1
+      character(3) :: c
+   end type
+   block
+      block
+         type(t) :: x
+         x%c = 'abc'
+         print *, len(x%c)
+      end ! { dg-error "END BLOCK statement expected" }
+   end    ! { dg-error "END BLOCK statement expected" }
+end
+! { dg-error "Unexpected end of file" "" { target "*-*-*" } 0 }