[Bug c++/71832] New: ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] New: ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

            Bug ID: 71832
           Summary: ICE on invalid C++11 code with incorrect decltype use
                    for non-type template parameter: Segmentation fault
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

The following C++11 code causes an ICE when compiled with the current GCC trunk
on x86_64-linux-gnu in both 32-bit and 64-bit modes.  

This is a regression from 6.1.x.


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20160710 (experimental) [trunk revision 238196] (GCC)
$
$ g++-6.1 -c small.cpp
small.cpp:2:21: error: expected nested-name-specifier before ‘decltype’
 template < typename decltype (0) > struct A
                     ^~~~~~~~
small.cpp:2:21: error: two or more data types in declaration of ‘parameter’
$
$ g++-trunk -c small.cpp
small.cpp:2:21: error: expected nested-name-specifier before ‘decltype’
 template < typename decltype (0) > struct A
                     ^~~~~~~~
small.cpp:2:21: error: two or more data types in declaration of ‘parameter’
small.cpp: In substitution of ‘template<<declaration error> > template<class
... S> void A<<declaration error> >::baz() [with S = <missing>; <declaration
error> = {}]’:
small.cpp:4:22:   required from here
small.cpp:4:22: internal compiler error: Segmentation fault
   void foo () { baz (); }
                      ^
0xdbae6f crash_signal
        ../../gcc-source-trunk/gcc/toplev.c:335
0x73d863 tree_class_check
        ../../gcc-source-trunk/gcc/tree.h:3152
0x73d863 pop_nested_class()
        ../../gcc-source-trunk/gcc/cp/class.c:7785
0x702980 instantiate_template_1
        ../../gcc-source-trunk/gcc/cp/pt.c:17485
0x702980 instantiate_template(tree_node*, tree_node*, int)
        ../../gcc-source-trunk/gcc/cp/pt.c:17534
0x71439c fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, bool, bool)
        ../../gcc-source-trunk/gcc/cp/pt.c:17909
0x6746fb add_template_candidate_real
        ../../gcc-source-trunk/gcc/cp/call.c:3113
0x67542c add_template_candidate
        ../../gcc-source-trunk/gcc/cp/call.c:3191
0x67542c add_candidates
        ../../gcc-source-trunk/gcc/cp/call.c:5363
0x675cc6 build_new_method_call_1
        ../../gcc-source-trunk/gcc/cp/call.c:8391
0x675cc6 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
        ../../gcc-source-trunk/gcc/cp/call.c:8590
0x791ef3 cp_parser_postfix_expression
        ../../gcc-source-trunk/gcc/cp/parser.c:6880
0x79a68c cp_parser_unary_expression
        ../../gcc-source-trunk/gcc/cp/parser.c:7991
0x79aee7 cp_parser_cast_expression
        ../../gcc-source-trunk/gcc/cp/parser.c:8668
0x79b4e5 cp_parser_binary_expression
        ../../gcc-source-trunk/gcc/cp/parser.c:8770
0x79bdd0 cp_parser_assignment_expression
        ../../gcc-source-trunk/gcc/cp/parser.c:9058
0x79e6c9 cp_parser_expression
        ../../gcc-source-trunk/gcc/cp/parser.c:9225
0x79ee3f cp_parser_expression_statement
        ../../gcc-source-trunk/gcc/cp/parser.c:10686
0x78cc7b cp_parser_statement
        ../../gcc-source-trunk/gcc/cp/parser.c:10537
0x78d93c cp_parser_statement_seq_opt
        ../../gcc-source-trunk/gcc/cp/parser.c:10809
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$


----------------------------------------------------


// should be: template < decltype (0) > struct A
template < typename decltype (0) > struct A
{
  void foo () { baz (); }
  template < typename ... S > void baz () {};
};
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-07-11
                 CC|                            |marxin at gcc dot gnu.org
            Summary|ICE on invalid C++11 code   |[7 Regression] ICE on
                   |with incorrect decltype use |invalid C++11 code with
                   |for non-type template       |incorrect decltype use for
                   |parameter: Segmentation     |non-type template
                   |fault                       |parameter: Segmentation
                   |                            |fault
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started to ICE from r236221.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |7.0
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |error-recovery
           Priority|P3                          |P4
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.0                         |7.2

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 7.1 has been released.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.2                         |7.3

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.2 is being released, adjusting target milestone.

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.2 is being released, adjusting target milestone.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.2                         |7.3

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.2 is being released, adjusting target milestone.

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.2 is being released, adjusting target milestone.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.2                         |7.3
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Related to PR71169.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.3                         |7.4

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.3 is being released, adjusting target milestone.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo.carlini at oracle dot com

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Avoiding the ICE seems easy, something like the below but the diagnostic we
produce is way too redundant. I believe that in such cases we should skip
completely the body of the template (A).

Index: class.c
===================================================================
--- class.c     (revision 258250)
+++ class.c     (working copy)
@@ -7568,6 +7568,9 @@ push_nested_class (tree type)
 void
 pop_nested_class (void)
 {
+  if (!current_class_type)
+    return;
+
   tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));

   popclass ();
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|paolo.carlini at oracle dot com    |
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Mine.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Skipping completely the body works for this testcase, isn't that difficult to
do, but goes too far, the template completely disappears and we end up with bad
error recovery for anything referring to it afterwards. Probably, a better
approximation would be skipping the *instantiations* of the body.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Another idea - which appears to work great! - is skipping the bodies of the
member function definitions. If everything goes well I'll send soon a draft
patch.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7/8 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

--- Comment #9 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Fri Mar  9 23:03:06 2018
New Revision: 258401

URL: https://gcc.gnu.org/viewcvs?rev=258401&root=gcc&view=rev
Log:
/cp
2018-03-09  Jason Merrill  <[hidden email]>
            Paolo Carlini  <[hidden email]>

        PR c++/71169
        PR c++/71832
        * pt.c (any_erroneous_template_args_p): New.
        * cp-tree.h (any_erroneous_template_args_p): Declare it.
        * parser.c (cp_parser_class_specifier_1): Use it.

/testsuite
2018-03-09  Jason Merrill  <[hidden email]>
            Paolo Carlini  <[hidden email]>

        PR c++/71169
        PR c++/71832
        * g++.dg/cpp0x/pr71169.C: New.
        * g++.dg/cpp0x/pr71169-2.C: Likewise.
        * g++.dg/cpp0x/pr71832.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr71169-2.C
    trunk/gcc/testsuite/g++.dg/cpp0x/pr71169.C
    trunk/gcc/testsuite/g++.dg/cpp0x/pr71832.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[7/8 Regression] ICE on     |[7 Regression] ICE on
                   |invalid C++11 code with     |invalid C++11 code with
                   |incorrect decltype use for  |incorrect decltype use for
                   |non-type template           |non-type template
                   |parameter: Segmentation     |parameter: Segmentation
                   |fault                       |fault

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed in trunk.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.4                         |7.5
Reply | Threaded
Open this post in threaded view
|

[Bug c++/71832] [7 Regression] ICE on invalid C++11 code with incorrect decltype use for non-type template parameter: Segmentation fault

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71832

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|                            |8.0
         Resolution|---                         |FIXED
   Target Milestone|7.5                         |8.0
      Known to fail|                            |7.5.0

--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in GCC8.