* [PATCH] c++: Fix ICE on complex constant with -frounding-math [PR103114]
@ 2021-11-09 9:38 Jakub Jelinek
2021-11-09 13:55 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-11-09 9:38 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
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?
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Fix ICE on complex constant with -frounding-math [PR103114]
2021-11-09 9:38 [PATCH] c++: Fix ICE on complex constant with -frounding-math [PR103114] Jakub Jelinek
@ 2021-11-09 13:55 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-11-09 13:55 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-09 13:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 9:38 [PATCH] c++: Fix ICE on complex constant with -frounding-math [PR103114] Jakub Jelinek
2021-11-09 13:55 ` Jason Merrill
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).