* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
@ 2022-10-27 18:41 ` anlauf at gcc dot gnu.org
2022-10-27 18:52 ` kargl at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 18:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |anlauf at gcc dot gnu.org
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-10-27
--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.
There is an inconsistency either in the generated code for the caller or
the callee:
integer(kind=4) testoptional (character(kind=1)[1:1] & restrict w,
integer(kind=4) x, integer(kind=8) _w, logical(kind=1) _x)
vs.
t = testoptional (&s, 0, 0, 1);
How does the ABI define the ordering of character length and presence flag?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
2022-10-27 18:41 ` [Bug fortran/107441] " anlauf at gcc dot gnu.org
@ 2022-10-27 18:52 ` kargl at gcc dot gnu.org
2022-10-27 19:20 ` anlauf at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-10-27 18:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #2 from kargl at gcc dot gnu.org ---
(In reply to anlauf from comment #1)
> Confirmed.
>
> There is an inconsistency either in the generated code for the caller or
> the callee:
>
> integer(kind=4) testoptional (character(kind=1)[1:1] & restrict w,
> integer(kind=4) x, integer(kind=8) _w, logical(kind=1) _x)
>
> vs.
>
> t = testoptional (&s, 0, 0, 1);
>
> How does the ABI define the ordering of character length and presence flag?
Yep, there's an API issue. If you use
character(len=13) :: s
the produced code is
t = testoptional (&s, 0, 0, 13);
so the hidden charlen is tacked on last whereas I think the hidden presence
argument is also expected to be last. Likely a counting error in generating
the interface.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
2022-10-27 18:41 ` [Bug fortran/107441] " anlauf at gcc dot gnu.org
2022-10-27 18:52 ` kargl at gcc dot gnu.org
@ 2022-10-27 19:20 ` anlauf at gcc dot gnu.org
2022-10-27 19:42 ` anlauf at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 19:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #3 from anlauf at gcc dot gnu.org ---
(In reply to kargl from comment #2)
> so the hidden charlen is tacked on last whereas I think the hidden presence
> argument is also expected to be last. Likely a counting error in generating
> the interface.
I've found the code generating the function call in gfc_conv_procedure_call
(trans-expr.cc:7680)
/* Add the return arguments. */
vec_safe_splice (retargs, arglist);
/* Add the hidden present status for optional+value to the arguments. */
vec_safe_splice (retargs, optionalargs);
/* Add the hidden string length parameters to the arguments. */
vec_safe_splice (retargs, stringargs);
/* We may want to append extra arguments here. This is used e.g. for
calls to libgfortran_matmul_??, which need extra information. */
vec_safe_splice (retargs, append_args);
We now need the corresponding part on the procedure side.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (2 preceding siblings ...)
2022-10-27 19:20 ` anlauf at gcc dot gnu.org
@ 2022-10-27 19:42 ` anlauf at gcc dot gnu.org
2022-10-27 19:49 ` anlauf at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #3)
> We now need the corresponding part on the procedure side.
That might be create_function_arglist (trans-decl.cc).
There's currently a single hidden_arglist, which needs
to be aligned to the caller's side.
Is there a public documentation what the ordering should be?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (3 preceding siblings ...)
2022-10-27 19:42 ` anlauf at gcc dot gnu.org
@ 2022-10-27 19:49 ` anlauf at gcc dot gnu.org
2022-10-27 20:07 ` anlauf at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 19:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #5 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #4)
> Is there a public documentation what the ordering should be?
It is actually documented for gfortran:
https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
The arguments are passed in the following order
* Result variable, when the function result is passed by reference
* Character length of the function result, if it is a of type CHARACTER and no
C binding is used
* The arguments in the order in which they appear in the Fortran declaration
* The present status for optional arguments with value attribute, which are
internally passed by value
* The character length and/or coarray token and offset for the first argument
which is a CHARACTER or a nonallocatable coarray dummy argument, followed by
the hidden arguments of the next dummy argument of such a type
So it is create_function_arglist which is broken.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (4 preceding siblings ...)
2022-10-27 19:49 ` anlauf at gcc dot gnu.org
@ 2022-10-27 20:07 ` anlauf at gcc dot gnu.org
2022-10-27 20:52 ` anlauf at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 20:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #6 from anlauf at gcc dot gnu.org ---
Created attachment 53782
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53782&action=edit
Patch
Regtesting the attached patch.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (5 preceding siblings ...)
2022-10-27 20:07 ` anlauf at gcc dot gnu.org
@ 2022-10-27 20:52 ` anlauf at gcc dot gnu.org
2022-10-27 21:11 ` anlauf at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 20:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #7 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #6)
> Created attachment 53782 [details]
> Patch
>
> Regtesting the attached patch.
Looks good for the reported issue.
However, while working on variations of the testcase, I hit an ICE for:
subroutine test3 (w)
character, intent(in), value, optional :: w
print*, 'present(w) is ', present(w)
end subroutine test3
It is not new, though.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (6 preceding siblings ...)
2022-10-27 20:52 ` anlauf at gcc dot gnu.org
@ 2022-10-27 21:11 ` anlauf at gcc dot gnu.org
2022-10-27 21:56 ` sgk at troutmask dot apl.washington.edu
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-27 21:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #8 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #7)
> However, while working on variations of the testcase, I hit an ICE for:
>
> subroutine test3 (w)
> character, intent(in), value, optional :: w
> print*, 'present(w) is ', present(w)
> end subroutine test3
>
> It is not new, though.
This is now tracked in PR107444.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (7 preceding siblings ...)
2022-10-27 21:11 ` anlauf at gcc dot gnu.org
@ 2022-10-27 21:56 ` sgk at troutmask dot apl.washington.edu
2022-10-28 20:13 ` anlauf at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2022-10-27 21:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #9 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Thu, Oct 27, 2022 at 09:11:08PM +0000, anlauf at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
>
> --- Comment #8 from anlauf at gcc dot gnu.org ---
> (In reply to anlauf from comment #7)
> > However, while working on variations of the testcase, I hit an ICE for:
> >
> > subroutine test3 (w)
> > character, intent(in), value, optional :: w
> > print*, 'present(w) is ', present(w)
> > end subroutine test3
> >
> > It is not new, though.
>
> This is now tracked in PR107444.
>
If no other issues pop up and if this is an old issue,
you can probably commit your fix for current issue
as you've opened a new bug report.
Thanks for pecking away at gfortran bugs.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (8 preceding siblings ...)
2022-10-27 21:56 ` sgk at troutmask dot apl.washington.edu
@ 2022-10-28 20:13 ` anlauf at gcc dot gnu.org
2022-11-09 19:56 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-28 20:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #10 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2022-October/058398.html
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (9 preceding siblings ...)
2022-10-28 20:13 ` anlauf at gcc dot gnu.org
@ 2022-11-09 19:56 ` cvs-commit at gcc dot gnu.org
2022-12-06 18:39 ` anlauf at gcc dot gnu.org
2023-04-08 18:39 ` anlauf at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-09 19:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
--- Comment #11 from CVS 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:e805adaa283129604a1fb305d0a1cf1e8a90c76e
commit r13-3863-ge805adaa283129604a1fb305d0a1cf1e8a90c76e
Author: Harald Anlauf <anlauf@gmx.de>
Date: Fri Oct 28 21:58:08 2022 +0200
Fortran: ordering of hidden procedure arguments [PR107441]
The gfortran ABI specifies the order of given and hidden procedure
arguments,
where the hidden presence status flags of optional+value scalar arguments
shall come before character length, coarray token and offset. Respect
that.
gcc/fortran/ChangeLog:
PR fortran/107441
* trans-decl.cc (create_function_arglist): Adjust the ordering of
automatically generated hidden procedure arguments to match the
documented ABI for gfortran.
* trans-types.cc (gfc_get_function_type): Separate hidden
parameters
so that the presence flag for optional+value arguments come before
string length, coarray token and offset, as required.
gcc/testsuite/ChangeLog:
PR fortran/107441
* gfortran.dg/coarray/pr107441-caf.f90: New test.
* gfortran.dg/optional_absent_6.f90: New test.
* gfortran.dg/optional_absent_7.f90: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (10 preceding siblings ...)
2022-11-09 19:56 ` cvs-commit at gcc dot gnu.org
@ 2022-12-06 18:39 ` anlauf at gcc dot gnu.org
2023-04-08 18:39 ` anlauf at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-12-06 18:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |13.0
--- Comment #12 from anlauf at gcc dot gnu.org ---
Fixed on mainline for gcc-13. Closing.
Thanks for the report!
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/107441] optional arguments are identified as "present" when missing
2022-10-27 17:56 [Bug fortran/107441] New: optional arguments are identified as "present" when missing kaiserkarl31 at yahoo dot com
` (11 preceding siblings ...)
2022-12-06 18:39 ` anlauf at gcc dot gnu.org
@ 2023-04-08 18:39 ` anlauf at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-04-08 18:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107441
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org
--- Comment #13 from anlauf at gcc dot gnu.org ---
*** Bug 91196 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread