Bug 82360 - [8 Regression] tree check fail in get_inner_reference, at expr.c:6996
Summary: [8 Regression] tree check fail in get_inner_reference, at expr.c:6996
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 82766 82780 82822 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-09-29 11:50 UTC by David Binderman
Modified: 2017-12-04 13:12 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.2.1
Known to fail:
Last reconfirmed: 2017-10-02 00:00:00


Attachments
gzipped C++ source code (820.92 KB, application/gzip)
2017-09-29 11:50 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2017-09-29 11:50:11 UTC
Created attachment 42260 [details]
gzipped C++ source code

The attached c++ code, when compiled by today's trunk gcc, does this:

/usr/include/boost/smart_ptr/weak_ptr.hpp:109:82: internal compiler error: tree 
check: expected tree that contains ‘decl common’ structure, have ‘identifier_nod
e’ in get_inner_reference, at expr.c:6996
     BOOST_NOEXCEPT : px( r.px ), pn( static_cast< boost::detail::weak_count && 
>( r.pn ) )

The problem seems to exist between versions 253249 and 253276.

I'll have a go at reducing the code.
Comment 1 David Binderman 2017-09-29 12:30:37 UTC
I don't think this is still C++ code, but it 
does seem to provoke the error:

class a {
} template <b> class c {          c(c &&e) : (static_cast a && e.d;          a d
Comment 2 David Binderman 2017-09-29 14:13:27 UTC
Here is a possibly better example, that is legal C++ code:

class a {};
template <class> class b {
  b(b &&c) : d(static_cast<a &&>(c.d)) {}
  a d;
};
Comment 3 Richard Biener 2017-10-02 08:06:40 UTC
Confirmed.

> ./cc1plus  -quiet t.ii
t.ii: In constructor ‘b< <template-parameter-1-1> >::b(b< <template-parameter-1-1> >&&)’:
t.ii:3:37: internal compiler error: tree check: expected tree that contains ‘decl common’ structure, have ‘identifier_node’ in get_inner_reference, at expr.c:6996
   b(b &&c) : d(static_cast<a &&>(c.d)) {}
                                     ^
0x155dde4 tree_contains_struct_check_failed(tree_node const*, tree_node_structure_enum, char const*, int, char const*)
        /tmp/trunk2/gcc/tree.c:9254
0x7ff44f contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*)
        /tmp/trunk2/gcc/tree.h:3218
0xd8ff31 get_inner_reference(tree_node*, long*, long*, tree_node**, machine_mode*, int*, int*, int*)
        /tmp/trunk2/gcc/expr.c:6996
0xdd1d04 fold_unary_loc(unsigned int, tree_code, tree_node*, tree_node*)
        /tmp/trunk2/gcc/fold-const.c:7726
0xde70dd fold_build1_loc(unsigned int, tree_code, tree_node*, tree_node*)
        /tmp/trunk2/gcc/fold-const.c:12226
0xdbce9f fold_convert_loc(unsigned int, tree_node*, tree_node*)
        /tmp/trunk2/gcc/fold-const.c:2257
0x8a3306 cp_fold_convert(tree_node*, tree_node*)
        /tmp/trunk2/gcc/cp/cvt.c:607
0xb0019a build_static_cast_1
        /tmp/trunk2/gcc/cp/typeck.c:6852
0xb012f9 build_static_cast(tree_node*, tree_node*, int)
        /tmp/trunk2/gcc/cp/typeck.c:7079
0x9aec22 cp_parser_postfix_expression
        /tmp/trunk2/gcc/cp/parser.c:6584
0x9b31a3 cp_parser_unary_expression
        /tmp/trunk2/gcc/cp/parser.c:8251
0x9b428a cp_parser_cast_expression
        /tmp/trunk2/gcc/cp/parser.c:9019
Comment 4 David Binderman 2017-10-05 09:40:04 UTC
Possibly in the same area, I just tried a valgrind build of trunk gcc and
got this:

==4967== Invalid read of size 8
==4967==    at 0xD87FD8: component_ref_field_offset(tree_node*) (tree.c:12600)
==4967==    by 0x9786EB: get_inner_reference(tree_node*, long*, long*, tree_node**, machine_mode*, int*, int*, int*) (expr.c:7059)
==4967==    by 0x9A9C6E: fold_unary_loc(unsigned int, tree_code, tree_node*, tree_node*) (fold-const.c:7724)
==4967==    by 0x9AA0D9: fold_build1_loc(unsigned int, tree_code, tree_node*, tree_node*) (fold-const.c:12226)
Comment 5 Tobias Burnus 2017-10-09 09:39:26 UTC
[Still occurs with today's Rev. 253536.]

Bisecting (for comment 2) points to:

https://gcc.gnu.org/viewcvs?rev=253266&root=gcc&view=rev
commit 4cedc476c94a41551d965bc57fbbe0186983c3c4

Author: jason
Date:   Thu Sep 28 19:39:45 2017 +0000

            PR c++/56973, DR 696 - capture constant variables only as needed.

            * expr.c (mark_use): Split out from mark_rvalue_use and
            mark_lvalue_use.  Handle lambda capture of constant variables.
            (mark_lvalue_use_nonread): New.
            * semantics.c (process_outer_var_ref): Don't capture a constant
            variable until forced.
            * pt.c (processing_nonlambda_template): New.
            * call.c (build_this): Check it.
            * decl2.c (grok_array_decl): Call mark_rvalue_use and
            mark_lvalue_use_nonread.
            * init.c (constant_value_1): Don't call mark_rvalue_use.
            * typeck.c (build_static_cast): Handle lambda capture.

    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253266 138bc75d-0d04-0410-961f-82ee72b054a4
Comment 6 Markus Trippelsdorf 2017-10-30 12:57:02 UTC
*** Bug 82766 has been marked as a duplicate of this bug. ***
Comment 7 Markus Trippelsdorf 2017-10-31 09:45:06 UTC
*** Bug 82780 has been marked as a duplicate of this bug. ***
Comment 8 Martin Liška 2017-11-03 11:52:36 UTC
*** Bug 82822 has been marked as a duplicate of this bug. ***
Comment 9 Jason Merrill 2017-11-13 21:49:47 UTC
Author: jason
Date: Mon Nov 13 21:49:16 2017
New Revision: 254710

URL: https://gcc.gnu.org/viewcvs?rev=254710&root=gcc&view=rev
Log:
	PR c++/82360 - ICE with static_cast in template.

	* call.c (perform_direct_initialization_if_possible): Check
	processing_template_decl.
	* typeck.c (build_static_cast_1): Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/template/cast5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/typeck.c
Comment 10 Jason Merrill 2017-11-13 22:35:00 UTC
Fixed.
Comment 11 Eric Gallager 2017-12-04 13:12:19 UTC
(In reply to Jason Merrill from comment #9)
> Author: jason
> Date: Mon Nov 13 21:49:16 2017
> New Revision: 254710
> 
> URL: https://gcc.gnu.org/viewcvs?rev=254710&root=gcc&view=rev
> Log:
> 	PR c++/82360 - ICE with static_cast in template.
> 
> 	* call.c (perform_direct_initialization_if_possible): Check
> 	processing_template_decl.
> 	* typeck.c (build_static_cast_1): Likewise.
> 
> Added:
>     trunk/gcc/testsuite/g++.dg/template/cast5.C
> Modified:
>     trunk/gcc/cp/ChangeLog
>     trunk/gcc/cp/call.c
>     trunk/gcc/cp/typeck.c

Aw, my latest gcc was built just 2 days before this... guess I'll have to rebuild...