public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
@ 2023-03-16 20:15 vincent_saulue at hotmail dot fr
2023-03-17 14:23 ` [Bug c++/109160] " ppalka at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: vincent_saulue at hotmail dot fr @ 2023-03-16 20:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
Bug ID: 109160
Summary: [Valid code] Constraint on deduced NTTP from method
call causes ICE/Segfault.
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent_saulue at hotmail dot fr
Target Milestone: ---
To my knowledge, the following code is well-formed c++20, and compiles with
clang and MSVC.
- g++ 11.x & 12.x: this code causes a segmentation fault.
- g++ 10.x & 13.0(godbolt trunk): this code causes an ICE.
The issue is reproducible on godbolt: https://godbolt.org/z/bxbeTa69f
Code:
```
struct Traits {
static constexpr bool value = true;
};
template<typename T, typename Traits>
concept cBarOf = Traits::value;
template<typename Traits, auto bar>
struct Foo {
template<cBarOf<Traits> auto rhsBar> // <-- this concept causes ICE.
void doNothing(Foo<Traits, rhsBar> const&);
};
void someFunction() {
Foo<Traits, 0> lhs{};
lhs.doNothing(lhs);
}
```
Compiler output on my local machine:
```
# g++ --version
g++-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0
# g++ -std=c++20 source.cpp
source.cpp: In substitution of ‘template<auto [requires ::cBarOf<<placeholder>,
Traits>] rhsBar> void Foo<Traits, 0>::doNothing(const Foo<Traits, rhsBar>&)
[with auto [requires ::cBarOf<<placeholder>, Traits>] rhsBar = <missing>]’:
source.cpp:16:18: required from here
source.cpp:16:18: internal compiler error: Segmentation fault
16 | lhs.doNothing(lhs);
| ~~~~~~~~~~~~~^~~~~
0xd910e3 crash_signal
../../src/gcc/toplev.cc:322
0x7f546f77251f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x801af0 iterative_hash_template_arg(tree_node*, unsigned int)
../../src/gcc/cp/pt.cc:1786
0x6e9d99 sat_hasher::hash(sat_entry*)
../../src/gcc/cp/constraint.cc:2491
0x6e9d99 hash_table<sat_hasher, false, xcallocator>::find_slot(sat_entry*
const&, insert_option)
../../src/gcc/hash-table.h:435
0x6e9d99 satisfaction_cache::satisfaction_cache(tree_node*, tree_node*,
sat_info)
../../src/gcc/cp/constraint.cc:2584
0x6ec446 satisfy_atom
../../src/gcc/cp/constraint.cc:2914
0x6ec446 satisfy_constraint_r
../../src/gcc/cp/constraint.cc:3023
0x6ecf33 satisfy_normalized_constraints
../../src/gcc/cp/constraint.cc:3048
0x6eaa53 satisfy_nondeclaration_constraints
../../src/gcc/cp/constraint.cc:3130
0x6eaa53 constraint_satisfaction_value
../../src/gcc/cp/constraint.cc:3285
0x6ecfbb constraints_satisfied_p(tree_node*, tree_node*)
../../src/gcc/cp/constraint.cc:3317
0x80c2c2 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int)
../../src/gcc/cp/pt.cc:30349
0x8166d9 unify
../../src/gcc/cp/pt.cc:24272
0x816791 unify
../../src/gcc/cp/pt.cc:24476
0x82d48e try_class_unification
../../src/gcc/cp/pt.cc:23437
0x81633b unify
../../src/gcc/cp/pt.cc:24513
0x82bfa3 unify_one_argument
../../src/gcc/cp/pt.cc:22650
0x814938 type_unification_real
../../src/gcc/cp/pt.cc:22773
0x831b0a fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
../../src/gcc/cp/pt.cc:22096
```
Output of godbolt's gcc(trunk):
```
# g++ --version
g++
(Compiler-Explorer-Build-gcc-0c061da91a3657afdb3fac68e4595af685909a1a-binutils-2.38)
13.0.1 20230316 (experimental)
# g++ -std=c++20
<source>: In substitution of 'template<auto [requires ::cBarOf<<placeholder>,
Traits>] rhsBar> void Foo<Traits, 0>::doNothing(const Foo<Traits, rhsBar>&)
[with auto [requires ::cBarOf<<placeholder>, Traits>] rhsBar = <missing>]':
<source>:16:18: required from here
<source>:16:18: internal compiler error: tree check: accessed elt 1 of
'tree_vec' with 0 elts in hash, at cp/constraint.cc:2571
16 | lhs.doNothing(lhs);
| ~~~~~~~~~~~~~^~~~~
0x23b52ae internal_error(char const*, ...)
???:0
0x94819b tree_vec_elt_check_failed(int, int, char const*, int, char const*)
???:0
0xafc7c4 sat_hasher::hash(sat_entry*)
???:0
0xaf7adf satisfaction_cache::satisfaction_cache(tree_node*, tree_node*,
sat_info)
???:0
0xafb922 constraints_satisfied_p(tree_node*, tree_node*)
???:0
0xc79882 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int)
???:0
0xcb0831 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
???:0
0xaac75a build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
???:0
0xc5e0df c_parse_file()
???:0
0xd9ac69 c_common_parse_file()
???:0
```
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
@ 2023-03-17 14:23 ` ppalka at gcc dot gnu.org
2023-04-01 16:01 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-03-17 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2023-03-17
Blocks| |67491
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, this never worked properly.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67491
[Bug 67491] [meta-bug] concepts issues
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
2023-03-17 14:23 ` [Bug c++/109160] " ppalka at gcc dot gnu.org
@ 2023-04-01 16:01 ` cvs-commit at gcc dot gnu.org
2023-04-01 16:02 ` ppalka at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-01 16:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:a5de246535db1b4fdc61287f27de0fdd074fc4b3
commit r13-6971-ga5de246535db1b4fdc61287f27de0fdd074fc4b3
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Apr 1 12:01:30 2023 -0400
c++: NTTP constraint depending on outer parms [PR109160]
Here we're crashing during satisfaction for the NTTP 'C<B> auto V'
ultimately because convert_template_argument / unify don't pass all
outer template arguments to do_auto_deduction, and during satisfaction
we need to know all arguments. While these callers do pass some outer
arguments, they are only sufficient to properly substitute the
(level-lowered) 'auto' and are not necessarily the entire set.
Fortunately it seems these callers have access to the full set of outer
arguments via convert_template_argument's 'in_decl' parameter and
unify's 'tparms' parameter. So this patch adds a new parameter to
do_auto_deduction, used only during adc_unify deduction, through which
these callers can pass the enclosing (partially instantiated) template
and from which do_auto_deduction can obtain _all_ outer template
arguments for sake of satisfaction.
This patch also ensures that the 'in_decl' argument passed to
coerce_template_parms is always a TEMPLATE_DECL, which in turn allows us
to pass it as-is to do_auto_deduction; the only coerce_template_parms
caller that needed adjustment was tsubst_decl it seems.
PR c++/109160
gcc/cp/ChangeLog:
* cp-tree.h (do_auto_deduction): Add defaulted tmpl parameter.
* pt.cc (convert_template_argument): Pass 'in_decl' as 'tmpl' to
do_auto_deduction.
(tsubst_decl) <case VAR_/TYPE_DECL>: Pass 'tmpl' instead of 't' as
'in_decl' to coerce_template_parms.
(unify) <case TEMPLATE_PARM_INDEX>: Pass TPARMS_PRIMARY_TEMPLATE
as 'tmpl' to do_auto_deduction.
(do_auto_deduction): Document default arguments. Rename local
variable 'tmpl' to 'ctmpl'. Use 'tmpl' to obtain a full set of
template arguments for satisfaction in the adc_unify case.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-placeholder12.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
2023-03-17 14:23 ` [Bug c++/109160] " ppalka at gcc dot gnu.org
2023-04-01 16:01 ` cvs-commit at gcc dot gnu.org
@ 2023-04-01 16:02 ` ppalka at gcc dot gnu.org
2023-04-01 16:02 ` ppalka at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-04-01 16:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.3
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12 so far.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
` (2 preceding siblings ...)
2023-04-01 16:02 ` ppalka at gcc dot gnu.org
@ 2023-04-01 16:02 ` ppalka at gcc dot gnu.org
2023-04-14 13:33 ` vincent_saulue at hotmail dot fr
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-04-01 16:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #3)
> Fixed for GCC 12 so far.
GCC 13*
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
` (3 preceding siblings ...)
2023-04-01 16:02 ` ppalka at gcc dot gnu.org
@ 2023-04-14 13:33 ` vincent_saulue at hotmail dot fr
2023-05-08 12:26 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: vincent_saulue at hotmail dot fr @ 2023-04-14 13:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
--- Comment #5 from Vincent Saulue-Laborde <vincent_saulue at hotmail dot fr> ---
(In reply to Patrick Palka from comment #4)
> (In reply to Patrick Palka from comment #3)
> > Fixed for GCC 12 so far.
>
> GCC 13*
I confirm that gcc trunk works fine from my side.
Thanks for the fix !
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
` (4 preceding siblings ...)
2023-04-14 13:33 ` vincent_saulue at hotmail dot fr
@ 2023-05-08 12:26 ` rguenth at gcc dot gnu.org
2023-05-09 12:57 ` cvs-commit at gcc dot gnu.org
2023-05-09 12:58 ` ppalka at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|12.3 |12.4
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
` (5 preceding siblings ...)
2023-05-08 12:26 ` rguenth at gcc dot gnu.org
@ 2023-05-09 12:57 ` cvs-commit at gcc dot gnu.org
2023-05-09 12:58 ` ppalka at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-09 12:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:56da68414b5b5f0124cac29756c88710e5752762
commit r12-9525-g56da68414b5b5f0124cac29756c88710e5752762
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Apr 1 12:01:30 2023 -0400
c++: NTTP constraint depending on outer parms [PR109160]
Here we're crashing during satisfaction for the NTTP 'C<B> auto V'
ultimately because convert_template_argument / unify don't pass all
outer template arguments to do_auto_deduction, and during satisfaction
we need to know all arguments. While these callers do pass some outer
arguments, they are only sufficient to properly substitute the
(level-lowered) 'auto' and are not necessarily the entire set.
Fortunately it seems these callers have access to the full set of outer
arguments via convert_template_argument's 'in_decl' parameter and
unify's 'tparms' parameter. So this patch adds a new parameter to
do_auto_deduction, used only during adc_unify deduction, through which
these callers can pass the enclosing (partially instantiated) template
and from which do_auto_deduction can obtain _all_ outer template
arguments for sake of satisfaction.
This patch also ensures that the 'in_decl' argument passed to
coerce_template_parms is always a TEMPLATE_DECL, which in turn allows us
to pass it as-is to do_auto_deduction; the only coerce_template_parms
caller that needed adjustment was tsubst_decl it seems.
PR c++/109160
gcc/cp/ChangeLog:
* cp-tree.h (do_auto_deduction): Add defaulted tmpl parameter.
* pt.cc (convert_template_argument): Pass 'in_decl' as 'tmpl' to
do_auto_deduction.
(tsubst_decl) <case VAR_/TYPE_DECL>: Pass 'tmpl' instead of 't' as
'in_decl' to coerce_template_parms.
(unify) <case TEMPLATE_PARM_INDEX>: Pass TPARMS_PRIMARY_TEMPLATE
as 'tmpl' to do_auto_deduction.
(do_auto_deduction): Document default arguments. Rename local
variable 'tmpl' to 'ctmpl'. Use 'tmpl' to obtain a full set of
template arguments for satisfaction in the adc_unify case.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-placeholder12.C: New test.
(cherry picked from commit a5de246535db1b4fdc61287f27de0fdd074fc4b3)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/109160] [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault.
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
` (6 preceding siblings ...)
2023-05-09 12:57 ` cvs-commit at gcc dot gnu.org
@ 2023-05-09 12:58 ` ppalka at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-09 12:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109160
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12.4+
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-05-09 12:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 20:15 [Bug c++/109160] New: [Valid code] Constraint on deduced NTTP from method call causes ICE/Segfault vincent_saulue at hotmail dot fr
2023-03-17 14:23 ` [Bug c++/109160] " ppalka at gcc dot gnu.org
2023-04-01 16:01 ` cvs-commit at gcc dot gnu.org
2023-04-01 16:02 ` ppalka at gcc dot gnu.org
2023-04-01 16:02 ` ppalka at gcc dot gnu.org
2023-04-14 13:33 ` vincent_saulue at hotmail dot fr
2023-05-08 12:26 ` rguenth at gcc dot gnu.org
2023-05-09 12:57 ` cvs-commit at gcc dot gnu.org
2023-05-09 12: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).