This patch properly sets the elem_len in gfc_array_init_size; it
probably could restricted to do so only for BT_CLASS and for
deferred-length BT_CHARACTER as otherwise the correct elem_len is set.
Additionally, the stride handling now uses elem_len to convert from/to
the stride multiplier instead of the declared TYPE_UNIT_SIZE. The latter
doesn't properly work for strings (at least not in all cases) and
(never) for polymorphic variables.
The code keeps using the declared size for nonstrings/record types. The
reason is that the declared size is a compile-time constant. Using
elem_len would otherwise cause problems, e.g., with vectorization as the
vectorizer cannot see that the memory access is contiguous.
(The other patch removes some code which used to be: new_ubound =
old_ubound + (old_lbound-new_lbound); with the change of the array
descriptor to extents, the code was now effectively "new_extent =
old_extent", which is pointless.)
This patch brings down the regression-test failures from 15 to 6. Still
failing are:
gfortran.dg/auto_char_len_3.f90
gfortran.dg/mvbits_7.f90
gfortran.dg/mvbits_8.f90
gfortran.dg/proc_decl_23.f90
gfortran.dg/subref_array_pointer_2.f90
gfortran.dg/transfer_intrinsic_3.f90
gfortran.dg/unlimited_polymorphic_1.f03
Besides solving those regressions, the main task is still outstanding:
Removal of "offset". Additional tasks are lower_bound == 0 for actuals
to nonpointer/nonallocatables dummies and the proper handling of
subpointers (i.e. sm != n*elem_len).
Committed as Rev. 198669 after building and regtesting on
x86-64-gnu-linux. Additionally, I have updated the branch to the trunk,
Rev. 198670.
Tobias
2013-05-07 Tobias Burnus <bur...@net-b.de>
* trans-array.c (gfc_conv_descriptor_stride_get,
gfc_conv_descriptor_stride_set): Use elem_len, unless it is
a nonstring intrinsic type for which size_in_bytes is used.
(gfc_array_init_size): Set elem_len before handling the
strides.
* trans-expr.c (gfc_conv_subref_array_arg): Remove no-op
extent shifting code.
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 08f12aa..db8de69 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -422,7 +422,11 @@ gfc_conv_descriptor_stride_get (tree desc, tree dim)
return gfc_index_one_node;
tmp = gfc_get_element_type (type);
- size = size_in_bytes (tmp);
+ if (TREE_CODE (tmp) != RECORD_TYPE && !TYPE_STRING_FLAG (tmp))
+ size = size_in_bytes (tmp);
+ else
+ size = gfc_conv_descriptor_elem_len_get (desc);
+
size = fold_convert (gfc_array_index_type, size);
tmp = fold_build2_loc (input_location, FLOOR_DIV_EXPR, gfc_array_index_type,
gfc_conv_descriptor_sm_get (desc, dim), size);
@@ -440,7 +444,11 @@ gfc_conv_descriptor_stride_set (stmtblock_t *block, tree desc,
{
tree tmp;
tmp = gfc_get_element_type (TREE_TYPE (desc));
- tmp = size_in_bytes (tmp);
+ if (TREE_CODE (tmp) != RECORD_TYPE && !TYPE_STRING_FLAG (tmp))
+ tmp = size_in_bytes (tmp);
+ else
+ tmp = gfc_conv_descriptor_elem_len_get (desc);
+
tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
fold_convert (gfc_array_index_type, value),
fold_convert (gfc_array_index_type, tmp));
@@ -5117,6 +5125,34 @@ gfc_array_init_size (tree descriptor, gfc_typespec *ts,
tmp = gfc_conv_descriptor_dtype (descriptor);
gfc_add_modify (descriptor_block, tmp, gfc_get_dtype (ts));
+ if (expr3_elem_size != NULL_TREE)
+ tmp = expr3_elem_size;
+ else if (expr3 != NULL)
+ {
+ if (expr3->ts.type == BT_CLASS)
+ {
+ gfc_se se_sz;
+ gfc_expr *sz = gfc_copy_expr (expr3);
+ gfc_add_vptr_component (sz);
+ gfc_add_size_component (sz);
+ gfc_init_se (&se_sz, NULL);
+ gfc_conv_expr (&se_sz, sz);
+ gfc_free_expr (sz);
+ tmp = se_sz.expr;
+ }
+ else
+ {
+ tmp = gfc_typenode_for_spec (&expr3->ts);
+ tmp = TYPE_SIZE_UNIT (tmp);
+ }
+ }
+ else
+ tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
+
+ /* Convert to size_t. */
+ element_size = fold_convert (size_type_node, tmp);
+ gfc_conv_descriptor_elem_len_set (descriptor_block, descriptor, element_size);
+
or_expr = boolean_false_node;
for (n = 0; n < rank; n++)
@@ -5249,36 +5285,6 @@ gfc_array_init_size (tree descriptor, gfc_typespec *ts,
}
}
- /* The stride is the number of elements in the array, so multiply by the
- size of an element to get the total size. Obviously, if there is a
- SOURCE expression (expr3) we must use its element size. */
- if (expr3_elem_size != NULL_TREE)
- tmp = expr3_elem_size;
- else if (expr3 != NULL)
- {
- if (expr3->ts.type == BT_CLASS)
- {
- gfc_se se_sz;
- gfc_expr *sz = gfc_copy_expr (expr3);
- gfc_add_vptr_component (sz);
- gfc_add_size_component (sz);
- gfc_init_se (&se_sz, NULL);
- gfc_conv_expr (&se_sz, sz);
- gfc_free_expr (sz);
- tmp = se_sz.expr;
- }
- else
- {
- tmp = gfc_typenode_for_spec (&expr3->ts);
- tmp = TYPE_SIZE_UNIT (tmp);
- }
- }
- else
- tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
-
- /* Convert to size_t. */
- element_size = fold_convert (size_type_node, tmp);
-
if (rank == 0)
return element_size;
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 2370f44..07f3ead 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -3772,12 +3772,6 @@ gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr, int g77,
offset = gfc_index_zero_node;
for (n = 0; n < dimen; n++)
{
- tmp = gfc_conv_descriptor_extent_get (parmse->expr,
- gfc_rank_cst[n]);
- gfc_conv_descriptor_ubound_set (&parmse->pre,
- parmse->expr,
- gfc_rank_cst[n],
- tmp);
gfc_conv_descriptor_lbound_set (&parmse->pre,
parmse->expr,
gfc_rank_cst[n],