Skip to content

Commit 2e5c1c5

Browse files
author
lkrupp
committed
2018-01-15 Louis Krupp <[email protected]>
PR fortran/82257 * interface.c (compare_rank): Don't try to retrieve CLASS_DATA from symbol marked unlimited polymorphic. * resolve.c (resolve_structure_cons): Likewise. * misc.c (gfc_typename): Don't dereference derived->components if it's NULL. 2018-01-15 Louis Krupp <[email protected]> PR fortran/82257 * gfortran.dg/unlimited_polymorphic_28.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256720 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent da13911 commit 2e5c1c5

File tree

6 files changed

+76
-4
lines changed

6 files changed

+76
-4
lines changed

gcc/fortran/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2018-01-15 Louis Krupp <[email protected]>
2+
3+
PR fortran/82257
4+
* interface.c (compare_rank): Don't try to retrieve CLASS_DATA
5+
from symbol marked unlimited polymorphic.
6+
* resolve.c (resolve_structure_cons): Likewise.
7+
* misc.c (gfc_typename): Don't dereference derived->components
8+
if it's NULL.
9+
110
2018-01-15 Thomas Koenig <[email protected]>
211

312
PR fortran/54613

gcc/fortran/interface.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,12 @@ compare_rank (gfc_symbol *s1, gfc_symbol *s2)
754754
if (s2->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK))
755755
return true;
756756

757-
as1 = (s1->ts.type == BT_CLASS) ? CLASS_DATA (s1)->as : s1->as;
758-
as2 = (s2->ts.type == BT_CLASS) ? CLASS_DATA (s2)->as : s2->as;
757+
as1 = (s1->ts.type == BT_CLASS
758+
&& !s1->ts.u.derived->attr.unlimited_polymorphic)
759+
? CLASS_DATA (s1)->as : s1->as;
760+
as2 = (s2->ts.type == BT_CLASS
761+
&& !s2->ts.u.derived->attr.unlimited_polymorphic)
762+
? CLASS_DATA (s2)->as : s2->as;
759763

760764
r1 = as1 ? as1->rank : 0;
761765
r2 = as2 ? as2->rank : 0;

gcc/fortran/misc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ gfc_typename (gfc_typespec *ts)
156156
sprintf (buffer, "TYPE(%s)", ts->u.derived->name);
157157
break;
158158
case BT_CLASS:
159-
ts = &ts->u.derived->components->ts;
159+
if (ts->u.derived->components)
160+
ts = &ts->u.derived->components->ts;
160161
if (ts->u.derived->attr.unlimited_polymorphic)
161162
sprintf (buffer, "CLASS(*)");
162163
else

gcc/fortran/resolve.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,9 @@ resolve_structure_cons (gfc_expr *expr, int init)
12891289
}
12901290

12911291
rank = comp->as ? comp->as->rank : 0;
1292-
if (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->as)
1292+
if (comp->ts.type == BT_CLASS
1293+
&& !comp->ts.u.derived->attr.unlimited_polymorphic
1294+
&& CLASS_DATA (comp)->as)
12931295
rank = CLASS_DATA (comp)->as->rank;
12941296

12951297
if (cons->expr->expr_type != EXPR_NULL && rank != cons->expr->rank

gcc/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-01-15 Louis Krupp <[email protected]>
2+
3+
PR fortran/82257
4+
* gfortran.dg/unlimited_polymorphic_28.f90: New test.
5+
16
2018-01-15 Martin Sebor <[email protected]>
27

38
PR testsuite/83869
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
! { dg-do compile }
2+
!
3+
! PR 82257: ICE in gfc_typename(), compare_rank(), resolve_structure_cons()
4+
5+
module m1
6+
7+
implicit none
8+
9+
type,abstract :: c_base
10+
contains
11+
procedure(i1),private,deferred :: f_base
12+
end type c_base
13+
14+
abstract interface
15+
function i1(this) result(res)
16+
import
17+
class(c_base),intent(IN) :: this
18+
class(c_base), pointer :: res
19+
end function i1
20+
end interface
21+
22+
type,abstract,extends(c_base) :: c_derived
23+
contains
24+
procedure :: f_base => f_derived ! { dg-error "Type mismatch in function result \\(CLASS\\(\\*\\)/CLASS\\(c_base\\)\\)" }
25+
end type c_derived
26+
27+
contains
28+
29+
function f_derived(this) result(res) ! { dg-error "must be dummy, allocatable or pointer" }
30+
class(c_derived), intent(IN) :: this
31+
class(*) :: res
32+
end function f_derived
33+
34+
end module m1
35+
36+
module m2
37+
38+
implicit none
39+
40+
type :: t
41+
contains
42+
procedure :: p
43+
end type t
44+
45+
contains
46+
47+
class(*) function p(this) ! { dg-error "must be dummy, allocatable or pointer" }
48+
class(t), intent(IN) :: this
49+
end function p
50+
51+
end module m2

0 commit comments

Comments
 (0)