c++: Mangle EXCESS_PRECISION_EXPR <REAL_CST> as fold_convert REAL_CST [PR108698]
Checks
Commit Message
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
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-08 Jakub Jelinek <jakub@redhat.com>
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.
Jakub
Comments
On 2/8/23 00:59, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 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-08 Jakub Jelinek <jakub@redhat.com>
>
> 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.jj 2023-01-25 15:13:23.220649480 +0100
> +++ gcc/cp/mangle.cc 2023-02-07 19:27:35.949588461 +0100
> @@ -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');
> --- gcc/testsuite/g++.dg/cpp0x/pr108698.C.jj 2023-02-07 20:33:45.365125556 +0100
> +++ gcc/testsuite/g++.dg/cpp0x/pr108698.C 2023-02-07 19:55:57.459493456 +0100
> @@ -0,0 +1,16 @@
> +// PR c++/108698
> +// { dg-do compile { target c++11 } }
> +
> +template <typename T>
> +decltype (T () * T () + 1.0) foo ()
> +{
> + return T () * T () + 1.0;
> +}
> +
> +void
> +bar ()
> +{
> + foo <float> ();
> + foo <double> ();
> + foo <long double> ();
> +}
>
> Jakub
>
@@ -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');
@@ -0,0 +1,16 @@
+// PR c++/108698
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+decltype (T () * T () + 1.0) foo ()
+{
+ return T () * T () + 1.0;
+}
+
+void
+bar ()
+{
+ foo <float> ();
+ foo <double> ();
+ foo <long double> ();
+}