From: Paul Thomas Date: Mon, 22 Sep 2025 06:33:07 +0000 (+0100) Subject: Fortran: Fix error recovery after missing END BLOCK [PR103508] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e6937b9ab4f752c22b4e2fd0e01836a0df24653;p=thirdparty%2Fgcc.git Fortran: Fix error recovery after missing END BLOCK [PR103508] 2025-09-22 Steve Kargl 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. --- diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 99644939056..102c6a8e8df 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -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 index 00000000000..541b9b2d1f0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103508.f90 @@ -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 +! +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 }