public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/86277] Presence of optional arguments not recognized for zero length arrays
Date: Sun, 11 Jun 2023 20:44:08 +0000	[thread overview]
Message-ID: <bug-86277-4-OD4UB7kIXp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-86277-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86277

--- Comment #20 from anlauf at gcc dot gnu.org ---
(In reply to Mikael Morin from comment #18)
> Created attachment 55300 [details]
> Alternative patch v2

This patch fails for me on several occasions including the testsuite.
I guess the logic was intended as follows:

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e1c75e9fe02..ebadda20004 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1117,7 +1117,7 @@ gfc_trans_allocate_array_storage (stmtblock_t * pre,
stmtblock_t * post,

   desc = info->descriptor;
   info->offset = gfc_index_zero_node;
-  if (size == NULL_TREE || integer_zerop (size))
+  if (size == NULL_TREE)
     {
       /* A callee allocated array.  */
       gfc_conv_descriptor_data_set (pre, desc, null_pointer_node);
@@ -1129,6 +1129,7 @@ gfc_trans_allocate_array_storage (stmtblock_t * pre,
stmtblock_t * post,
       onstack = !dynamic && initial == NULL_TREE
                         && (flag_stack_arrays
                             || gfc_can_put_var_on_stack (size));
+      onstack = onstack && !integer_zerop (size);

       if (onstack)
        {


This seems to work on the present cases and regtests almost cleanly, with
the only exception being gfortran.dg/pr69955.f90, which needs an adjustment
of the scan-tree-dump pattern due to an additional __builtin_malloc.

I am beginning to think that there are multiple issues exhibited here: a
wrong-code issue, which is fixed by the above, and a missed-optimization,
which I tried to address with my initial patch.

If the above patch turns out to fix the wrong-code issue safely, I would
like to prepare it for mainline, and if it survives there for some time,
consider a backport to 13-branch in time for 13.2 release.

The missed optimization with superfluous temporaries could then be split
off to a separate PR and addressed only for future (14+) branches.

I'll prepare additional testcases for character and type and see if the above
patch is sufficient.

  parent reply	other threads:[~2023-06-11 20:44 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-86277-4@http.gcc.gnu.org/bugzilla/>
2020-03-12 11:58 ` jakub at gcc dot gnu.org
2021-06-01  8:11 ` rguenth at gcc dot gnu.org
2022-05-27  8:19 ` rguenth at gcc dot gnu.org
2023-06-09 19:48 ` anlauf at gcc dot gnu.org
2023-06-09 19:48 ` anlauf at gcc dot gnu.org
2023-06-10 10:27 ` mikael at gcc dot gnu.org
2023-06-10 10:30 ` mikael at gcc dot gnu.org
2023-06-10 10:40 ` mikael at gcc dot gnu.org
2023-06-10 11:45 ` mikael at gcc dot gnu.org
2023-06-10 13:21 ` anlauf at gcc dot gnu.org
2023-06-10 13:25 ` anlauf at gcc dot gnu.org
2023-06-10 19:27 ` anlauf at gcc dot gnu.org
2023-06-10 19:55 ` mikael at gcc dot gnu.org
2023-06-10 20:07 ` mikael at gcc dot gnu.org
2023-06-10 20:17 ` mikael at gcc dot gnu.org
2023-06-10 20:33 ` mikael at gcc dot gnu.org
2023-06-11 20:44 ` anlauf at gcc dot gnu.org [this message]
2023-06-12  7:13 ` mikael at gcc dot gnu.org
2023-06-12  7:39 ` mikael at gcc dot gnu.org
2023-06-12  7:56 ` mikael at gcc dot gnu.org
2023-06-12  8:17 ` mikael at gcc dot gnu.org
2023-06-12 10:38 ` mikael at gcc dot gnu.org
2023-06-12 19:42 ` anlauf at gcc dot gnu.org
2023-06-12 19:47 ` anlauf at gcc dot gnu.org
2023-06-12 20:16 ` mikael at gcc dot gnu.org
2023-06-12 20:32 ` anlauf at gcc dot gnu.org
2023-06-12 20:51 ` mikael at gcc dot gnu.org
2023-06-12 21:00 ` anlauf at gcc dot gnu.org
2023-06-12 21:14 ` anlauf at gcc dot gnu.org
2023-06-13 18:09 ` cvs-commit at gcc dot gnu.org
2023-06-13 19:30 ` anlauf at gcc dot gnu.org
2023-06-29 19:50 ` cvs-commit at gcc dot gnu.org
2023-06-29 19:53 ` anlauf at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-86277-4-OD4UB7kIXp@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).