public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments
@ 2023-11-29 21:35 anlauf at gcc dot gnu.org
2023-11-30 20:48 ` [Bug fortran/112772] " anlauf at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-29 21:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112772
Bug ID: 112772
Summary: Some issues with OPTIONAL, ALLOCATABLE dummy arguments
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: ---
While working on pr100651, the following issues surfaced (not discussed there):
program main
call test_rank1 ()
contains
subroutine test_rank1 (msg1)
class(*), optional, allocatable :: msg1(:)
if (present (msg1)) stop 77
call assert_rank1 () ! <- no problem here
call assert_rank1 (msg1) ! <- problematic code path
end
subroutine assert_rank1 (msg2)
class(*), optional, allocatable :: msg2(:)
end
end
This crashes at runtime. The dump for the problematic code path is:
{
struct __class__STAR_1_0a class.0;
if (msg1 != 0B)
{
class.0._len = msg1->_len;
class.0._data = msg1->_data;
class.0._vptr = msg1->_vptr;
}
assert_rank1 (msg1 != 0B ? &class.0 : 0B);
msg1->_data = class.0._data;
msg1->_vptr = class.0._vptr;
msg1->_len = class.0._len;
}
We need to protect the copy-out for an absent optional argument.
Also, the testcase provided in
https://gcc.gnu.org/pipermail/fortran/2023-November/059969.html
which is similar to the above but uses deferred-length character
shows a questionable tree dump (excerpt):
void test_rank1 (struct array01_character(kind=1) * msg1, integer(kind=8) *
_msg1)
{
integer(kind=8) D.4350;
bitsizetype D.4351;
sizetype D.4352;
D.4350 = *_msg1;
D.4351 = (bitsizetype) (sizetype) *_msg1 * 8;
D.4352 = (sizetype) *_msg1;
if (msg1 != 0B)
{
_gfortran_stop_numeric (77, 0);
}
L.2:;
assert_rank1 (0B, &0);
{
struct array01_character(kind=1) * D.4348;
integer(kind=8) * D.4349;
D.4348 = msg1 != 0B ? msg1 : 0B;
D.4349 = msg1 != 0B ? _msg1 : 0B;
assert_rank1 (D.4348, D.4349);
}
}
This emits warning messages with -fsanitize=undefined, likely due to the
unconditional dereferencing of _msg1 at function entry.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/112772] Some issues with OPTIONAL, ALLOCATABLE dummy arguments
2023-11-29 21:35 [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments anlauf at gcc dot gnu.org
@ 2023-11-30 20:48 ` anlauf at gcc dot gnu.org
2023-11-30 21:08 ` anlauf at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-30 20:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112772
--- Comment #1 from anlauf at gcc dot gnu.org ---
Created attachment 56736
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56736&action=edit
Fix for testcase 1
The attached rather obvious patch fixes the copy-out issue for class dummies
and regtests ok.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/112772] Some issues with OPTIONAL, ALLOCATABLE dummy arguments
2023-11-29 21:35 [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments anlauf at gcc dot gnu.org
2023-11-30 20:48 ` [Bug fortran/112772] " anlauf at gcc dot gnu.org
@ 2023-11-30 21:08 ` anlauf at gcc dot gnu.org
2023-12-01 21:03 ` anlauf at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-11-30 21:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112772
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
--- Comment #2 from anlauf at gcc dot gnu.org ---
Fix for first testcase submitted:
https://gcc.gnu.org/pipermail/fortran/2023-November/059976.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/112772] Some issues with OPTIONAL, ALLOCATABLE dummy arguments
2023-11-29 21:35 [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments anlauf at gcc dot gnu.org
2023-11-30 20:48 ` [Bug fortran/112772] " anlauf at gcc dot gnu.org
2023-11-30 21:08 ` anlauf at gcc dot gnu.org
@ 2023-12-01 21:03 ` anlauf at gcc dot gnu.org
2023-12-01 21:21 ` cvs-commit at gcc dot gnu.org
2023-12-02 14:23 ` anlauf at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-12-01 21:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112772
--- Comment #3 from anlauf at gcc dot gnu.org ---
Created attachment 56758
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56758&action=edit
Patch for testcase 2
This patch makes the initialization code seen in testcase 2
dependent on the presence of the optional argument.
Needs testing.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/112772] Some issues with OPTIONAL, ALLOCATABLE dummy arguments
2023-11-29 21:35 [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments anlauf at gcc dot gnu.org
` (2 preceding siblings ...)
2023-12-01 21:03 ` anlauf at gcc dot gnu.org
@ 2023-12-01 21:21 ` cvs-commit at gcc dot gnu.org
2023-12-02 14:23 ` anlauf at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-01 21:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112772
--- Comment #4 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:7317275497e10c4a0fb3fbaa6ca87f3463ac124d
commit r14-6066-g7317275497e10c4a0fb3fbaa6ca87f3463ac124d
Author: Harald Anlauf <anlauf@gmx.de>
Date: Thu Nov 30 21:53:21 2023 +0100
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/112772] Some issues with OPTIONAL, ALLOCATABLE dummy arguments
2023-11-29 21:35 [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments anlauf at gcc dot gnu.org
` (3 preceding siblings ...)
2023-12-01 21:21 ` cvs-commit at gcc dot gnu.org
@ 2023-12-02 14:23 ` anlauf at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-12-02 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112772
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Keywords| |wrong-code
Target Milestone|--- |14.0
Status|UNCONFIRMED |RESOLVED
--- Comment #5 from anlauf at gcc dot gnu.org ---
Fixed testcase 1.
Testcase 2 is dealt with by the fix for pr100651.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-12-02 14:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-29 21:35 [Bug fortran/112772] New: Some issues with OPTIONAL, ALLOCATABLE dummy arguments anlauf at gcc dot gnu.org
2023-11-30 20:48 ` [Bug fortran/112772] " anlauf at gcc dot gnu.org
2023-11-30 21:08 ` anlauf at gcc dot gnu.org
2023-12-01 21:03 ` anlauf at gcc dot gnu.org
2023-12-01 21:21 ` cvs-commit at gcc dot gnu.org
2023-12-02 14:23 ` 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).