public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template
@ 2022-11-30 19:09 johelegp at gmail dot com
2022-11-30 19:23 ` [Bug c++/107938] [11/12/13 Regression] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: johelegp at gmail dot com @ 2022-11-30 19:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Bug ID: 107938
Summary: ICE directly returning `this` of `extern` variable in
template
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
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://compiler-explorer.com/z/4d1esaber.
```C++
struct Q {
int n;
constexpr const Q* operator()(auto) const { return this; }
};
extern const Q q;
template<int>
constexpr const Q* p = q(0);
```
```
<source>:9:27: internal compiler error: Segmentation fault
9 | constexpr const Q* p = q(0);
| ^
0x22e3a9e internal_error(char const*, ...)
???:0
0xce2006 convert_for_initialization(tree_node*, tree_node*, tree_node*, int,
impl_conv_rhs, tree_node*, int, int)
???:0
0xced3f0 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xb22845 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
???:0
0xc20997 c_parse_file()
???:0
0xd5b949 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
```
Being less direct works: https://compiler-explorer.com/z/jn99aG36e.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
@ 2022-11-30 19:23 ` pinskia at gcc dot gnu.org
2022-11-30 19:30 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-30 19:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.4
Last reconfirmed| |2022-11-30
Summary|ICE directly returning |[11/12/13 Regression] ICE
|`this` of `extern` variable |directly returning `this`
|in template |of `extern` variable in
| |template
Known to work| |10.4.0
Ever confirmed|0 |1
Keywords| |needs-bisection
Status|UNCONFIRMED |NEW
Known to fail| |11.1.0
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. A regression from GCC 10.4.0.
A C++14 testcase (removing the auto from the operator()):
```
struct Q {
int n;
constexpr const Q* operator()(int) const { return this; }
};
extern const Q q;
template<int>
constexpr const Q* p = q(0);
```
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
2022-11-30 19:23 ` [Bug c++/107938] [11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2022-11-30 19:30 ` pinskia at gcc dot gnu.org
2022-12-01 8:03 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-30 19:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, the following slightly modified testcase works in GCC 8.5.0 but started to
ICE in GCC 9.1.0:
```
struct Q {
int n;
constexpr const Q* operator()(int) const { return this; }
};
constexpr Q q{};
template<int>
constexpr const Q* p = q(0);
```
It is still a regression though.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
2022-11-30 19:23 ` [Bug c++/107938] [11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-11-30 19:30 ` pinskia at gcc dot gnu.org
@ 2022-12-01 8:03 ` rguenth at gcc dot gnu.org
2022-12-02 14:52 ` [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557 jakub at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-01 8:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
` (2 preceding siblings ...)
2022-12-01 8:03 ` rguenth at gcc dot gnu.org
@ 2022-12-02 14:52 ` jakub at gcc dot gnu.org
2023-02-13 18:09 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-02 14:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12/13 Regression] ICE |[11/12/13 Regression] ICE
|directly returning `this` |directly returning `this`
|of `extern` variable in |of `extern` variable in
|template |template since r11-557
Keywords|needs-bisection |
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This also started with r11-557-gbeb019d346b903c16b9fd349937de444b6a8b6c0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
` (3 preceding siblings ...)
2022-12-02 14:52 ` [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557 jakub at gcc dot gnu.org
@ 2023-02-13 18:09 ` mpolacek at gcc dot gnu.org
2023-02-23 23:52 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-13 18:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
CC| |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
` (4 preceding siblings ...)
2023-02-13 18:09 ` mpolacek at gcc dot gnu.org
@ 2023-02-23 23:52 ` mpolacek at gcc dot gnu.org
2023-02-28 15:10 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-02-23 23:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch posted:
<https://gcc.gnu.org/pipermail/gcc-patches/2023-February/612700.html>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
` (5 preceding siblings ...)
2023-02-23 23:52 ` mpolacek at gcc dot gnu.org
@ 2023-02-28 15:10 ` cvs-commit at gcc dot gnu.org
2023-03-04 17:43 ` [Bug c++/107938] [11/12 " cvs-commit at gcc dot gnu.org
2023-03-04 18:24 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-28 15:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
--- Comment #5 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:ea718febab2a1f6e58806738abf70f1c73c6a308
commit r13-6376-gea718febab2a1f6e58806738abf70f1c73c6a308
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Feb 23 17:54:47 2023 -0500
c++: ICE with constexpr variable template [PR107938]
Since r11-557, cp_finish_decl can call check_initializer even in
a template for a constexpr initializer. That ultimately leads to
convert_for_assignment and check_address_or_pointer_of_packed_member,
where we crash, because it doesn't expect that the CALL_EXPR is
a function object. Q has a constexpr operator(), but since we're
in a template, q(0) is a CALL_EXPR whose CALL_EXPR_FN is just
a VAR_DECL; it hasn't been converted to Q::operator<int>(&q, 0) yet.
I propose to robustify check_address_or_pointer_of_packed_member.
var-templ74.C has an XFAIL, subject to 107939.
I noticed that our -Waddress-of-packed-member tests weren't testing
member functions, added thus. (I was tempted to check
FUNCTION_POINTER_TYPE_P but that doesn't include METHOD_TYPE.)
PR c++/107938
gcc/c-family/ChangeLog:
* c-warn.cc (check_address_or_pointer_of_packed_member): Check
POINTER_TYPE_P.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ73.C: New test.
* g++.dg/cpp1y/var-templ74.C: New test.
* g++.dg/warn/Waddress-of-packed-member3.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12 Regression] ICE directly returning `this` of `extern` variable in template since r11-557
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
` (6 preceding siblings ...)
2023-02-28 15:10 ` cvs-commit at gcc dot gnu.org
@ 2023-03-04 17:43 ` cvs-commit at gcc dot gnu.org
2023-03-04 18:24 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-04 17:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
--- Comment #6 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:445082ff3cb7f9d30021adf338e9ab6038c3e412
commit r12-9215-g445082ff3cb7f9d30021adf338e9ab6038c3e412
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Feb 23 17:54:47 2023 -0500
c++: ICE with constexpr variable template [PR107938]
Since r11-557, cp_finish_decl can call check_initializer even in
a template for a constexpr initializer. That ultimately leads to
convert_for_assignment and check_address_or_pointer_of_packed_member,
where we crash, because it doesn't expect that the CALL_EXPR is
a function object. Q has a constexpr operator(), but since we're
in a template, q(0) is a CALL_EXPR whose CALL_EXPR_FN is just
a VAR_DECL; it hasn't been converted to Q::operator<int>(&q, 0) yet.
I propose to robustify check_address_or_pointer_of_packed_member.
var-templ74.C has an XFAIL, subject to 107939.
I noticed that our -Waddress-of-packed-member tests weren't testing
member functions, added thus. (I was tempted to check
FUNCTION_POINTER_TYPE_P but that doesn't include METHOD_TYPE.)
PR c++/107938
gcc/c-family/ChangeLog:
* c-warn.cc (check_address_or_pointer_of_packed_member): Check
POINTER_TYPE_P.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ73.C: New test.
* g++.dg/cpp1y/var-templ74.C: New test.
* g++.dg/warn/Waddress-of-packed-member3.C: New test.
(cherry picked from commit ea718febab2a1f6e58806738abf70f1c73c6a308)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107938] [11/12 Regression] ICE directly returning `this` of `extern` variable in template since r11-557
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
` (7 preceding siblings ...)
2023-03-04 17:43 ` [Bug c++/107938] [11/12 " cvs-commit at gcc dot gnu.org
@ 2023-03-04 18:24 ` mpolacek at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-04 18:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107938
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-03-04 18:24 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-30 19:09 [Bug c++/107938] New: ICE directly returning `this` of `extern` variable in template johelegp at gmail dot com
2022-11-30 19:23 ` [Bug c++/107938] [11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-11-30 19:30 ` pinskia at gcc dot gnu.org
2022-12-01 8:03 ` rguenth at gcc dot gnu.org
2022-12-02 14:52 ` [Bug c++/107938] [11/12/13 Regression] ICE directly returning `this` of `extern` variable in template since r11-557 jakub at gcc dot gnu.org
2023-02-13 18:09 ` mpolacek at gcc dot gnu.org
2023-02-23 23:52 ` mpolacek at gcc dot gnu.org
2023-02-28 15:10 ` cvs-commit at gcc dot gnu.org
2023-03-04 17:43 ` [Bug c++/107938] [11/12 " cvs-commit at gcc dot gnu.org
2023-03-04 18:24 ` mpolacek 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).