public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5751] c++: Mangle EXCESS_PRECISION_EXPR <REAL_CST> as fold_convert REAL_CST [PR108698]
@ 2023-02-09  8:32 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-02-09  8:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b1ed0c9671b99c6b06cbb8c61be14cdec0998de8

commit r13-5751-gb1ed0c9671b99c6b06cbb8c61be14cdec0998de8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Feb 9 09:31:55 2023 +0100

    c++: Mangle EXCESS_PRECISION_EXPR <REAL_CST> 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  <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.

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 <typename T>
+decltype (T () * T () + 1.0) foo ()
+{
+  return T () * T () + 1.0;
+}
+
+void
+bar ()
+{
+  foo <float> ();
+  foo <double> ();
+  foo <long double> ();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-09  8:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09  8:32 [gcc r13-5751] c++: Mangle EXCESS_PRECISION_EXPR <REAL_CST> as fold_convert REAL_CST [PR108698] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).