[PATCH] c++: Fix ICE on complex constant with -frounding-math [PR103114]

Jason Merrill jason@redhat.com
Tue Nov 9 13:55:40 GMT 2021


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
> 



More information about the Gcc-patches mailing list