Re: [Patch, fortran] PR126909 - Lost statement label in a program with a CONTAINS section

Steve Kargl <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
On 8/22/26 07:41, Paul Richard Thomas wrote:
> Hi Steve,
> 
> Thanks for the review.
> 
> The attached is a very much cleaner resubmission, which handles
> statement labels at the end of subroutines and functions that have
> contained blocks. It regression tests cleanly.
> 
> OK for mainline?

Yes.  Thanks for the fix.  I suspect that this is just
a corner case in that programmers using internal subprograms
likely do not use statement labels or at least use them
sparingly.

> I am not sure that your second example is standard defying. Surely the
> normal rules of host association apply to labels in the same way as
> entities? FYI, ifx and flang do not catch it.

I have yet to determine if the below code is valid or not.
Yes, flang compiles it, but there may be a bit of ambiguity
with the language in the standard.  F2018, 6.2.5 has the
below statement.

>>      F2018, 6.2.5 Statement labels
>>      ...
>>      The same statement label shall not be given to more than
>>      one statement in its scope.
>>
>> subroutine lost()
>>      call sub()
>>      goto 10
>>      contains
>>         subroutine sub()
>>            goto 10
>> 10       return
>>         end subroutine sub
>> 10 end subroutine lost

But 'F2018, 11.2.1 Branch concepts' has the following statement:

    A branch causes a transfer of control from one statement to
    a labeled branch target statement in the same inclusive scope

Note, here it is much more restrictive in language by using
'same inclusive scope'.  An internal subprogram is in the
inclusive scope of its host scoping unit.  The definition of
'inclusive scope' in 3.87 (pg 12) is (to me) somewhat difficult
to parse.  It does, however, lead to the definition 'scoping unit'
3.123 (pg 17), which suggests that SUB()'s scoping unit can be
ignored when interpreting 'its scope' from 6.2.5.

-- 
steve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.