https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103912
Bug ID: 103912
Summary: ICE in a consteval function in cp_gimplify_expr, at
cp/cp-gimplify.c:557
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 0xd34df00d at gmail dot com
Target Milestone: ---
This program:
#include <string_view>
namespace
{
constexpr uint64_t CalcHash (std::string_view name)
{
return 0;
}
template<typename T>
struct Command
{
const uint64_t Hash_;
const T Cmd_;
consteval Command (std::string_view name, T cmd)
: Hash_ { CalcHash (name) }
, Cmd_ { cmd }
{
}
};
template<typename T>
consteval auto MakeHash (auto&&... commands)
{
const std::initializer_list<Command<T>> commandsList { commands... };
for (auto i = commandsList.begin (); i != std::prev (commandsList.end
()); ++i)
for (auto j = std::next (i); j != commandsList.end (); ++j)
if (i->Hash_ == j->Hash_)
throw "duplicate hashes";
return [=] (std::string_view str)
{
const auto strHash = CalcHash (str);
T result {};
((commands.Hash_ == strHash && (result = commands.Cmd_)) || ...);
return result;
};
}
}
struct Foo
{
int foo1(int x) { return x * 1; }
};
int bar(std::string_view arg)
{
constexpr auto hash = MakeHash<int (Foo::*) (int)> (Command { "foo1",
&Foo::foo1 });
Foo f {};
auto res = hash(arg);
return (f.*res)(42);
}
compiled with -std=c++20 (as in g++ -std=c++20 foo.cpp -o foo.o) results in
foo.cpp: In function 'consteval auto {anonymous}::MakeHash(auto:11&& ...) [with
T = int (Foo::*)(int); auto:11 = {{anonymous}::Command<int (Foo::*)(int)>}]':
foo.cpp:27:17: internal compiler error: in cp_gimplify_expr, at
cp/cp-gimplify.c:557
27 | for (auto i = commandsList.begin (); i != std::prev
(commandsList.end ()); ++i)
| ^~~
0x164bc1d internal_error(char const*, ...)
???:0
0x604ee1 fancy_abort(char const*, int, char const*)
???:0
0xa7662b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xa77265 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xa7734c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xa77265 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xa7734c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xa85bd4 gimplify_body(tree_node*, bool)
???:0
0xa8611e gimplify_function_tree(tree_node*)
???:0
0x8fd5ab cgraph_node::analyze()
???:0
0x903af3 symbol_table::finalize_compilation_unit()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
This reproduces both with gcc 11.1.0 and 11.2.1:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/11.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-11.2.1_p20211127/work/gcc-11-20211127/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/11.2.1
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.1
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.1/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.1/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/11.2.1/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--disable-libunwind-exceptions --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo
11.2.1_p20211127 p3' --disable-esp --enable-libstdcxx-time
--with-build-config=bootstrap-lto --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --enable-multilib
--with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all
--enable-libgomp --disable-libssp --disable-libada --disable-cet
--disable-systemtap --disable-valgrind-annotations --disable-vtable-verify
--disable-libvtv --without-zstd --enable-lto --with-isl
--disable-isl-version-check --disable-default-pie --enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20211127 (Gentoo 11.2.1_p20211127 p3)