public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/107000] ICE in gfc_real2complex, at fortran/arith.cc:2243
Date: Wed, 28 Sep 2022 18:22:16 +0000	[thread overview]
Message-ID: <bug-107000-4-obINwlGDsb@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107000-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from kargl at gcc dot gnu.org ---
(In reply to anlauf from comment #7)
> (In reply to Steve Kargl from comment #6)
> > Yes, that would work!  I was thinking of something more complex
> > such as looking at the types of the operand(s), but simplification
> > probably handles +1 and -1 correctly and punts on +'1' and -'1'.
> 
> I played some more and found that we would regress on e.g.
> 
>   print *, [real :: 1, +real(2.0)]
> 
> while
> 
>   print *, [real :: 1,  real(2.0)]
> 
> is fine.
> 
> So we need a better solution...

This is the type of solution I had in mind.  It allows the above
and catches +.false. and -.true.

diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index bbdb5b392fc..8b689f28612 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -1205,6 +1205,21 @@ walk_array_constructor (gfc_typespec *ts,
gfc_constructor_base head)
   for (c = gfc_constructor_first (head); c; c = gfc_constructor_next (c))
     {
       e = c->expr;
+
+      /* Special case unary operators to catch [real :: +'1'].  */
+      if (e->expr_type == EXPR_OP && e->ts.type == BT_UNKNOWN)
+       {
+         gfc_expr *op1 = e->value.op.op1;
+         if ((op1->value.op.op == INTRINSIC_UMINUS
+              || op1->value.op.op == INTRINSIC_UPLUS)
+             && !gfc_numeric_ts (&op1->ts))
+           {
+             gfc_error("Invalid operand of unary operator at %L",
+                       &op1->where);
+             return MATCH_ERROR;
+           }
+       }
+
       if (e->expr_type == EXPR_ARRAY && e->ts.type == BT_UNKNOWN
          && !e->ref && e->value.constructor)
        {

Unfortunately, it ICEs with 

 print *, [real :: 1, +(.true)]

  parent reply	other threads:[~2022-09-28 18:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21 17:33 [Bug fortran/107000] New: " gscfq@t-online.de
2022-09-21 17:34 ` [Bug fortran/107000] " gscfq@t-online.de
2022-09-21 18:58 ` anlauf at gcc dot gnu.org
2022-09-21 19:44 ` anlauf at gcc dot gnu.org
2022-09-24 16:30 ` kargl at gcc dot gnu.org
2022-09-26 20:38 ` anlauf at gcc dot gnu.org
2022-09-26 21:37 ` sgk at troutmask dot apl.washington.edu
2022-09-27 19:32 ` anlauf at gcc dot gnu.org
2022-09-28 18:22 ` kargl at gcc dot gnu.org [this message]
2022-09-28 18:55 ` kargl at gcc dot gnu.org
2022-09-29 19:57 ` anlauf at gcc dot gnu.org
2022-09-29 20:10 ` sgk at troutmask dot apl.washington.edu
2022-09-29 21:13 ` sgk at troutmask dot apl.washington.edu
2022-09-30 12:45 ` mikael at gcc dot gnu.org
2022-09-30 19:46 ` anlauf at gcc dot gnu.org
2022-09-30 20:26 ` sgk at troutmask dot apl.washington.edu
2022-10-02 20:05 ` anlauf at gcc dot gnu.org
2022-10-02 20:58 ` anlauf at gcc dot gnu.org
2022-10-03 10:05 ` mikael at gcc dot gnu.org
2022-10-03 10:14 ` mikael at gcc dot gnu.org
2022-10-03 19:36 ` anlauf at gcc dot gnu.org
2022-10-04 21:20 ` anlauf at gcc dot gnu.org
2022-10-05 16:10 ` sgk at troutmask dot apl.washington.edu
2022-10-05 21:20 ` anlauf at gcc dot gnu.org
2022-10-08 20:27 ` cvs-commit at gcc dot gnu.org
2023-05-02 19:11 ` 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-107000-4-obINwlGDsb@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).