8sa1-gcc/gcc/testsuite/substr_9.f90
Harald Anlauf bdd1b1f555 PR fortran/93340 - fix missed substring simplifications
Substrings were not reduced early enough for use in initializations,
such as DATA statements.  Add an early simplification for substrings
with constant starting and ending points.

gcc/fortran/ChangeLog:

	* gfortran.h (gfc_resolve_substring): Add prototype.
	* primary.c (match_string_constant): Simplify substrings with
	constant starting and ending points.
	* resolve.c: Rename resolve_substring to gfc_resolve_substring.
	(gfc_resolve_ref): Use renamed function gfc_resolve_substring.

gcc/testsuite/ChangeLog:

	* substr_10.f90: New test.
	* substr_9.f90: New test.
2021-01-14 20:25:33 +01:00

29 lines
766 B
Fortran

! { dg-do run }
! { dg-options "-std=gnu -fdump-tree-original" }
! PR93340 - issues with substrings in initializers
program p
implicit none
integer, parameter :: m = 1
character b(2) /'a', 'b' (1:1)/
character c(2) /'a', 'bc' (1:1)/
character d(2) /'a', 'bxyz'(m:m)/
character e(2)
character f(2)
data e /'a', 'bxyz'( :1)/
data f /'a', 'xyzb'(4:4)/
character :: g(2) = [ 'a', 'b' (1:1) ]
character :: h(2) = [ 'a', 'bc'(1:1) ]
character :: k(2) = [ 'a', 'bc'(m:1) ]
if (b(2) /= "b") stop 1
if (c(2) /= "b") stop 2
if (d(2) /= "b") stop 3
if (e(2) /= "b") stop 4
if (f(2) /= "b") stop 5
if (g(2) /= "b") stop 6
if (h(2) /= "b") stop 7
if (k(2) /= "b") stop 8
end
! { dg-final { scan-tree-dump-times "xyz" 0 "original" } }