https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100737
Bug ID: 100737 Summary: g++ segfaults in template substitution Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: henrik.nortamo at csc dot fi Target Milestone: --- Created attachment 50860 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50860&action=edit version and configuration information for all the gcc versions for which the issue has been observed. The following code crashes g++, when compiled with g++ min.cpp min.cpp """ template<int v> using __bool_constant=int; template<class R> struct duration { static constexpr int fun() { return 0; } template<typename _Period2> using __is_harmonic = __bool_constant<(&duration::fun)()>; template <class _P2> static constexpr __is_harmonic<_P2> a=55; }; int main(){ duration<int> g; return g.a<int>; } """ Error produced is: """ min.cpp: In substitution of 'template<class R> template<class _Period2> using __is_harmonic = __bool_constant<duration<R>::fun()> [with _Period2 = _P2; R = R]': min.cpp:15:43: required from here min.cpp:13:43: internal compiler error: Segmentation fault 13 | = __bool_constant<(&duration::fun)()>; | ~~~~~~~~~~~~~~~~^~ 0xc5e1af crash_signal /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/toplev.c:328 0x783e05 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/semantics.c:2587 0x752672 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:20191 0x763de4 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:19274 0x763de4 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:18886 0x768926 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:13225 0x7562cd tsubst(tree_node*, tree_node*, int, tree_node*) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:15184 0x761c43 tsubst_decl /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:14641 0x76dff2 instantiate_template_1 /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:20947 0x756414 instantiate_template(tree_node*, tree_node*, int) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:21004 0x756414 instantiate_alias_template /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:21042 0x756414 tsubst(tree_node*, tree_node*, int, tree_node*) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:15185 0x76067f lookup_template_class_1 /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:9860 0x760d5c lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*, int, int) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/pt.c:10136 0x783a6d finish_template_type(tree_node*, tree_node*, int) /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/semantics.c:3408 0x72ad1f cp_parser_template_id /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/parser.c:16750 0x72af8c cp_parser_class_name /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/parser.c:23727 0x727c31 cp_parser_qualifying_entity /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/parser.c:6780 0x727c31 cp_parser_nested_name_specifier_opt /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/parser.c:6462 0x716d5a cp_parser_constructor_declarator_p /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/gcc/cp/parser.c:28683 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://github.com/spack/spack/issues> for instructions. """ compiling with -Wall -Wextra does not produce any additional output. In addition to version 10.3.0, same issue is also observed for gcc versions: 7.4.0, 8.3.0, 9.1.0 and 9.3.0 ( multiple different installation configurations for gcc 7.4.0 and 8.3.0 produce the same error ) icpc version 19.0.4.243, AMD clang 10.0.0 and AMD clang 12.0.0 compile the code without issues. I'm pasting here the compiler info for version 10.3.0 and attaching the info for the rest of the versions in a separate file. """ Reading specs from /appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx/lib/gcc/x86_64-pc-linux-gnu/10.3.0/specs COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx/libexec/gcc/x86_64-pc-linux-gnu/10.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /local_scratch/build/spack-stage/nortamoh/spack-stage-gcc-10.3.0-viumsxju75yhxz3ydlpn5vquya47elp7/spack-src/configure --prefix=/appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx --with-pkgversion='Spack GCC' --with-bugurl=https://github.com/spack/spack/issues --disable-multilib --enable-languages=c,c++,fortran --disable-nls --with-system-zlib --with-zstd=/appl/spack/v016/install-tree/gcc-4.8.5/zstd-1.4.5-gdikrw --with-gnu-ld --with-ld=/appl/spack/v016/install-tree/gcc-4.8.5/binutils-2.35.1-uylirb/bin/ld --with-gnu-as --with-as=/appl/spack/v016/install-tree/gcc-4.8.5/binutils-2.35.1-uylirb/bin/as --with-mpfr-include=/appl/spack/v016/install-tree/gcc-4.8.5/mpfr-4.0.2-ulc3sl/include --with-mpfr-lib=/appl/spack/v016/install-tree/gcc-4.8.5/mpfr-4.0.2-ulc3sl/lib --with-gmp-include=/appl/spack/v016/install-tree/gcc-4.8.5/gmp-6.1.2-5odxtl/include --with-gmp-lib=/appl/spack/v016/install-tree/gcc-4.8.5/gmp-6.1.2-5odxtl/lib --with-mpc-include=/appl/spack/v016/install-tree/gcc-4.8.5/mpc-1.1.0-23n6zj/include --with-mpc-lib=/appl/spack/v016/install-tree/gcc-4.8.5/mpc-1.1.0-23n6zj/lib --with-isl-include=/appl/spack/v016/install-tree/gcc-4.8.5/isl-0.21-loye6x/include --with-isl-lib=/appl/spack/v016/install-tree/gcc-4.8.5/isl-0.21-loye6x/lib --with-stage1-ldflags='-Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx/lib64 -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/gmp-6.1.2-5odxtl/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/mpfr-4.0.2-ulc3sl/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/mpc-1.1.0-23n6zj/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/isl-0.21-loye6x/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/zlib-1.2.11-vhzh5c/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/zstd-1.4.5-gdikrw/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/binutils-2.35.1-uylirb/lib' --with-boot-ldflags='-Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/gcc-10.3.0-viumsx/lib64 -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/gmp-6.1.2-5odxtl/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/mpfr-4.0.2-ulc3sl/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/mpc-1.1.0-23n6zj/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/isl-0.21-loye6x/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/zlib-1.2.11-vhzh5c/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/zstd-1.4.5-gdikrw/lib -Wl,-rpath,/appl/spack/v016/install-tree/gcc-4.8.5/binutils-2.35.1-uylirb/lib -static-libstdc++ -static-libgcc' Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.3.0 (Spack GCC) """ It can be noted that if "&duration::fun" is changed to "fun" the code compiles fine. Some additional context (not that relevant,mainly where the bug was encountered and impact) using <chrono> in a file which is compiled with nvcc (v 11.2.2) craches when gcc is the host compiler (due to g++ crashing with the above segfault). cudafe++ basically transforms "__bool_constant<(fun)()>;" -> "__bool_constant<(&duration::fun)()>;" before passing it on to gcc. The minial example is basically a very small and recuded part from <chrono>.