* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
@ 2023-12-19 12:34 ` rguenth at gcc dot gnu.org
2023-12-19 14:11 ` jakub at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-19 12:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|target |c++
Target Milestone|--- |14.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
2023-12-19 12:34 ` [Bug c++/113083] " rguenth at gcc dot gnu.org
@ 2023-12-19 14:11 ` jakub at gcc dot gnu.org
2023-12-19 15:09 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-12-19 14:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Maybe targetm.cxx.cdtor_returns_this () related?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
2023-12-19 12:34 ` [Bug c++/113083] " rguenth at gcc dot gnu.org
2023-12-19 14:11 ` jakub at gcc dot gnu.org
@ 2023-12-19 15:09 ` mpolacek at gcc dot gnu.org
2023-12-19 22:17 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-19 15:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Last reconfirmed| |2023-12-19
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Priority|P3 |P1
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (2 preceding siblings ...)
2023-12-19 15:09 ` mpolacek at gcc dot gnu.org
@ 2023-12-19 22:17 ` mpolacek at gcc dot gnu.org
2023-12-20 17:01 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-19 22:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Previously we had:
{
return A::A (this);
}
now:
{
return *this = {};
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (3 preceding siblings ...)
2023-12-19 22:17 ` mpolacek at gcc dot gnu.org
@ 2023-12-20 17:01 ` mpolacek at gcc dot gnu.org
2023-12-22 19:21 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-20 17:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The ICE can be reproduced with -O -fdeclone-ctor-dtor as well.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (4 preceding siblings ...)
2023-12-20 17:01 ` mpolacek at gcc dot gnu.org
@ 2023-12-22 19:21 ` mpolacek at gcc dot gnu.org
2024-01-10 15:13 ` jason at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-22 19:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The problem occurs only when we declone cdtors and are on a
targetm.cxx.cdtor_returns_this target like ARM.
Decloning causes us to create a thunk calling the "main" ctor:
A*
A::A (A *const this)
{
return A::A (this);
}
'this' is now accepted in constexpr so we evaluate the call into {} and end up
with
{
return *this = {};
}
which is gimplified into
{
A *D.4937;
D.4937 = *this = {};
}
but that means there's a discrepancy: we're converting A to A* and that
crashes.
I wonder if we should refuse to evaluate A::A (this) (returning a pointer) into
{} (not a pointer).
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (5 preceding siblings ...)
2023-12-22 19:21 ` mpolacek at gcc dot gnu.org
@ 2024-01-10 15:13 ` jason at gcc dot gnu.org
2024-02-22 21:27 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2024-01-10 15:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #4)
> I wonder if we should refuse to evaluate A::A (this) (returning a pointer)
> into {} (not a pointer).
If the constructor returns a pointer, instead of maybe_constant_value
evaluating A::A (this) to (*this = {}), perhaps it should become (*this = {},
this)?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (6 preceding siblings ...)
2024-01-10 15:13 ` jason at gcc dot gnu.org
@ 2024-02-22 21:27 ` jakub at gcc dot gnu.org
2024-02-22 21:33 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-22 21:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What about:
2024-02-22 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.
--- gcc/cp/cp-gimplify.cc.jj 2024-02-22 21:45:09.663430066 +0100
+++ gcc/cp/cp-gimplify.cc 2024-02-22 22:16:41.816591451 +0100
@@ -3415,6 +3415,10 @@ cp_fold (tree x, fold_flags_t flags)
tree s = build_fold_indirect_ref_loc (loc,
CALL_EXPR_ARG (x, 0));
r = cp_build_init_expr (s, r);
+ if (targetm.cxx.cdtor_returns_this ())
+ r = build2 (COMPOUND_EXPR, TREE_TYPE (x), r,
+ fold_convert (TREE_TYPE (x),
+ CALL_EXPR_ARG (x, 0)));
}
x = r;
break;
--- gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C.jj 2024-01-13
00:05:00.077372302 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C 2024-02-22
22:20:20.622618992 +0100
@@ -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 ()
+{
+}
Though, perhaps we need cp_save_expr in that case to make sure if there were
side-effects in CALL_EXPR (x, 0) that we wouldn't evaluate them twice.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (7 preceding siblings ...)
2024-02-22 21:27 ` jakub at gcc dot gnu.org
@ 2024-02-22 21:33 ` jakub at gcc dot gnu.org
2024-02-23 17:56 ` cvs-commit at gcc dot gnu.org
2024-02-23 17:58 ` jakub at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-22 21:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As in:
2024-02-22 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.
--- gcc/cp/cp-gimplify.cc.jj 2024-02-22 21:45:09.663430066 +0100
+++ gcc/cp/cp-gimplify.cc 2024-02-22 22:30:23.481428242 +0100
@@ -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;
--- gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C.jj 2024-01-13
00:05:00.077372302 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-113083.C 2024-02-22
22:20:20.622618992 +0100
@@ -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] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (8 preceding siblings ...)
2024-02-22 21:33 ` jakub at gcc dot gnu.org
@ 2024-02-23 17:56 ` cvs-commit at gcc dot gnu.org
2024-02-23 17:58 ` jakub at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-23 17:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113083] [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0
2023-12-19 11:39 [Bug target/113083] New: [14 Regression][arm] ICE in fold_convert_loc, at fold-const.cc:2602 since r14-5979-g99d114c15523e0 mjires at suse dot cz
` (9 preceding siblings ...)
2024-02-23 17:56 ` cvs-commit at gcc dot gnu.org
@ 2024-02-23 17:58 ` jakub at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-23 17:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113083
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 12+ messages in thread