From 8bed63c9312650b76db45329ee8b8e0c9c235bae Mon Sep 17 00:00:00 2001 From: pault Date: Sun, 13 May 2018 17:01:16 +0000 Subject: [PATCH] 2018-05-13 Paul Thomas PR fortran/85742 * trans-types.c (gfc_get_dtype_rank_type): Reorder evaluation of 'size'. If the element type is a pointer use the size of the TREE_TYPE of the type, unless it is VOID_TYPE. In this latter case, set the size to zero. 2018-05-13 Paul Thomas PR fortran/85742 * gfortran.dg/assumed_type_9.f90 : New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260211 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 10 +++++++- gcc/fortran/trans-types.c | 14 ++++++++---- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/assumed_type_9.f90 | 34 ++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/assumed_type_9.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 72bbda39640..a00e8617d56 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2018-05-13 Paul Thomas + + PR fortran/85742 + * trans-types.c (gfc_get_dtype_rank_type): Reorder evaluation + of 'size'. If the element type is a pointer use the size of the + TREE_TYPE of the type, unless it is VOID_TYPE. In this latter + case, set the size to zero. + 2018-05-13 Steven G. Kargl * gfortran.h: Remove prototype. @@ -7,7 +15,7 @@ PR fortran/85542 * expr.c (check_inquiry): Avoid NULL pointer dereference. - + 2018-05-10 Steven G. Kargl PR fortran/85687 diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 7ff27a3650c..f50eb0a9f01 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -1518,6 +1518,8 @@ gfc_get_dtype_rank_type (int rank, tree etype) tree field; vec *v = NULL; + size = TYPE_SIZE_UNIT (etype); + switch (TREE_CODE (etype)) { case INTEGER_TYPE: @@ -1546,22 +1548,24 @@ gfc_get_dtype_rank_type (int rank, tree etype) /* We will never have arrays of arrays. */ case ARRAY_TYPE: n = BT_CHARACTER; + if (size == NULL_TREE) + size = TYPE_SIZE_UNIT (TREE_TYPE (etype)); break; case POINTER_TYPE: n = BT_ASSUMED; + if (TREE_CODE (TREE_TYPE (etype)) != VOID_TYPE) + size = TYPE_SIZE_UNIT (TREE_TYPE (etype)); + else + size = build_int_cst (size_type_node, 0); break; default: /* TODO: Don't do dtype for temporary descriptorless arrays. */ - /* We can strange array types for temporary arrays. */ + /* We can encounter strange array types for temporary arrays. */ return gfc_index_zero_node; } - size = TYPE_SIZE_UNIT (etype); - if (n == BT_CHARACTER && size == NULL_TREE) - size = TYPE_SIZE_UNIT (TREE_TYPE (etype)); - tmp = get_dtype_type_node (); field = gfc_advance_chain (TYPE_FIELDS (tmp), GFC_DTYPE_ELEM_LEN); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ddcba1fd220..657390ce5d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-05-13 Paul Thomas + + PR fortran/85742 + * gfortran.dg/assumed_type_9.f90 : New test. + 2018-05-11 Steven G. Kargl PR fortran/85542 diff --git a/gcc/testsuite/gfortran.dg/assumed_type_9.f90 b/gcc/testsuite/gfortran.dg/assumed_type_9.f90 new file mode 100644 index 00000000000..c4a93fe7c65 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/assumed_type_9.f90 @@ -0,0 +1,34 @@ +! { dg-do run } +! +! Test the fix for PR85742 in which the descriptors, passed to alsize, +! for 'a' and 'b' had the wrong element length. +! +! Contributed by Cesar Philippidis +! +program main + implicit none + integer, allocatable :: a + real, pointer :: b + integer, allocatable :: am(:,:) + real, pointer :: bm(:,:) + + allocate (a) + allocate (b) + allocate (am(3,3)) + allocate (bm(4,4)) + + if (sizeof (a) /= alsize (a)) stop 1 + if (sizeof (b) /= alsize (b)) stop 2 + if (sizeof (am) /= alsize (am)) stop 3 + if (sizeof (bm) /= alsize (bm)) stop 4 + + deallocate (b) + deallocate (bm) +contains + function alsize (a) + integer alsize + type (*), dimension (..), contiguous :: a + alsize = sizeof(a) + end function +end program main + -- 2.11.4.GIT