public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9158] c++: Fix ICE due to folding a call to constructor on cdtor_returns_this arches (aka arm32) [PR113083
@ 2024-02-23 17:56 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-02-23 17:56 UTC (permalink / raw)
  To: gcc-cvs

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

commit r14-9158-gfdf9df9d55802e1d8ff0bd14585ea61b2bb9d798
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 23 18:55:12 2024 +0100

    c++: Fix ICE due to folding a call to constructor on cdtor_returns_this arches (aka arm32) [PR113083]
    
    When targetm.cxx.cdtor_returns_this () (aka on arm32 TARGET_AAPCS_BASED)
    constructor is supposed to return this pointer, but when we cp_fold such
    a call, we don't take that into account and just INIT_EXPR the object,
    so we can later ICE during gimplification, because the expression doesn't
    have the right type.
    
    2024-02-23  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/113083
            * cp-gimplify.cc (cp_fold): For targetm.cxx.cdtor_returns_this ()
            wrap r into a COMPOUND_EXPR and return folded CALL_EXPR_ARG (x, 0).
    
            * g++.dg/cpp0x/constexpr-113083.C: New test.

Diff:
---
 gcc/cp/cp-gimplify.cc                         | 10 ++++++++--
 gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 30e94797f9fd..f3baae6ade75 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -3412,9 +3412,15 @@ cp_fold (tree x, fold_flags_t flags)
 	    if (DECL_CONSTRUCTOR_P (callee))
 	      {
 		loc = EXPR_LOCATION (x);
-		tree s = build_fold_indirect_ref_loc (loc,
-						      CALL_EXPR_ARG (x, 0));
+		tree a = CALL_EXPR_ARG (x, 0);
+		bool return_this = targetm.cxx.cdtor_returns_this ();
+		if (return_this)
+		  a = cp_save_expr (a);
+		tree s = build_fold_indirect_ref_loc (loc, a);
 		r = cp_build_init_expr (s, r);
+		if (return_this)
+		  r = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (x), r,
+				  fold_convert_loc (loc, TREE_TYPE (x), a));
 	      }
 	    x = r;
 	    break;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C
new file mode 100644
index 000000000000..3829ac589c49
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C
@@ -0,0 +1,16 @@
+// PR c++/113083
+// { dg-do compile { target c++11 } }
+// { dg-options "-Os" }
+
+struct A { constexpr A (); };
+
+void
+foo ()
+{
+  A b;
+}
+
+constexpr
+A::A ()
+{
+}

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

only message in thread, other threads:[~2024-02-23 17:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 17:56 [gcc r14-9158] c++: Fix ICE due to folding a call to constructor on cdtor_returns_this arches (aka arm32) [PR113083 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).