From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Fix ICE on complex constant with -frounding-math [PR103114]
Date: Tue, 9 Nov 2021 08:55:40 -0500 [thread overview]
Message-ID: <0bdf2dd2-62c4-3830-fe0f-600ffc718a0e@redhat.com> (raw)
In-Reply-To: <20211109093843.GM2710@tucnak>
On 11/9/21 04:38, Jakub Jelinek wrote:
> Hi!
>
> The FE uses build_complex which assumes that fold_convert will fold
> value to a constant. With -frounding-math that isn't guaranteed though.
> So, the patch instead fold_build2s COMPLEX_EXPR, which will result
> in build_complex if both arguments are constants, and otherwise
> will build COMPLEX_EXPR.
> build_zero_cst is an optimization for fold_convert (type, integer_zero_node).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2021-11-09 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/103114
> * parser.c (cp_parser_userdef_numeric_literal): Use fold_build2
> with COMPLEX_EXPR arg instead of build_complex, use build_zero_cst
> instead of fold_convert from integer_zero_node.
>
> * g++.dg/ext/complex10.C: New test.
>
> --- gcc/cp/parser.c.jj 2021-10-28 20:07:48.571193189 +0200
> +++ gcc/cp/parser.c 2021-11-08 23:10:14.623106858 +0100
> @@ -4804,9 +4804,8 @@ cp_parser_userdef_numeric_literal (cp_pa
> else /* if (id_equal (suffix_id, "il")) */
> type = long_double_type_node;
>
> - value = build_complex (build_complex_type (type),
> - fold_convert (type, integer_zero_node),
> - fold_convert (type, value));
> + value = fold_build2 (COMPLEX_EXPR, build_complex_type (type),
> + build_zero_cst (type), fold_convert (type, value));
> }
>
> if (cp_parser_uncommitted_to_tentative_parse_p (parser))
> --- gcc/testsuite/g++.dg/ext/complex10.C.jj 2021-11-08 23:09:58.826331001 +0100
> +++ gcc/testsuite/g++.dg/ext/complex10.C 2021-11-08 23:09:21.847855693 +0100
> @@ -0,0 +1,5 @@
> +// PR c++/103114
> +// { dg-do compile }
> +// { dg-options "-frounding-math" }
> +
> +_Complex double d = 10.1i;
>
> Jakub
>
prev parent reply other threads:[~2021-11-09 13:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-09 9:38 Jakub Jelinek
2021-11-09 13:55 ` Jason Merrill [this message]
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=0bdf2dd2-62c4-3830-fe0f-600ffc718a0e@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/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).