Skip to content

Commit d5ba011

Browse files
author
pault
committed
2017-09-21 Paul Thomas <[email protected]>
PR fortran/52832 * match.c (gfc_match_associate): Before failing the association try again, allowing a proc pointer selector. PR fortran/80120 PR fortran/81903 PR fortran/82121 * primary.c (gfc_match_varspec): Introduce 'tgt_expr', which points to the associate selector, if any. Go through selector references, after resolution for variables, to catch any full or section array references. If a class associate name does not have the same declared type as the selector, resolve the selector and copy the declared type to the associate name. Before throwing a no implicit type error, resolve all allowed selector expressions, and copy the resulting typespec. PR fortran/67543 * resolve.c (resolve_assoc_var): Selector must cannot be the NULL expression and it must have a type. PR fortran/78152 * resolve.c (resolve_symbol): Allow associate names to be coarrays. 2017-09-21 Paul Thomas <[email protected]> PR fortran/78512 * gfortran.dg/associate_26.f90 : New test. PR fortran/80120 * gfortran.dg/associate_27.f90 : New test. PR fortran/81903 * gfortran.dg/associate_28.f90 : New test. PR fortran/82121 * gfortran.dg/associate_29.f90 : New test. PR fortran/67543 * gfortran.dg/associate_30.f90 : New test. PR fortran/52832 * gfortran.dg/associate_31.f90 : New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253077 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent f2740d9 commit d5ba011

File tree

11 files changed

+306
-22
lines changed

11 files changed

+306
-22
lines changed

gcc/fortran/ChangeLog

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
2017-09-21 Paul Thomas <[email protected]>
2+
3+
PR fortran/52832
4+
* match.c (gfc_match_associate): Before failing the association
5+
try again, allowing a proc pointer selector.
6+
7+
PR fortran/80120
8+
PR fortran/81903
9+
PR fortran/82121
10+
* primary.c (gfc_match_varspec): Introduce 'tgt_expr', which
11+
points to the associate selector, if any. Go through selector
12+
references, after resolution for variables, to catch any full
13+
or section array references. If a class associate name does
14+
not have the same declared type as the selector, resolve the
15+
selector and copy the declared type to the associate name.
16+
Before throwing a no implicit type error, resolve all allowed
17+
selector expressions, and copy the resulting typespec.
18+
19+
PR fortran/67543
20+
* resolve.c (resolve_assoc_var): Selector must cannot be the
21+
NULL expression and it must have a type.
22+
23+
PR fortran/78152
24+
* resolve.c (resolve_symbol): Allow associate names to be
25+
coarrays.
26+
127
2017-09-21 Cesar Philippidis <[email protected]>
228

329
* openmp.c (gfc_match_oacc_wait): Don't restrict wait directive

gcc/fortran/match.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,8 +1885,15 @@ gfc_match_associate (void)
18851885
if (gfc_match (" %n => %e", newAssoc->name, &newAssoc->target)
18861886
!= MATCH_YES)
18871887
{
1888-
gfc_error ("Expected association at %C");
1889-
goto assocListError;
1888+
/* Have another go, allowing for procedure pointer selectors. */
1889+
gfc_matching_procptr_assignment = 1;
1890+
if (gfc_match (" %n => %e", newAssoc->name, &newAssoc->target)
1891+
!= MATCH_YES)
1892+
{
1893+
gfc_error ("Expected association at %C");
1894+
goto assocListError;
1895+
}
1896+
gfc_matching_procptr_assignment = 0;
18901897
}
18911898
newAssoc->where = gfc_current_locus;
18921899

gcc/fortran/primary.c

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
19371937
gfc_ref *substring, *tail, *tmp;
19381938
gfc_component *component;
19391939
gfc_symbol *sym = primary->symtree->n.sym;
1940+
gfc_expr *tgt_expr = NULL;
19401941
match m;
19411942
bool unknown;
19421943
char sep;
@@ -1965,6 +1966,9 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
19651966
}
19661967
}
19671968

1969+
if (sym->assoc && sym->assoc->target)
1970+
tgt_expr = sym->assoc->target;
1971+
19681972
/* For associate names, we may not yet know whether they are arrays or not.
19691973
If the selector expression is unambiguously an array; eg. a full array
19701974
or an array section, then the associate name must be an array and we can
@@ -1976,26 +1980,43 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
19761980
&& sym->ts.type != BT_CLASS
19771981
&& !sym->attr.dimension)
19781982
{
1979-
if ((!sym->assoc->dangling
1980-
&& sym->assoc->target
1981-
&& sym->assoc->target->ref
1982-
&& sym->assoc->target->ref->type == REF_ARRAY
1983-
&& (sym->assoc->target->ref->u.ar.type == AR_FULL
1984-
|| sym->assoc->target->ref->u.ar.type == AR_SECTION))
1985-
||
1986-
(!(sym->assoc->dangling || sym->ts.type == BT_CHARACTER)
1987-
&& sym->assoc->st
1988-
&& sym->assoc->st->n.sym
1989-
&& sym->assoc->st->n.sym->attr.dimension == 0))
1990-
{
1991-
sym->attr.dimension = 1;
1992-
if (sym->as == NULL && sym->assoc
1983+
gfc_ref *ref = NULL;
1984+
1985+
if (!sym->assoc->dangling && tgt_expr)
1986+
{
1987+
if (tgt_expr->expr_type == EXPR_VARIABLE)
1988+
gfc_resolve_expr (tgt_expr);
1989+
1990+
ref = tgt_expr->ref;
1991+
for (; ref; ref = ref->next)
1992+
if (ref->type == REF_ARRAY
1993+
&& (ref->u.ar.type == AR_FULL
1994+
|| ref->u.ar.type == AR_SECTION))
1995+
break;
1996+
}
1997+
1998+
if (ref || (!(sym->assoc->dangling || sym->ts.type == BT_CHARACTER)
1999+
&& sym->assoc->st
2000+
&& sym->assoc->st->n.sym
2001+
&& sym->assoc->st->n.sym->attr.dimension == 0))
2002+
{
2003+
sym->attr.dimension = 1;
2004+
if (sym->as == NULL
19932005
&& sym->assoc->st
19942006
&& sym->assoc->st->n.sym
19952007
&& sym->assoc->st->n.sym->as)
19962008
sym->as = gfc_copy_array_spec (sym->assoc->st->n.sym->as);
19972009
}
19982010
}
2011+
else if (sym->ts.type == BT_CLASS
2012+
&& tgt_expr
2013+
&& tgt_expr->expr_type == EXPR_VARIABLE
2014+
&& sym->ts.u.derived != tgt_expr->ts.u.derived)
2015+
{
2016+
gfc_resolve_expr (tgt_expr);
2017+
if (tgt_expr->rank)
2018+
sym->ts.u.derived = tgt_expr->ts.u.derived;
2019+
}
19992020

20002021
if ((equiv_flag && gfc_peek_ascii_char () == '(')
20012022
|| gfc_peek_ascii_char () == '[' || sym->attr.codimension
@@ -2055,14 +2076,24 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
20552076
&& gfc_get_default_type (sym->name, sym->ns)->type == BT_DERIVED)
20562077
gfc_set_default_type (sym, 0, sym->ns);
20572078

2058-
/* Before throwing an error try resolving the target expression of
2059-
associate names. This should resolve function calls, for example. */
2079+
/* See if there is a usable typespec in the "no IMPLICIT type" error. */
20602080
if (sym->ts.type == BT_UNKNOWN && m == MATCH_YES)
20612081
{
2062-
if (sym->assoc && sym->assoc->target)
2082+
bool permissible;
2083+
2084+
/* These target expressions can ge resolved at any time. */
2085+
permissible = tgt_expr && tgt_expr->symtree && tgt_expr->symtree->n.sym
2086+
&& (tgt_expr->symtree->n.sym->attr.use_assoc
2087+
|| tgt_expr->symtree->n.sym->attr.host_assoc
2088+
|| tgt_expr->symtree->n.sym->attr.if_source
2089+
== IFSRC_DECL);
2090+
permissible = permissible
2091+
|| (tgt_expr && tgt_expr->expr_type == EXPR_OP);
2092+
2093+
if (permissible)
20632094
{
2064-
gfc_resolve_expr (sym->assoc->target);
2065-
sym->ts = sym->assoc->target->ts;
2095+
gfc_resolve_expr (tgt_expr);
2096+
sym->ts = tgt_expr->ts;
20662097
}
20672098

20682099
if (sym->ts.type == BT_UNKNOWN)

gcc/fortran/resolve.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8396,11 +8396,23 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
83968396
sym->attr.subref_array_pointer = 1;
83978397
}
83988398

8399+
if (target->expr_type == EXPR_NULL)
8400+
{
8401+
gfc_error ("Selector at %L cannot be NULL()", &target->where);
8402+
return;
8403+
}
8404+
else if (target->ts.type == BT_UNKNOWN)
8405+
{
8406+
gfc_error ("Selector at %L has no type", &target->where);
8407+
return;
8408+
}
8409+
83998410
/* Get type if this was not already set. Note that it can be
84008411
some other type than the target in case this is a SELECT TYPE
84018412
selector! So we must not update when the type is already there. */
84028413
if (sym->ts.type == BT_UNKNOWN)
84038414
sym->ts = target->ts;
8415+
84048416
gcc_assert (sym->ts.type != BT_UNKNOWN);
84058417

84068418
/* See if this is a valid association-to-variable. */
@@ -11926,6 +11938,7 @@ deferred_requirements (gfc_symbol *sym)
1192611938
if (sym->ts.deferred
1192711939
&& !(sym->attr.pointer
1192811940
|| sym->attr.allocatable
11941+
|| sym->attr.associate_var
1192911942
|| sym->attr.omp_udr_artificial_var))
1193011943
{
1193111944
gfc_error ("Entity %qs at %L has a deferred type parameter and "
@@ -14763,6 +14776,7 @@ resolve_symbol (gfc_symbol *sym)
1476314776
if (class_attr.codimension
1476414777
&& !(class_attr.allocatable || sym->attr.dummy || sym->attr.save
1476514778
|| sym->attr.select_type_temporary
14779+
|| sym->attr.associate_var
1476614780
|| (sym->ns->save_all && !sym->attr.automatic)
1476714781
|| sym->ns->proc_name->attr.flavor == FL_MODULE
1476814782
|| sym->ns->proc_name->attr.is_main_program

gcc/testsuite/ChangeLog

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2017-09-21 Paul Thomas <[email protected]>
2+
3+
PR fortran/78512
4+
* gfortran.dg/associate_26.f90 : New test.
5+
6+
PR fortran/80120
7+
* gfortran.dg/associate_27.f90 : New test.
8+
9+
PR fortran/81903
10+
* gfortran.dg/associate_28.f90 : New test.
11+
12+
PR fortran/82121
13+
* gfortran.dg/associate_29.f90 : New test.
14+
15+
PR fortran/67543
16+
* gfortran.dg/associate_30.f90 : New test.
17+
18+
PR fortran/52832
19+
* gfortran.dg/associate_31.f90 : New test.
20+
121
2017-09-21 Eric Botcazou <[email protected]>
222

323
* gnat.dg/discr48.adb: New test.
@@ -42,7 +62,7 @@
4262
Jeff Law <[email protected]>
4363

4464
* gcc.dg/stack-check-5.c: Add argument for s390.
45-
* lib/target-supports.exp:
65+
* lib/target-supports.exp:
4666
(check_effective_target_supports_stack_clash_protection): Enable for
4767
s390/s390x targets.
4868

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! { dg-do compile }
2+
! { dg-options "-fcoarray=single" }
3+
!
4+
! Test the fix for PR78152
5+
!
6+
! Contributed by <[email protected]>
7+
!
8+
program co_assoc
9+
implicit none
10+
integer, parameter :: p = 5
11+
real, allocatable :: a(:,:)[:,:]
12+
allocate (a(p,p)[2,*])
13+
associate (i => a(1:p, 1:p))
14+
end associate
15+
end program co_assoc
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
! { dg-do run }
2+
!
3+
! Test the fix for PR80120
4+
!
5+
! Contributed by Marco Restelli <[email protected]>
6+
!
7+
program p
8+
implicit none
9+
10+
type :: t
11+
character(len=25) :: text(2)
12+
end type t
13+
type(t) :: x
14+
15+
x%text(1) = "ABC"
16+
x%text(2) = "defgh"
17+
18+
associate( c => x%text )
19+
if (c(1)(:maxval(len_trim(c))) .ne. trim (x%text(1))) call abort
20+
if (c(2)(:maxval(len_trim(c))) .ne. trim (x%text(2))) call abort
21+
end associate
22+
23+
end program p
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
! { dg-do run }
2+
!
3+
! Test the fix for PR81903
4+
!
5+
! Contributed by Karl May <[email protected]>
6+
!
7+
Module TestMod_A
8+
Type :: TestType_A
9+
Real, Allocatable :: a(:,:)
10+
End type TestType_A
11+
End Module TestMod_A
12+
Module TestMod_B
13+
Type :: TestType_B
14+
Real, Pointer, contiguous :: a(:,:)
15+
End type TestType_B
16+
End Module TestMod_B
17+
Module TestMod_C
18+
use TestMod_A
19+
use TestMod_B
20+
Implicit None
21+
Type :: TestType_C
22+
Class(TestType_A), Pointer :: TT_A(:)
23+
Type(TestType_B), Allocatable :: TT_B(:)
24+
contains
25+
Procedure, Pass :: SetPt => SubSetPt
26+
End type TestType_C
27+
Interface
28+
Module Subroutine SubSetPt(this)
29+
class(TestType_C), Intent(InOut), Target :: this
30+
End Subroutine
31+
End Interface
32+
End Module TestMod_C
33+
Submodule(TestMod_C) SetPt
34+
contains
35+
Module Procedure SubSetPt
36+
Implicit None
37+
integer :: i
38+
integer :: sum_a = 0
39+
outer:block
40+
associate(x=>this%TT_B,y=>this%TT_A)
41+
Do i=1,size(x)
42+
x(i)%a=>y(i)%a
43+
sum_a = sum_a + sum (int (x(i)%a))
44+
End Do
45+
end associate
46+
End block outer
47+
if (sum_a .ne. 30) call abort
48+
End Procedure
49+
End Submodule SetPt
50+
Program Test
51+
use TestMod_C
52+
use TestMod_A
53+
Implicit None
54+
Type(TestType_C) :: tb
55+
Type(TestType_A), allocatable, Target :: ta(:)
56+
integer :: i
57+
real :: src(2,2) = reshape ([(real(i), i = 1,4)],[2,2])
58+
allocate(ta(2),tb%tt_b(2))
59+
do i=1,size(ta)
60+
allocate(ta(i)%a(2,2), source = src*real(i))
61+
End do
62+
tb%TT_A=>ta
63+
call tb%setpt()
64+
End Program Test
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
! { dg-do compile }
2+
!
3+
! Test the fix for PR82121
4+
!
5+
! Contributed by Iain Miller <[email protected]>
6+
!
7+
MODULE YOMCDDH
8+
IMPLICIT NONE
9+
SAVE
10+
TYPE :: TCDDH
11+
CHARACTER(len=12),ALLOCATABLE :: CADHTLS(:)
12+
END TYPE TCDDH
13+
CHARACTER(len=12),ALLOCATABLE :: CADHTTS(:)
14+
TYPE(TCDDH), POINTER :: YRCDDH => NULL()
15+
END MODULE YOMCDDH
16+
17+
18+
SUBROUTINE SUCDDH()
19+
USE YOMCDDH , ONLY : YRCDDH,CADHTTS
20+
IMPLICIT NONE
21+
ALLOCATE (YRCDDH%CADHTLS(20))
22+
ALLOCATE (CADHTTS(20))
23+
ASSOCIATE(CADHTLS=>YRCDDH%CADHTLS, NORMCHAR=>CADHTTS)
24+
! Direct reference to character array compiled correctly
25+
! YRCDDH%CADHTLS(1)='SVGTLF'
26+
! Reference to associated variable name failed to compile
27+
CADHTLS(2)='SVGTLT'
28+
NORMCHAR(1)='SVLTTC'
29+
END ASSOCIATE
30+
END SUBROUTINE SUCDDH
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! { dg-do compile }
2+
!
3+
! Test the fix for PR67543
4+
!
5+
! Contributed by Gerhard Steinmetz <[email protected]>
6+
!
7+
subroutine s1
8+
associate (x => null()) ! { dg-error "cannot be NULL()" }
9+
end associate
10+
end subroutine
11+
12+
subroutine s2
13+
associate (x => [null()]) ! { dg-error "has no type" }
14+
end associate
15+
end subroutine

0 commit comments

Comments
 (0)