+2016-12-21 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR fortran/78867
+ * trans-expr.c (gfc_conv_procedure_call): Emit DECL_EXPR also for
+ non-pointer character results.
+
2016-12-21 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
* iresolve.c (gfc_resolve_ftell): Call "ftell" instead of "ftell2".
type = gfc_get_character_type (ts.kind, ts.u.cl);
type = build_pointer_type (type);
+ /* Emit a DECL_EXPR for the VLA type. */
+ tmp = TREE_TYPE (type);
+ if (TYPE_SIZE (tmp)
+ && TREE_CODE (TYPE_SIZE (tmp)) != INTEGER_CST)
+ {
+ tmp = build_decl (input_location, TYPE_DECL, NULL_TREE, tmp);
+ DECL_ARTIFICIAL (tmp) = 1;
+ DECL_IGNORED_P (tmp) = 1;
+ tmp = fold_build1_loc (input_location, DECL_EXPR,
+ TREE_TYPE (tmp), tmp);
+ gfc_add_expr_to_block (&se->pre, tmp);
+ }
+
/* Return an address to a char[0:len-1]* temporary for
character pointers. */
if ((!comp && (sym->attr.pointer || sym->attr.allocatable))
{
var = gfc_create_var (type, "pstr");
- /* Emit a DECL_EXPR for the VLA type. */
- tmp = TREE_TYPE (type);
- if (TYPE_SIZE (tmp)
- && TREE_CODE (TYPE_SIZE (tmp)) != INTEGER_CST)
- {
- tmp = build_decl (input_location, TYPE_DECL, NULL_TREE, tmp);
- DECL_ARTIFICIAL (tmp) = 1;
- DECL_IGNORED_P (tmp) = 1;
- tmp = fold_build1_loc (input_location, DECL_EXPR,
- TREE_TYPE (tmp), tmp);
- gfc_add_expr_to_block (&se->pre, tmp);
- }
-
if ((!comp && sym->attr.allocatable)
|| (comp && comp->attr.allocatable))
{
--- /dev/null
+! { dg-do compile }
+! { dg-require-effective-target lto }
+! { dg-options "-flto" }
+! PR 78867, test case adapted from gfortran.dg/string_length_1.f90
+program pr78867
+ if (len(bar(2_8)) /= 2) call abort
+contains
+
+ function bar(i)
+ integer(8), intent(in) :: i
+ character(len=i) :: bar
+
+ bar = ""
+ end function bar
+
+end program pr78867