From b1ed0c9671b99c6b06cbb8c61be14cdec0998de8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 9 Feb 2023 09:31:55 +0100 Subject: 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. --- gcc/cp/mangle.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gcc/cp/mangle.cc') diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index f2cda3b..f2761d2 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'); -- cgit v1.1