From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id EA0813858C3A; Tue, 9 Nov 2021 14:30:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA0813858C3A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5054] c++: Fix ICE on complex constant with -frounding-math [PR103114] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: a22d910305a5232694ff48ead37a7f53e46b7202 X-Git-Newrev: 0318df0ae63e47f6b2f30e96205d00dcb3696538 Message-Id: <20211109143014.EA0813858C3A@sourceware.org> Date: Tue, 9 Nov 2021 14:30:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 14:30:15 -0000 https://gcc.gnu.org/g:0318df0ae63e47f6b2f30e96205d00dcb3696538 commit r12-5054-g0318df0ae63e47f6b2f30e96205d00dcb3696538 Author: Jakub Jelinek Date: Tue Nov 9 15:29:36 2021 +0100 c++: Fix ICE on complex constant with -frounding-math [PR103114] 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). 2021-11-09 Jakub Jelinek 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. Diff: --- gcc/cp/parser.c | 5 ++--- gcc/testsuite/g++.dg/ext/complex10.C | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 6061f983392..32de97b08bd 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -4804,9 +4804,8 @@ cp_parser_userdef_numeric_literal (cp_parser *parser) 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)) diff --git a/gcc/testsuite/g++.dg/ext/complex10.C b/gcc/testsuite/g++.dg/ext/complex10.C new file mode 100644 index 00000000000..67dfb0c2aed --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/complex10.C @@ -0,0 +1,5 @@ +// PR c++/103114 +// { dg-do compile } +// { dg-options "-frounding-math" } + +_Complex double d = 10.1i;