Bug 96805 - [10 Regression] ICE: Segmentation fault in instantiate_template / pop_nested_class()
Summary: [10 Regression] ICE: Segmentation fault in instantiate_template / pop_nested_...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.1
: P2 normal
Target Milestone: 10.3
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
: 96732 96819 96872 97293 99550 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-08-26 19:10 UTC by Marc Mutz
Modified: 2021-12-15 01:31 UTC (History)
11 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.0
Known to fail: 10.2.0
Last reconfirmed: 2020-08-26 00:00:00


Attachments
BZ2-compressed preprocessed source (367.44 KB, application/x-bzip)
2020-08-26 19:10 UTC, Marc Mutz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Mutz 2020-08-26 19:10:48 UTC
Created attachment 49134 [details]
BZ2-compressed preprocessed source

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96732 looks similar, but this is on 10.2, not 11...

$ g++ -E -pipe -O2 -fPIC -std=c++2a -fvisibility=hidden -fvisibility-inlines-hidden -ffunction-sections -fdata-sections -fno-exceptions -Wall -Wextra -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-format-overflow -Wsuggest-override -D_REENTRANT -DQT_NO_JAVA_STYLE_ITERATORS -DPCRE2_DISABLE_JIT -DHAVE_CONFIG_H -DQT_VERSION_STR='"6.0.0"' -DQT_VERSION_MAJOR=6 -DQT_VERSION_MINOR=0 -DQT_VERSION_PATCH=0 -DQT_BOOTSTRAPPED -DQT_NO_CAST_TO_ASCII -DPCRE2_CODE_UNIT_WIDTH=16 -DQT_NO_FOREACH -DQT_NO_CAST_FROM_ASCII -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_BUILD_BOOTSTRAP_LIB -DQT_BUILDING_QT -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -DQT_DEPRECATED_WARNINGS_SINCE=0x060000 -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -I/home/marc/Qt/qtbase/src/tools/bootstrap -I. -I/home/marc/Qt/qtbase/src/tools -I/home/marc/Qt/qtbase/src/3rdparty/tinycbor/src -I/home/marc/Qt/qtbase/src/3rdparty/pcre2/src -I../../../include -I../../../include/QtCore -I../../../include/QtCore/6.0.0 -I../../../include/QtCore/6.0.0/QtCore -I../../../include/QtXml -I../../../include/QtXml/6.0.0 -I../../../include/QtXml/6.0.0/QtXml -I/home/marc/Qt/qtbase/mkspecs/linux-g++ -o qendian.ii /home/marc/Qt/qtbase/src/corelib/global/qendian.cpp
../../../include/QtCore/../../../qtbase/src/corelib/tools/qarraydataops.h:102:77: internal compiler error: Segmentation fault
  102 |             noexcept(std::is_nothrow_constructible_v<T, iterator_copy_value<ForwardIt>>)
      |                                                                             ^~~~~~~~~
0xc2ee1f crash_signal
        ../../gcc/gcc/toplev.c:328
0x6280c5 pop_nested_class()
        ../../gcc/gcc/cp/class.c:8184
0x738747 instantiate_template_1
        ../../gcc/gcc/cp/pt.c:20853
0x733694 instantiate_template(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/pt.c:20908
0x733694 instantiate_alias_template
        ../../gcc/gcc/cp/pt.c:20946
0x733694 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.c:15147
0x739b0f lookup_template_class_1
        ../../gcc/gcc/cp/pt.c:9853
0x73a1ec lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*, int, int)
        ../../gcc/gcc/cp/pt.c:10119
0x756b3d finish_template_type(tree_node*, tree_node*, int)
        ../../gcc/gcc/cp/semantics.c:3408
0x6fe15d cp_parser_template_id
        ../../gcc/gcc/cp/parser.c:16739
0x6fe3cc cp_parser_class_name
        ../../gcc/gcc/cp/parser.c:23713
0x6fb101 cp_parser_qualifying_entity
        ../../gcc/gcc/cp/parser.c:6776
0x6fb101 cp_parser_nested_name_specifier_opt
        ../../gcc/gcc/cp/parser.c:6458
0x702706 cp_parser_simple_type_specifier
        ../../gcc/gcc/cp/parser.c:18134
0x6e93ed cp_parser_type_specifier
        ../../gcc/gcc/cp/parser.c:17792
0x6fc9a9 cp_parser_type_specifier_seq
        ../../gcc/gcc/cp/parser.c:22402
0x6f6f34 cp_parser_type_id_1
        ../../gcc/gcc/cp/parser.c:22219
0x6f9473 cp_parser_template_type_arg
        ../../gcc/gcc/cp/parser.c:22310
0x6fcb2f cp_parser_template_argument
        ../../gcc/gcc/cp/parser.c:17189
0x6fcb2f cp_parser_template_argument_list
        ../../gcc/gcc/cp/parser.c:17100
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.
Comment 1 Marc Mutz 2020-08-26 19:11:47 UTC
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/d/gcc/10/libexec/gcc/x86_64-pc-linux-gnu/10.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/d/gcc/10 --enable-languages=c,c++,fortran,lto,objc --no-create --no-recursion : (reconfigured) ../gcc/configure --prefix=/d/gcc/10 --enable-languages=c,c++,fortran,lto,objc --no-create --no-recursion
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20200824 (GCC)
Comment 2 Marc Mutz 2020-08-26 19:29:06 UTC
also in gcc version 10.2.1 20200826 (GCC)
Comment 3 Marek Polacek 2020-08-26 19:40:01 UTC
Confirmed.  Seems like this one started with r11-2747 instead.
Comment 4 Martin Liška 2020-08-27 10:33:48 UTC
Reduced test-case:

$ cat qendian.ii
template <typename> bool is_nothrow_constructible_v;
template <typename> struct QArrayExceptionSafetyPrimitives {
  struct {
    template <typename> using iterator_move_value = decltype(0);
    template <typename ForwardIt>
    void
    move() noexcept(is_nothrow_constructible_v<iterator_move_value<ForwardIt>>);
  };
};
Comment 5 Jonathan Wakely 2020-08-27 16:00:58 UTC
*** Bug 96819 has been marked as a duplicate of this bug. ***
Comment 6 Patrick Palka 2020-08-27 19:37:33 UTC
*** Bug 96732 has been marked as a duplicate of this bug. ***
Comment 7 Marek Polacek 2020-08-31 21:57:56 UTC
*** Bug 96872 has been marked as a duplicate of this bug. ***
Comment 8 Marek Polacek 2020-10-05 14:36:21 UTC
*** Bug 97293 has been marked as a duplicate of this bug. ***
Comment 9 David Binderman 2020-10-05 16:56:38 UTC
I see no progress on this bug for over a month now.
I'd be happy to help with testing. 

Perhaps Jason is best placed to make progress on this bug.
Comment 10 Patrick Palka 2020-10-07 20:33:10 UTC
Here's a more condensed testcase (accepted with -std=c++11/14, ICEs with -std=c++17/20):

template <typename> class a {
  template <int b> struct c {
    template <bool> using t = int;
    t<b> m;
  };
};
Comment 11 GCC Commits 2020-10-08 20:54:17 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:1c56c143b2011080d8a4516f37f78f647b0ee258

commit r11-3738-g1c56c143b2011080d8a4516f37f78f647b0ee258
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Oct 8 15:43:26 2020 -0400

    c++: Fix member alias template in C++17 and up. [PR96805]
    
    Here we're trying to push into a<T>::c<N> in order to instantiate t<N>, but
    were building a TYPENAME_TYPE for it because a<T> isn't open yet.  Don't
    do that when we know we're trying to enter the scope.
    
    gcc/cp/ChangeLog:
    
            PR c++/96805
            PR c++/96199
            * pt.c (tsubst_aggr_type): Don't build a TYPENAME_TYPE when
            entering_scope.
            (tsubst_template_decl): Use tsubst_aggr_type.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/96805
            * g++.dg/cpp0x/alias-decl-pr96805.C: New test.
Comment 12 Richard Biener 2020-10-12 12:28:27 UTC
Fixed on trunk(?)
Comment 13 GCC Commits 2020-11-24 17:54:55 UTC
The releases/gcc-10 branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:e89ebd3e896f27d4afc400044d5a2b69cb524bcb

commit r10-9069-ge89ebd3e896f27d4afc400044d5a2b69cb524bcb
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Oct 8 15:43:26 2020 -0400

    c++: Fix member alias template in C++17 and up. [PR96805]
    
    Here we're trying to push into a<T>::c<N> in order to instantiate t<N>, but
    were building a TYPENAME_TYPE for it because a<T> isn't open yet.  Don't
    do that when we know we're trying to enter the scope.
    
    gcc/cp/ChangeLog:
    
            PR c++/96805
            PR c++/96199
            * pt.c (tsubst_aggr_type): Don't build a TYPENAME_TYPE when
            entering_scope.
            (tsubst_template_decl): Use tsubst_aggr_type.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/96805
            * g++.dg/cpp0x/alias-decl-pr96805.C: New test.
Comment 14 Jason Merrill 2020-11-24 20:55:47 UTC
Fixed.
Comment 15 Andrew Pinski 2021-12-15 01:31:34 UTC
*** Bug 99550 has been marked as a duplicate of this bug. ***