[Bug c++/126864] New: [-fcontracts] ICE in tsubst when postcondition references constexpr template function

dragon-archer at outlook dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126864

            Bug ID: 126864
           Summary: [-fcontracts] ICE in tsubst when postcondition
                    references constexpr template function
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dragon-archer at outlook dot com
  Target Milestone: ---

This was first reported to MSYS2 at
https://github.com/msys2/MINGW-packages/issues/31006. It wasn't able to
generate a bug report on MSYS2 (with both 16.1.0 and 16.2.0), but it can be
reproduced on Ubuntu with GCC 16.1.0. The generated bug report on Ubuntu is
pasted below.

contract.cpp:10:17: internal compiler error: in tsubst, at cp/pt.cc:17261
   10 |     post(i: i < bar<T>())
      |                 ^~~~~~
0x17e408f internal_error(char const*, ...)
        ../../src/gcc/diagnostic-global-context.cc:787
0x17e8b76 fancy_abort(char const*, int, char const*)
        ../../src/gcc/diagnostics/context.cc:1813
0xa522c7 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../src/gcc/cp/pt.cc:17261
0x1c35403 tsubst_template_arg(tree_node*, tree_node*, int, tree_node*)
        ../../src/gcc/cp/pt.cc:13312
0x1c35403 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ../../src/gcc/cp/pt.cc:14697
0x1c4d027 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../src/gcc/cp/pt.cc:21476
0x1c4c3d5 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../src/gcc/cp/pt.cc:22235
0x1c435b6 tsubst_expr(tree_node*, tree_node*, int, tree_node*) [clone
.constprop.3]
        ../../src/gcc/cp/pt.cc:21764
0x10e6582 rebuild_postconditions(tree_node*)
        ../../src/gcc/cp/contracts.cc:2007
0x87f19a grokfndecl
        ../../src/gcc/cp/decl.cc:12663
0x19a898a grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*,
decl_context, int, tree_node**)
        ../../src/gcc/cp/decl.cc:16938
0x19a66e9 start_function(cp_decl_specifier_seq*, cp_declarator const*,
tree_node*)
        ../../src/gcc/cp/decl.cc:20167
0x198fa4b cp_parser_function_definition_from_specifiers_and_declarator
        ../../src/gcc/cp/parser.cc:36031
0x198fa4b cp_parser_init_declarator
        ../../src/gcc/cp/parser.cc:26081
0x1b7f444 cp_parser_single_declaration
        ../../src/gcc/cp/parser.cc:36575
0x1b70e2c cp_parser_template_declaration_after_parameters
        ../../src/gcc/cp/parser.cc:36228
0x1b70e2c cp_parser_explicit_template_declaration
        ../../src/gcc/cp/parser.cc:36402
0x1980d7e cp_parser_declaration
        ../../src/gcc/cp/parser.cc:17632
0x2176259 cp_parser_toplevel_declaration
        ../../src/gcc/cp/parser.cc:17742
0x2176259 cp_parser_translation_unit
        ../../src/gcc/cp/parser.cc:5596
/usr/libexec/gcc/x86_64-linux-gnu/16/cc1plus -quiet -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE contract.cpp -quiet -dumpdir a- -dumpbase
contract.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64-v3 -fcontracts
-freport-bug -foffload-options=-l_GCC_stdc++ -foffload-options=-l_GCC_m
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection
-fzero-init-padding-bits=all -Wbidi-chars=any -o /tmp/ccrI2Q4D.s
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-16/README.Bugs> for instructions.
=== BEGIN GCC DUMP ===
601: // Target: x86_64-linux-gnu
601: // Configured with: ../src/configure -v --with-pkgversion='Ubuntu
16.1.0-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-16/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust,cobol,algol68
--prefix=/usr --with-gcc-major-version-only --program-suffix=-16
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-arch-64=x86-64-v3
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-16-nXyWBu/gcc-16-16.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-16-nXyWBu/gcc-16-16.1.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
601: // Thread model: posix
601: // Supported LTO compression algorithms: zlib zstd
601: // gcc version 16.1.0 (Ubuntu 16.1.0-2ubuntu1)
601: //
601: // contract.cpp:10:17: internal compiler error: in tsubst, at
cp/pt.cc:17261
601: //    10 |     post(i: i < bar<T>())
601: //       |                 ^~~~~~
601: // 0x17e408f internal_error(char const*, ...)
601: //         ../../src/gcc/diagnostic-global-context.cc:787
601: // 0x17e8b76 fancy_abort(char const*, int, char const*)
601: //         ../../src/gcc/diagnostics/context.cc:1813
601: // 0xa522c7 tsubst(tree_node*, tree_node*, int, tree_node*)
601: //         ../../src/gcc/cp/pt.cc:17261
601: // 0x1c35403 tsubst_template_arg(tree_node*, tree_node*, int, tree_node*)
601: //         ../../src/gcc/cp/pt.cc:13312
601: // 0x1c35403 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
601: //         ../../src/gcc/cp/pt.cc:14697
601: // 0x1c4d027 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
601: //         ../../src/gcc/cp/pt.cc:21476
601: // 0x1c4c3d5 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
601: //         ../../src/gcc/cp/pt.cc:22235
601: // 0x1c435b6 tsubst_expr(tree_node*, tree_node*, int, tree_node*) [clone
.constprop.3]
601: //         ../../src/gcc/cp/pt.cc:21764
601: // 0x10e6582 rebuild_postconditions(tree_node*)
601: //         ../../src/gcc/cp/contracts.cc:2007
601: // 0x87f19a grokfndecl
601: //         ../../src/gcc/cp/decl.cc:12663
601: // 0x19a898a grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*,
decl_context, int, tree_node**)
601: //         ../../src/gcc/cp/decl.cc:16938
601: // 0x19a66e9 start_function(cp_decl_specifier_seq*, cp_declarator const*,
tree_node*)
601: //         ../../src/gcc/cp/decl.cc:20167
601: // 0x198fa4b cp_parser_function_definition_from_specifiers_and_declarator
601: //         ../../src/gcc/cp/parser.cc:36031
601: // 0x198fa4b cp_parser_init_declarator
601: //         ../../src/gcc/cp/parser.cc:26081
601: // 0x1b7f444 cp_parser_single_declaration
601: //         ../../src/gcc/cp/parser.cc:36575
601: // 0x1b70e2c cp_parser_template_declaration_after_parameters
601: //         ../../src/gcc/cp/parser.cc:36228
601: // 0x1b70e2c cp_parser_explicit_template_declaration
601: //         ../../src/gcc/cp/parser.cc:36402
601: // 0x1980d7e cp_parser_declaration
601: //         ../../src/gcc/cp/parser.cc:17632
601: // 0x2176259 cp_parser_toplevel_declaration
601: //         ../../src/gcc/cp/parser.cc:17742
601: // 0x2176259 cp_parser_translation_unit
601: //         ../../src/gcc/cp/parser.cc:5596
601: // -quiet -imultiarch x86_64-linux-gnu -D_GNU_SOURCE contract.cpp -quiet
-dumpdir a- -dumpbase contract.cpp -dumpbase-ext .cpp -mtune=generic
-march=x86-64-v3 -fcontracts -freport-bug -foffload-options=-l_GCC_stdc++
-foffload-options=-l_GCC_m -fasynchronous-unwind-tables
-fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection
-fcf-protection -fzero-init-padding-bits=all -Wbidi-chars=any -o -
-frandom-seed=0 -fdump-noaddr
601: // Please submit a full bug report, with preprocessed source.
601: // Please include the complete backtrace with any bug report.
601: // See <file:///usr/share/doc/gcc-16/README.Bugs> for instructions.
601:
601: // /usr/libexec/gcc/x86_64-linux-gnu/16/cc1plus -quiet -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE contract.cpp -quiet -dumpdir a- -dumpbase
contract.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64-v3 -fcontracts
-freport-bug -foffload-options=-l_GCC_stdc++ -foffload-options=-l_GCC_m
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection
-fzero-init-padding-bits=all -Wbidi-chars=any -o - -frandom-seed=0
-fdump-noaddr
601:
601: # 0 "contract.cpp"
601: # 0 "<built-in>"
601: # 0 "<command-line>"
601: # 1 "/usr/include/stdc-predef.h" 1 3
601: # 0 "<command-line>" 2
601: # 1 "contract.cpp"
601:
601: template <typename T>
601: constexpr int bar()
601: {
601:     return 1;
601: }
601:
601: template <typename T>
601: constexpr int foo()
601:     post(i: i < bar<T>())
601: {
601:     return 0;
601: }
601:
601: int main() {
601:     return 0;
601: }
=== END GCC DUMP ===

Not sure whether this is a duplicate of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125011.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.