public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer
@ 2022-09-28 21:58 johelegp at gmail dot com
2022-09-29 14:26 ` [Bug c++/107079] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: johelegp at gmail dot com @ 2022-09-28 21:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
Bug ID: 107079
Summary: ICE initializing lifetime-extended constexpr variable
that stores its this pointer
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See https://godbolt.org/z/5asqcnoMe.
```C++
struct X {
const X* x = this;
};
constexpr const X& x = X{};
```
```
<source>:4:26: internal compiler error: in cxx_eval_constant_expression, at
cp/constexpr.cc:7591
4 | constexpr const X& x = X{};
| ^
0x23507de internal_error(char const*, ...)
???:0
0xa9ea08 fancy_abort(char const*, int, char const*)
???:0
0xd4f2da store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xb78f38 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
???:0
0xc786f7 c_parse_file()
???:0
0xdb4a19 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
@ 2022-09-29 14:26 ` mpolacek at gcc dot gnu.org
2023-02-03 20:59 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-09-29 14:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-09-29
Summary|ICE initializing |[10/11/12/13 Regression]
|lifetime-extended constexpr |ICE initializing
|variable that stores its |lifetime-extended constexpr
|this pointer |variable that stores its
| |this pointer
Target Milestone|--- |10.5
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |jason at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
Priority|P3 |P2
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed. Started with r269003:
commit e8b3c1bc3ba22dcf59b9c743f11d4cb2bc5d7792
Author: Jason Merrill <jason@redhat.com>
Date: Mon Feb 18 20:01:50 2019 -0500
PR c++/89336 - multiple stores in constexpr stmt.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
2022-09-29 14:26 ` [Bug c++/107079] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
@ 2023-02-03 20:59 ` mpolacek at gcc dot gnu.org
2023-02-03 23:32 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-03 20:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Very interesting. We're in store_init_value, initializing x with
&TARGET_EXPR <D.2768, {.x=(const struct X *) &<PLACEHOLDER_EXPR struct X>}>
but we must lifetime-extend via extend_ref_init_temps and we get
_ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>;, (const struct
X &) &_ZGR1x_;
Since x was declared constexpr, we do cxx_constant_init (not quiet) and we hit
the code added in r269003:
+ bool preeval = SCALAR_TYPE_P (type) || TREE_CODE (t) == MODIFY_EXPR;
+ if (preeval)
+ {
+ /* Evaluate the value to be stored without knowing what object it will
be
+ stored in, so that any side-effects happen first. */
+ if (!SCALAR_TYPE_P (type))
+ new_ctx.ctor = new_ctx.object = NULL_TREE;
+ init = cxx_eval_constant_expression (&new_ctx, init, false,
+ non_constant_p, overflow_p);
while evaluating the INIT_EXPR _ZGR1x_.x = (const struct X *)
&<PLACEHOLDER_EXPR struct X> >>>. But we have no ctx.ctor or ctx.object here
so lookup_placeholder won't find anything and we ICE on
7861 /* A placeholder without a referent. We can get here when
7862 checking whether NSDMIs are noexcept, or in massage_init_elt;
7863 just say it's non-constant for now. */
7864 gcc_assert (ctx->quiet);
Somehow we should manage that the PLACEHOLDER_EXPR is replaced with _ZGR1x_ I
guess.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
2022-09-29 14:26 ` [Bug c++/107079] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
2023-02-03 20:59 ` mpolacek at gcc dot gnu.org
@ 2023-02-03 23:32 ` mpolacek at gcc dot gnu.org
2023-02-07 21:01 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-03 23:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The cxx_constant_init call actually takes decl=x so we should probably use
that.
value = cxx_constant_init (value, decl);
However, in cxx_eval_outermost_constant_expr type is const struct X & and so we
don't set up ctx.object.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (2 preceding siblings ...)
2023-02-03 23:32 ` mpolacek at gcc dot gnu.org
@ 2023-02-07 21:01 ` mpolacek at gcc dot gnu.org
2023-02-08 19:01 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-07 21:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The ICE could be fixed with
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -13604,9 +13604,13 @@ set_up_extended_ref_temp (tree decl, tree expr,
vec<tree, va_gc> **cleanups,
init = NULL_TREE;
}
else
- /* Create the INIT_EXPR that will initialize the temporary
- variable. */
- init = split_nonconstant_init (var, expr);
+ {
+ /* Create the INIT_EXPR that will initialize the temporary
+ variable. */
+ init = split_nonconstant_init (var, expr);
+ replace_placeholders (init, var);
+ }
+
if (at_function_scope_p ())
{
add_decl_expr (var);
but it'll result in
error: modification of ‘<temporary>’ is not a constant expression
because the INIT_EXPR is
_ZGR1x_.x = (const struct X *) &_ZGR1x_
but _ZGR1x_ isn't in our constexpr context.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (3 preceding siblings ...)
2023-02-07 21:01 ` mpolacek at gcc dot gnu.org
@ 2023-02-08 19:01 ` mpolacek at gcc dot gnu.org
2023-02-10 0:06 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-08 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I'll post...something.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12/13 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (4 preceding siblings ...)
2023-02-08 19:01 ` mpolacek at gcc dot gnu.org
@ 2023-02-10 0:06 ` cvs-commit at gcc dot gnu.org
2023-02-10 0:07 ` [Bug c++/107079] [10/11/12 " mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-10 0:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:67b82bc1b29b82e4577df9491793624f3a8eb12f
commit r13-5763-g67b82bc1b29b82e4577df9491793624f3a8eb12f
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Feb 8 14:02:48 2023 -0500
c++: ICE initing lifetime-extended constexpr var [PR107079]
We ICE on the simple:
struct X { const X* x = this; };
constexpr const X& x = X{};
where store_init_value initializes 'x' with
&TARGET_EXPR <D.2768, {.x=(const struct X *) &<PLACEHOLDER_EXPR struct
X>}>
but we must lifetime-extend via extend_ref_init_temps and we get
_ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>;, (const
struct X &) &_ZGR1x_;
Since 'x' was declared constexpr, we do cxx_constant_init and we hit
the preeval code added in r269003 while evaluating the INIT_EXPR:
_ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>
but we have no ctx.ctor or ctx.object here so lookup_placeholder won't
find anything that could replace X and we ICE on
7861 /* A placeholder without a referent. We can get here when
7862 checking whether NSDMIs are noexcept, or in
massage_init_elt;
7863 just say it's non-constant for now. */
7864 gcc_assert (ctx->quiet);
because cxx_constant_init means !ctx->quiet. It's not correct that
there isn't a referent. I think the following patch is a pretty
straightforward fix: pass the _ZGR var down to maybe_constant_init so
that it can replace the PLACEHOLDER_EXPR with _ZGR1x_.
The commented assert in the test doesn't pass: we complain that _ZGR1x_
isn't a constexpr variable because we don't implement DR2126 (PR101588).
PR c++/107079
gcc/cp/ChangeLog:
* call.cc (set_up_extended_ref_temp): Pass var to
maybe_constant_init.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-nsdmi2.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (5 preceding siblings ...)
2023-02-10 0:06 ` cvs-commit at gcc dot gnu.org
@ 2023-02-10 0:07 ` mpolacek at gcc dot gnu.org
2023-03-07 16:24 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-10 0:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[10/11/12/13 Regression] |[10/11/12 Regression] ICE
|ICE initializing |initializing
|lifetime-extended constexpr |lifetime-extended constexpr
|variable that stores its |variable that stores its
|this pointer |this pointer
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11/12 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (6 preceding siblings ...)
2023-02-10 0:07 ` [Bug c++/107079] [10/11/12 " mpolacek at gcc dot gnu.org
@ 2023-03-07 16:24 ` cvs-commit at gcc dot gnu.org
2023-03-07 16:25 ` [Bug c++/107079] [10/11 " mpolacek at gcc dot gnu.org
2023-06-30 13:58 ` ppalka at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-07 16:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:fb82334341e21ad0254f63e942be276f62d111cf
commit r12-9233-gfb82334341e21ad0254f63e942be276f62d111cf
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Feb 8 14:02:48 2023 -0500
c++: ICE initing lifetime-extended constexpr var [PR107079]
We ICE on the simple:
struct X { const X* x = this; };
constexpr const X& x = X{};
where store_init_value initializes 'x' with
&TARGET_EXPR <D.2768, {.x=(const struct X *) &<PLACEHOLDER_EXPR struct
X>}>
but we must lifetime-extend via extend_ref_init_temps and we get
_ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>;, (const
struct X &) &_ZGR1x_;
Since 'x' was declared constexpr, we do cxx_constant_init and we hit
the preeval code added in r269003 while evaluating the INIT_EXPR:
_ZGR1x_.x = (const struct X *) &<PLACEHOLDER_EXPR struct X> >>>
but we have no ctx.ctor or ctx.object here so lookup_placeholder won't
find anything that could replace X and we ICE on
7861 /* A placeholder without a referent. We can get here when
7862 checking whether NSDMIs are noexcept, or in
massage_init_elt;
7863 just say it's non-constant for now. */
7864 gcc_assert (ctx->quiet);
because cxx_constant_init means !ctx->quiet. It's not correct that
there isn't a referent. I think the following patch is a pretty
straightforward fix: pass the _ZGR var down to maybe_constant_init so
that it can replace the PLACEHOLDER_EXPR with _ZGR1x_.
The commented assert in the test doesn't pass: we complain that _ZGR1x_
isn't a constexpr variable because we don't implement DR2126 (PR101588).
PR c++/107079
gcc/cp/ChangeLog:
* call.cc (set_up_extended_ref_temp): Pass var to
maybe_constant_init.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-nsdmi2.C: New test.
(cherry picked from commit 67b82bc1b29b82e4577df9491793624f3a8eb12f)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (7 preceding siblings ...)
2023-03-07 16:24 ` cvs-commit at gcc dot gnu.org
@ 2023-03-07 16:25 ` mpolacek at gcc dot gnu.org
2023-06-30 13:58 ` ppalka at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-07 16:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Summary|[10/11/12 Regression] ICE |[10/11 Regression] ICE
|initializing |initializing
|lifetime-extended constexpr |lifetime-extended constexpr
|variable that stores its |variable that stores its
|this pointer |this pointer
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/107079] [10/11 Regression] ICE initializing lifetime-extended constexpr variable that stores its this pointer
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
` (8 preceding siblings ...)
2023-03-07 16:25 ` [Bug c++/107079] [10/11 " mpolacek at gcc dot gnu.org
@ 2023-06-30 13:58 ` ppalka at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-06-30 13:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107079
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
Target Milestone|10.5 |12.3
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-06-30 13:58 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 21:58 [Bug c++/107079] New: ICE initializing lifetime-extended constexpr variable that stores its this pointer johelegp at gmail dot com
2022-09-29 14:26 ` [Bug c++/107079] [10/11/12/13 Regression] " mpolacek at gcc dot gnu.org
2023-02-03 20:59 ` mpolacek at gcc dot gnu.org
2023-02-03 23:32 ` mpolacek at gcc dot gnu.org
2023-02-07 21:01 ` mpolacek at gcc dot gnu.org
2023-02-08 19:01 ` mpolacek at gcc dot gnu.org
2023-02-10 0:06 ` cvs-commit at gcc dot gnu.org
2023-02-10 0:07 ` [Bug c++/107079] [10/11/12 " mpolacek at gcc dot gnu.org
2023-03-07 16:24 ` cvs-commit at gcc dot gnu.org
2023-03-07 16:25 ` [Bug c++/107079] [10/11 " mpolacek at gcc dot gnu.org
2023-06-30 13:58 ` ppalka at gcc dot gnu.org
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).