* [PATCH] Fortran: copy-out for possibly missing OPTIONAL CLASS arguments [PR112772]
@ 2023-11-30 21:06 Harald Anlauf
2023-12-01 20:24 ` Mikael Morin
0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2023-11-30 21:06 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 333 bytes --]
Dear all,
the attached rather obvious patch fixes the first testcase of pr112772:
we unconditionally generated copy-out code for optional class arguments,
while the copy-in properly checked the presence of arguments.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
(The second testcase is a different issue.)
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr112772-part1.diff --]
[-- Type: text/x-patch, Size: 3457 bytes --]
From 38433016def0337a72cb0ef0029cd2c05d702282 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 30 Nov 2023 21:53:21 +0100
Subject: [PATCH] Fortran: copy-out for possibly missing OPTIONAL CLASS
arguments [PR112772]
gcc/fortran/ChangeLog:
PR fortran/112772
* trans-expr.cc (gfc_conv_class_to_class): Make copy-out conditional
on the presence of an OPTIONAL CLASS argument passed to an OPTIONAL
CLASS dummy.
gcc/testsuite/ChangeLog:
PR fortran/112772
* gfortran.dg/missing_optional_dummy_7.f90: New test.
---
gcc/fortran/trans-expr.cc | 9 +++
.../gfortran.dg/missing_optional_dummy_7.f90 | 64 +++++++++++++++++++
2 files changed, 73 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/missing_optional_dummy_7.f90
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index bfe9996ced6..6a47af39c57 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1365,6 +1365,15 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts,
tmp = build3_loc (input_location, COND_EXPR, void_type_node,
cond, tmp, tmp2);
gfc_add_expr_to_block (&parmse->pre, tmp);
+
+ if (!elemental && full_array && copyback)
+ {
+ tmp2 = build_empty_stmt (input_location);
+ tmp = gfc_finish_block (&parmse->post);
+ tmp = build3_loc (input_location, COND_EXPR, void_type_node,
+ cond, tmp, tmp2);
+ gfc_add_expr_to_block (&parmse->post, tmp);
+ }
}
else
gfc_add_block_to_block (&parmse->pre, &block);
diff --git a/gcc/testsuite/gfortran.dg/missing_optional_dummy_7.f90 b/gcc/testsuite/gfortran.dg/missing_optional_dummy_7.f90
new file mode 100644
index 00000000000..ad9ecd8f2b6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/missing_optional_dummy_7.f90
@@ -0,0 +1,64 @@
+! { dg-do run }
+! PR fortran/112772 - test absent OPTIONAL, ALLOCATABLE/POINTER class dummies
+
+program main
+ implicit none
+ type t
+ end type t
+ call test_c_a ()
+ call test_u_a ()
+ call test_c_p ()
+ call test_u_p ()
+contains
+ ! class, allocatable
+ subroutine test_c_a (msg1)
+ class(t), optional, allocatable :: msg1(:)
+ if (present (msg1)) stop 1
+ call assert_c_a ()
+ call assert_c_a (msg1)
+ end
+
+ subroutine assert_c_a (msg2)
+ class(t), optional, allocatable :: msg2(:)
+ if (present (msg2)) stop 2
+ end
+
+ ! unlimited polymorphic, allocatable
+ subroutine test_u_a (msg1)
+ class(*), optional, allocatable :: msg1(:)
+ if (present (msg1)) stop 3
+ call assert_u_a ()
+ call assert_u_a (msg1)
+ end
+
+ subroutine assert_u_a (msg2)
+ class(*), optional, allocatable :: msg2(:)
+ if (present (msg2)) stop 4
+ end
+
+ ! class, pointer
+ subroutine test_c_p (msg1)
+ class(t), optional, pointer :: msg1(:)
+ if (present (msg1)) stop 5
+ call assert_c_p ()
+ call assert_c_p (msg1)
+ end
+
+ subroutine assert_c_p (msg2)
+ class(t), optional, pointer :: msg2(:)
+ if (present (msg2)) stop 6
+ end
+
+ ! unlimited polymorphic, pointer
+ subroutine test_u_p (msg1)
+ class(*), optional, pointer :: msg1(:)
+ if (present (msg1)) stop 7
+ call assert_u_p ()
+ call assert_u_p (msg1)
+ end
+
+ subroutine assert_u_p (msg2)
+ class(*), optional, pointer :: msg2(:)
+ if (present (msg2)) stop 8
+ end
+end
--
2.35.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fortran: copy-out for possibly missing OPTIONAL CLASS arguments [PR112772]
2023-11-30 21:06 [PATCH] Fortran: copy-out for possibly missing OPTIONAL CLASS arguments [PR112772] Harald Anlauf
@ 2023-12-01 20:24 ` Mikael Morin
2023-12-01 21:15 ` Harald Anlauf
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Morin @ 2023-12-01 20:24 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Hello,
Le 30/11/2023 à 22:06, Harald Anlauf a écrit :
> the attached rather obvious patch fixes the first testcase of pr112772:
> we unconditionally generated copy-out code for optional class arguments,
> while the copy-in properly checked the presence of arguments.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
Looks good.
Thanks.
> (The second testcase is a different issue.)
>
Maybe use a separate PR?
Mikael
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fortran: copy-out for possibly missing OPTIONAL CLASS arguments [PR112772]
2023-12-01 20:24 ` Mikael Morin
@ 2023-12-01 21:15 ` Harald Anlauf
0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2023-12-01 21:15 UTC (permalink / raw)
To: Mikael Morin, fortran, gcc-patches
Hi Mikael,
On 12/1/23 21:24, Mikael Morin wrote:
> Hello,
>
> Le 30/11/2023 à 22:06, Harald Anlauf a écrit :
>> the attached rather obvious patch fixes the first testcase of pr112772:
>> we unconditionally generated copy-out code for optional class arguments,
>> while the copy-in properly checked the presence of arguments.
>>
>> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>>
> Looks good.
> Thanks.
ok, will commit.
>> (The second testcase is a different issue.)
>>
> Maybe use a separate PR?
>
> Mikael
>
I just found a fix that is regtesting, and which will allow to
re-enable the test failing with ASAN in the patch for PR100651.
Will merge that fix into the previous patch and submit a v3 later.
Thanks,
Harald
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-01 21:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 21:06 [PATCH] Fortran: copy-out for possibly missing OPTIONAL CLASS arguments [PR112772] Harald Anlauf
2023-12-01 20:24 ` Mikael Morin
2023-12-01 21:15 ` Harald Anlauf
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).