[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-17 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #8 from anlauf at gcc dot gnu.org ---
Fixed.

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-17 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

--- Comment #7 from GCC Commits  ---
The master branch has been updated by Harald Anlauf :

https://gcc.gnu.org/g:76aac40f5ecbc9cfb3b8734d181599e1b5a24bdf

commit r14-9045-g76aac40f5ecbc9cfb3b8734d181599e1b5a24bdf
Author: Harald Anlauf 
Date:   Fri Feb 16 22:33:16 2024 +0100

Fortran: deferred length of character variables shall not get lost
[PR113911]

PR fortran/113911

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_trans_deferred_array): Do not clobber
deferred length for a character variable passed as dummy argument.

gcc/testsuite/ChangeLog:

* gfortran.dg/allocatable_length_2.f90: New test.
* gfortran.dg/bind_c_optional-2.f90: Enable deferred-length test.

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-16 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

   Last reconfirmed||2024-02-16
   Assignee|unassigned at gcc dot gnu.org  |anlauf at gcc dot 
gnu.org
 Ever confirmed|0   |1
 Status|UNCONFIRMED |ASSIGNED

--- Comment #6 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2024-February/060233.html

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-13 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

--- Comment #5 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #4)
> Running f951 on the testcase under valgrind shows (among others) a
> frontend memleak in gfc_resolve_substring_charlen, obviously fixed by

Slash that.  It produces many regressions in the testsuite...

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-13 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

--- Comment #4 from anlauf at gcc dot gnu.org ---
Running f951 on the testcase under valgrind shows (among others) a
frontend memleak in gfc_resolve_substring_charlen, obviously fixed by

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 44f89f6afb4..b1f36efb10b 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -5392,11 +5392,7 @@ gfc_resolve_substring_charlen (gfc_expr *e)
 end = NULL;

   if (!start || !end)
-{
-  gfc_free_expr (start);
-  gfc_free_expr (end);
-  return;
-}
+goto cleanup;

   /* Length = (end - start + 1).
  Check first whether it has a constant length.  */
@@ -5431,6 +5427,10 @@ gfc_resolve_substring_charlen (gfc_expr *e)
   /* Make sure that the length is simplified.  */
   gfc_simplify_expr (e->ts.u.cl->length, 1);
   gfc_resolve_expr (e->ts.u.cl->length);
+
+cleanup:
+  gfc_free_expr (start);
+  gfc_free_expr (end);
 }

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-13 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

--- Comment #3 from anlauf at gcc dot gnu.org ---
The following semi-obvious patch seems to fix it:

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 2181990aa04..7fc409140b0 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -11531,7 +11607,7 @@ gfc_trans_deferred_array (gfc_symbol * sym,
gfc_wrapped_block * block)
   if (sym->ts.type == BT_CHARACTER
   && !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
 {
-  if (sym->ts.deferred && !sym->ts.u.cl->length)
+  if (sym->ts.deferred && !sym->ts.u.cl->length && !sym->attr.dummy)
gfc_add_modify (&init, sym->ts.u.cl->backend_decl,
build_zero_cst (TREE_TYPE
(sym->ts.u.cl->backend_decl)));
   gfc_conv_string_length (sym->ts.u.cl, NULL, &init);

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-13 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

--- Comment #2 from anlauf at gcc dot gnu.org ---
Looking at the tree-dump before and after r14-8947, I see:

- a change in the main program that seems to be desirable:

   bitsizetype D.4340;
   sizetype D.4341;

+  *_c6 = 0;
   D.4339 = *_c6;
   D.4340 = (bitsizetype) (sizetype) NON_LVALUE_EXPR <*_c6> * 8;
   D.4341 = (sizetype) NON_LVALUE_EXPR <*_c6>;

- a change in the subroutine that kills the length:

  __attribute__((fn spec (". w w ")))
  void deferred (character(kind=1)[1:*_c5] * & restrict c5, struct
array01_character(kind=1) & restrict c6, integer(kind=8) * _c5, integer(kind=8)
* _c6)
  {
integer(kind=8) D.4339;
bitsizetype D.4340;
sizetype D.4341;

+   *_c6 = 0;
D.4339 = *_c6;
D.4340 = (bitsizetype) (sizetype) NON_LVALUE_EXPR <*_c6> * 8;
D.4341 = (sizetype) NON_LVALUE_EXPR <*_c6>;

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-13 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

--- Comment #1 from anlauf at gcc dot gnu.org ---
Created attachment 57418
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57418&action=edit
Testcase

Extended testcase that works with gcc-13.  The deferred-length dummy may
be optional or not; both fail the same way.

[Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine

2024-02-13 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P3  |P4
   Target Milestone|--- |14.0