https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91941

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The crash is due to  expr->ts.u.cl->length == NULL for 'adjustl(x)' – which
fails in gfc_conv_expr_descriptor (see backtrace). Changing the condition to
call get_array_charlen() instead of dereferrencing expr->ts.u.cl->length, it
just moves the segfault to that function.

If gfc_conv_intrinsic_adjust is directly called (w/o the 'associate' block), it
takes care of obtaining the string length.
With the associate block, it calls trans_associate_var and never reaches the
point of calling gfc_conv_intrinsic_adjust.

NOTE: Running the program with GCC 7, it shows "abc" - then nothing for two
seconds - and only then "xyz". What is the program doing during those two
seconds?

I think the following patch is sensible – but as string->ts.u.cl->length ==
NULL,
it doesn't change anything regarding this PR.

diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c
index 53338dda0a7..e0028c30c86 100644
--- a/gcc/fortran/iresolve.c
+++ b/gcc/fortran/iresolve.c
@@ -224,3 +224,10 @@ gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
   if (string->ts.u.cl)
-    f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl);
+    {
+      f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl);
+      if (string->expr_type == EXPR_CONSTANT)
+       f->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+                                              string->value.character.length);
+      else if (string->ts.u.cl && string->ts.u.cl->length)
+       f->ts.u.cl->length = gfc_copy_expr (string->ts.u.cl->length);
+    }

@@ -236,3 +243,10 @@ gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
   if (string->ts.u.cl)
-    f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl);
+    {
+      f->ts.u.cl = gfc_new_charlen (gfc_current_ns, string->ts.u.cl);
+      if (string->expr_type == EXPR_CONSTANT)
+       f->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+                                              string->value.character.length);
+      else if (string->ts.u.cl && string->ts.u.cl->length)
+       f->ts.u.cl->length = gfc_copy_expr (string->ts.u.cl->length);
+    }

Reply via email to