public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine
@ 2024-02-13 18:28 anlauf at gcc dot gnu.org
2024-02-13 18:29 ` [Bug fortran/113911] " anlauf at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 18:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911
Bug ID: 113911
Summary: [14 Regression] Length is lost passing deferred-length
character to subroutine
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: anlauf at gcc dot gnu.org
Target Milestone: ---
As reported in
https://gcc.gnu.org/pipermail/fortran/2024-February/060224.html
the following testcase regressed after commit r14-8947:
program p
implicit none
integer, parameter :: n = 100, l = 10
character(l) :: a = 'a234567890', b(n) = 'bcdefghijk'
character(:), allocatable :: d, e(:)
allocate (d, source=a)
allocate (e, source=b)
print *, len (d), len (e), size (e)
call not_bindc_optional_deferred (d, e)
deallocate (d, e)
contains
subroutine not_bindc_optional_deferred (c5, c6)
character(:), allocatable, optional :: c5, c6(:)
if (.not. present (c5) .or. .not. present (c6)) stop 6
print *, len (c5), len (c6), size (c6)
if (len (c5) /= l .or. len (c6) /= l) stop 84
end
end
Expected:
10 10 100
10 10 100
After above commit:
10 10 100
10 0 100
STOP 84
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
@ 2024-02-13 18:29 ` anlauf at gcc dot gnu.org
2024-02-13 19:23 ` anlauf at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 18:29 UTC (permalink / raw)
To: 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
2024-02-13 18:29 ` [Bug fortran/113911] " anlauf at gcc dot gnu.org
@ 2024-02-13 19:23 ` anlauf at gcc dot gnu.org
2024-02-13 19:51 ` anlauf at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 19:23 UTC (permalink / raw)
To: 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
2024-02-13 18:29 ` [Bug fortran/113911] " anlauf at gcc dot gnu.org
2024-02-13 19:23 ` anlauf at gcc dot gnu.org
@ 2024-02-13 19:51 ` anlauf at gcc dot gnu.org
2024-02-13 20:02 ` anlauf at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 19:51 UTC (permalink / raw)
To: 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>;
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
` (2 preceding siblings ...)
2024-02-13 19:51 ` anlauf at gcc dot gnu.org
@ 2024-02-13 20:02 ` anlauf at gcc dot gnu.org
2024-02-13 20:33 ` anlauf at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 20:02 UTC (permalink / raw)
To: 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);
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
` (3 preceding siblings ...)
2024-02-13 20:02 ` anlauf at gcc dot gnu.org
@ 2024-02-13 20:33 ` anlauf at gcc dot gnu.org
2024-02-13 20:43 ` anlauf at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 20:33 UTC (permalink / raw)
To: 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);
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
` (4 preceding siblings ...)
2024-02-13 20:33 ` anlauf at gcc dot gnu.org
@ 2024-02-13 20:43 ` anlauf at gcc dot gnu.org
2024-02-16 21:44 ` anlauf at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-13 20:43 UTC (permalink / raw)
To: 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...
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
` (5 preceding siblings ...)
2024-02-13 20:43 ` anlauf at gcc dot gnu.org
@ 2024-02-16 21:44 ` anlauf at gcc dot gnu.org
2024-02-17 14:07 ` cvs-commit at gcc dot gnu.org
2024-02-17 20:19 ` anlauf at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-16 21:44 UTC (permalink / raw)
To: 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
` (6 preceding siblings ...)
2024-02-16 21:44 ` anlauf at gcc dot gnu.org
@ 2024-02-17 14:07 ` cvs-commit at gcc dot gnu.org
2024-02-17 20:19 ` anlauf at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-17 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113911
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:76aac40f5ecbc9cfb3b8734d181599e1b5a24bdf
commit r14-9045-g76aac40f5ecbc9cfb3b8734d181599e1b5a24bdf
Author: Harald Anlauf <anlauf@gmx.de>
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/113911] [14 Regression] Length is lost passing deferred-length character to subroutine
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
` (7 preceding siblings ...)
2024-02-17 14:07 ` cvs-commit at gcc dot gnu.org
@ 2024-02-17 20:19 ` anlauf at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-17 20:19 UTC (permalink / raw)
To: 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-02-17 20:19 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 18:28 [Bug fortran/113911] New: [14 Regression] Length is lost passing deferred-length character to subroutine anlauf at gcc dot gnu.org
2024-02-13 18:29 ` [Bug fortran/113911] " anlauf at gcc dot gnu.org
2024-02-13 19:23 ` anlauf at gcc dot gnu.org
2024-02-13 19:51 ` anlauf at gcc dot gnu.org
2024-02-13 20:02 ` anlauf at gcc dot gnu.org
2024-02-13 20:33 ` anlauf at gcc dot gnu.org
2024-02-13 20:43 ` anlauf at gcc dot gnu.org
2024-02-16 21:44 ` anlauf at gcc dot gnu.org
2024-02-17 14:07 ` cvs-commit at gcc dot gnu.org
2024-02-17 20:19 ` anlauf at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).