https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97093
Bug ID: 97093 Summary: ICE on C++20 code: memory corruption when chaining requirements (in hashtab_chk_error, at hash-table.c:137) Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dimitri.gorokhovik at free dot fr Target Milestone: --- The following code: template <typename T> concept C = requires (T t) { requires t.some_const < 2 #if BUG || requires { t.some_fn (); } #endif ; }; template <unsigned, unsigned> struct c {}; template <typename T> concept P = requires (T t, c <0, 1> v) { #if BUG { t (v) }; #else true; #endif }; template <P auto, P auto ...> struct m { constexpr auto operator () (C auto) const {}; }; struct pc { constexpr auto operator () (C auto) const {}; }; constexpr auto cc = pc {}; constexpr auto mmcc = m <cc> {}; when compiled as: g++ -std=c++20 -fconcepts-diagnostics-depth=3 -o bug-5.o -c bug-5.cpp -DBUG=1 gives an ICE (stack traces below) with a frequency of 60-70% -- might need to run it a few times to see. Defining BUG to > 0 and setting -fconcepts-diagnostics-depth to > 2 are required to reproduce. Version: g++ (GCC) 11.0.0 20200917 (experimental) Output from the compiler: dgorokho@desktop:~/Sources/Rete$ /home/dgorokho/gcc-trunk/trunk/dist/bin/g++ -std=c++20 -fconcepts-diagnostics-depth=25 -o bug-5.o -c bug-5.cpp -DBUG=1 bug-5.cpp:43:28: error: placeholder constraints not satisfied 43 | constexpr auto mmcc = m <cc> {}; | ^ bug-5.cpp:43:28: note: constraints not satisfied bug-5.cpp:18:9: required for the satisfaction of ‘P<pc>’ bug-5.cpp:18:13: in requirements with ‘T t’, ‘c<0, 1> v’ [with T = pc] bug-5.cpp:21:7: note: the required expression ‘t(v)’ is invalid, because 21 | { t (v) }; | ~~^~~ bug-5.cpp:21:7: error: no match for call to ‘(pc) (c<0, 1>&)’ bug-5.cpp:37:18: note: candidate: ‘template<class auto:2> requires C<auto:2> constexpr auto pc::operator()(auto:2) const’ 37 | constexpr auto operator () (C auto) const | ^~~~~~~~ bug-5.cpp:37:18: note: template argument deduction/substitution failed: bug-5.cpp:37:18: note: constraints not satisfied bug-5.cpp: In substitution of ‘template<class auto:2> requires C<auto:2> constexpr auto pc::operator()(auto:2) const [with auto:2 = c<0, 1>]’: bug-5.cpp:21:7: required from here bug-5.cpp:2:9: required for the satisfaction of ‘C<auto:2>’ [with auto:2 = c<0, 1>] bug-5.cpp:2:14: in requirements with ‘T t’ [with T = c<0, 1>] bug-5.cpp:6:3: note: nested requirement ‘((t.some_const < 2) || requires{t.some_fn();})’ is not satisfied, because 4 | requires t.some_const < 2 | ~~~~~~~~~~~~~~~~ 5 | #if BUG | ~~~~~~~ 6 | || requires { t.some_fn (); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hash table checking failed: equal operator returns true for a pair of values with a different hash value bug-5.cpp:4:12: internal compiler error: in hashtab_chk_error, at hash-table.c:137 4 | requires t.some_const < 2 | ~~~~~~~~~^~~~~~~~~~~~~~~~ 5 | #if BUG | ~~~~~~~ 6 | || requires { t.some_fn (); } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0x88c89a hashtab_chk_error() ../../src/gcc/hash-table.c:137 0x8f276c hash_table<sat_hasher, false, xcallocator>::verify(sat_entry* const&, unsigned int) ../../src/gcc/hash-table.h:1033 0x8f292b hash_table<sat_hasher, false, xcallocator>::find_with_hash(sat_entry* const&, unsigned int) ../../src/gcc/hash-table.h:918 0x8f0806 satisfy_constraint_r ../../src/gcc/hash-table.h:430 0x8f05c5 satisfy_constraint_r ../../src/gcc/cp/constraint.cc:2482 0x8f0db8 satisfy_constraint ../../src/gcc/cp/constraint.cc:2701 0x8f00b3 diagnose_nested_requirement ../../src/gcc/cp/constraint.cc:3413 0x8f00b3 diagnose_requirement ../../src/gcc/cp/constraint.cc:3433 0x8f00b3 diagnose_requires_expr ../../src/gcc/cp/constraint.cc:3457 0x8f00b3 diagnose_atomic_constraint ../../src/gcc/cp/constraint.cc:3493 0x8f0c58 satisfy_constraint_r ../../src/gcc/cp/constraint.cc:2652 0x8f0db8 satisfy_constraint ../../src/gcc/cp/constraint.cc:2701 0x8f20ed constraint_satisfaction_value ../../src/gcc/cp/constraint.cc:2719 0x8f2187 diagnose_constraints(unsigned int, tree_node*, tree_node*) ../../src/gcc/cp/constraint.cc:3563 0xa5196c 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.c:21317 0x8a1378 print_z_candidate ../../src/gcc/cp/call.c:3788 0x8a2e2f print_z_candidates ../../src/gcc/cp/call.c:3868 0x8b0713 build_op_call_1 ../../src/gcc/cp/call.c:4893 0x8b0713 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../src/gcc/cp/call.c:4929 0xa704ce finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) ../../src/gcc/cp/semantics.c:2724 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.