tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
tmp = TYPE_SIZE_UNIT (tmp);
tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
+ gfc_add_block_to_block (&block, &se_sz.pre);
expr3_esize = fold_build2_loc (input_location, MULT_EXPR,
TREE_TYPE (se_sz.expr),
tmp, se_sz.expr);
+ expr3_esize = gfc_evaluate_now (expr3_esize, &block);
}
}
source= or mold= expression. */
gfc_init_se (&se_sz, NULL);
gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+ gfc_add_block_to_block (&block, &se_sz.pre);
gfc_add_modify (&block, al_len,
fold_convert (TREE_TYPE (al_len),
se_sz.expr));
specified by a type spec for deferred length character
arrays or unlimited polymorphic objects without a
source= or mold= expression. */
- gfc_init_se (&se_sz, NULL);
- gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
- gfc_add_modify (&block, al_len,
- fold_convert (TREE_TYPE (al_len),
- se_sz.expr));
+ if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1)
+ {
+ gfc_init_se (&se_sz, NULL);
+ gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+ gfc_add_block_to_block (&block, &se_sz.pre);
+ gfc_add_modify (&block, al_len,
+ fold_convert (TREE_TYPE (al_len),
+ se_sz.expr));
+ }
+ else
+ gfc_add_modify (&block, al_len,
+ fold_convert (TREE_TYPE (al_len),
+ expr3_esize));
}
else
/* No length information needed, because type to allocate
--- /dev/null
+!{ dg-do run }
+
+! Check fix for PR fortran/71623
+
+program allocatemvce
+ implicit none
+ character(len=:), allocatable :: string
+ integer, dimension(4), target :: array = [1,2,3,4]
+ integer, dimension(:), pointer :: array_ptr
+ array_ptr => array
+ ! The allocate used to segfault
+ allocate(character(len=size(array_ptr))::string)
+end program allocatemvce