[Patch, fortran] PR fortran/50071 Duplicate statement labels from different scoping units rejected.

Mikael Morin mikael.morin@sfr.fr
Tue Aug 16 14:50:00 GMT 2011


On Sunday 14 August 2011 09:35:56 Tobias Burnus wrote:
> I think the following is valid and it is still rejected (it is accepted
> by NAG 5.1 and ifort):
> 
> 1 type t
>      integer :: i
>    end type t
> 
>    goto 1
> 1 print *, 'Hello'
> end
> 
> Related but separate issue: BLOCK also starts a new scoping unit, but
> the following is rejected:
> 
>     block
>       goto 1
>       print *, 'Hello'
> 1    continue
>     end block
> 1  continue
> end
> 
> 
> Also the following is rejected:
> 
>     block
>       goto 1
>       print *, 'Hello'
> 1  end block
> end
> 
> variant, which is rejected (note: Associate does not start a new scoping
> unit, just a new block):
> 
>    integer :: i
>    associate (j => i)
>      goto 1
>      print *, 'Hello'
> 1  end associate
> end
> 
Hem, OK; it is a can of Pandora.

I can propose the following ad-hoc fix for the two latter cases.

It uses the same hack as is used for IF, SELECT, and possibly others:
make a dummy code that will get the label.
The difference is that here, the dummy code is inserted in the nested scope 
(i.e. in the BLOCK or ASSOCIATE scope) instead of the parent one.

For consistency, I renamed EXEC_END_BLOCK to EXEC_END_NESTED_BLOCK, and reused 
EXEC_END_BLOCK for the new code.


The patch passes gfortran.dg/*goto* and gfortran.dg/*label*, and I'm doing a 
full regression test. Is that OK?



About your two former cases, the first one looks especially tricky. For the 
second one, it may be valid, but a warning would be nice IMO as one of the 
labels is masked by the other. Both cases need more investigation anyway.

Mikael.
-------------- next part --------------
2011-08-16  Mikael Morin  <mikael.morin@sfr.fr>

	PR fortran/50071
	* gfortran.h (gfc_exec_op): New constant EXEC_END_NESTED_BLOCK.
	* parse.c (check_statement_label): Accept ST_END_BLOCK and
	ST_END_ASSOCIATE as valid branch target.
	(accept_statement): Change EXEC_END_BLOCK to EXEC_END_NESTED_BLOCK.
	Add EXEC_END_BLOCK code in the ST_END_BLOCK and ST_END_ASSOCIATE cases.
	* resolve.c (find_reachable_labels): Change EXEC_END_BLOCK to
	EXEC_END_NESTED_BLOCK.
	(resolve_branch): Ditto.
	(resolve_code): Add EXEC_END_NESTED_BLOCK case.
	* st.c (gfc_free_statement): Ditto.
	* trans.c (trans_code): Ditto.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr50071_3.diff
Type: text/x-patch
Size: 3069 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20110816/ec59998c/attachment.bin>


More information about the Fortran mailing list