From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 423E13858C50; Thu, 9 Feb 2023 08:32:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 423E13858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675931559; bh=FCyYQKbCv8Z6/ImzyabCL5TrRihnzIBST6bv9ipYk00=; h=From:To:Subject:Date:From; b=iXFI/56d8+vZHqFldXw+WtUw8Mw2g4frtklr88SXI+cw9wlIlkA7ZQi9vOoaMNAIO lnSBgybNb0Yyk3v7iqCfeZGNyDc2+RlPn/18UCPgafp/tTW8jtZa7nK4B3HMDBAgbf 8ejmPtSF4iM0HLsCxEtl+QYCoGbvC3Fyk27kYZOE= 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 r13-5751] c++: Mangle EXCESS_PRECISION_EXPR as fold_convert REAL_CST [PR108698] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 4b19ff1b5ef684c2d9ccd4fb275aeef0a4b0b980 X-Git-Newrev: b1ed0c9671b99c6b06cbb8c61be14cdec0998de8 Message-Id: <20230209083239.423E13858C50@sourceware.org> Date: Thu, 9 Feb 2023 08:32:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b1ed0c9671b99c6b06cbb8c61be14cdec0998de8 commit r13-5751-gb1ed0c9671b99c6b06cbb8c61be14cdec0998de8 Author: Jakub Jelinek Date: Thu Feb 9 09:31:55 2023 +0100 c++: Mangle EXCESS_PRECISION_EXPR as fold_convert REAL_CST [PR108698] For standard excess precision, like the C FE we parse floating point constants as EXCESS_PRECISION_EXPR of promoted REAL_CST rather than the nominal REAL_CST, and as the following testcase shows the constants might need mangling. The following patch mangles those as fold_convert of the REAL_CST to EXCESS_PRECISION_EXPR type, i.e. how they were mangled before. I'm not really sure EXCESS_PRECISION_EXPR can appear elsewhere in expressions that would need mangling, tried various testcases but haven't managed to come up with one. If that is possible, we'd keep ICEing on it without/with this patch, and the big question is how to mangle those; they could be mangled as casts from the promoted type back to nominal, but then in the mangled expressions one could see the effects of excess precision. Until we have a reproducer, that is just theoretical though. 2023-02-09 Jakub Jelinek PR c++/108698 * mangle.cc (write_expression, write_template_arg): Handle EXCESS_PRECISION_EXPR with REAL_CST operand as write_template_arg_literal on fold_convert of the REAL_CST to EXCESS_PRECISION_EXPR type. * g++.dg/cpp0x/pr108698.C: New test. Diff: --- gcc/cp/mangle.cc | 8 ++++++++ gcc/testsuite/g++.dg/cpp0x/pr108698.C | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index f2cda3be2cf..f2761d22bba 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -3107,6 +3107,10 @@ write_expression (tree expr) else if (TREE_CODE_CLASS (code) == tcc_constant || code == CONST_DECL) write_template_arg_literal (expr); + else if (code == EXCESS_PRECISION_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == REAL_CST) + write_template_arg_literal (fold_convert (TREE_TYPE (expr), + TREE_OPERAND (expr, 0))); else if (code == PARM_DECL && DECL_ARTIFICIAL (expr)) { gcc_assert (id_equal (DECL_NAME (expr), "this")); @@ -3815,6 +3819,10 @@ write_template_arg (tree node) || code == CONST_DECL || null_member_pointer_value_p (node)) write_template_arg_literal (node); + else if (code == EXCESS_PRECISION_EXPR + && TREE_CODE (TREE_OPERAND (node, 0)) == REAL_CST) + write_template_arg_literal (fold_convert (TREE_TYPE (node), + TREE_OPERAND (node, 0))); else if (DECL_P (node)) { write_char ('L'); diff --git a/gcc/testsuite/g++.dg/cpp0x/pr108698.C b/gcc/testsuite/g++.dg/cpp0x/pr108698.C new file mode 100644 index 00000000000..30fd8cff943 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr108698.C @@ -0,0 +1,16 @@ +// PR c++/108698 +// { dg-do compile { target c++11 } } + +template +decltype (T () * T () + 1.0) foo () +{ + return T () * T () + 1.0; +} + +void +bar () +{ + foo (); + foo (); + foo (); +}