Hello,
as I mentioned yesterday on IRC adding a check that only complete types
have TYPE_BINFO defined triggers on type:

 <record_type 0x7ffff6d24d20 __is_integer type_5 type_6 VOID
    align 8 symtab 0 alias set -1 canonical type 0x7ffff6d24d20
    fields <const_decl 0x7ffff4a89930 __value
        type <enumeral_type 0x7ffff6d260a8 ._8 type <integer_type 
0x7ffff6d261f8 unsigned int>
            unsigned SI
            size <integer_cst 0x7ffff6d0e0a8 constant 32>
            unit size <integer_cst 0x7ffff6d0e0c0 constant 4>
            align 32 symtab 0 alias set -1 canonical type 0x7ffff6d260a8 
precision 32 min <integer_cst 0x7ffff6d0e0d8 0> max <integer_cst 0x7ffff6d0e090 
4294967295>
            values <tree_list 0x7ffff6d2e078
                purpose <identifier_node 0x7ffff6ea9c08 __value
                    bindings <(nil)>
                    local bindings <0x7ffff6d2a640>> value <const_decl 
0x7ffff4a89930 __value>> context <record_type 0x7ffff6d24d20 __is_integer>
            chain <type_decl 0x7ffff4aa4da8 ._8>>
        readonly constant VOID file 
/aux/hubicka/trunk-7/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/cpp_type_traits.h
 line 127 col 14
        align 1 context <enumeral_type 0x7ffff6d260a8 ._8> initial <integer_cst 
0x7ffff6eea1c8 0>
        chain <type_decl 0x7ffff4aa4a18 __is_integer type <record_type 
0x7ffff6d24dc8 __is_integer>
            external nonlocal in_system_header suppress-debug decl_4 VOID file 
/aux/hubicka/trunk-7/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/cpp_type_traits.h
 line 126 col 5
            align 8 context <record_type 0x7ffff6d24d20 __is_integer> result 
<record_type 0x7ffff6d24d20 __is_integer>
            chain <type_decl 0x7ffff4aa4da8 ._8>>> context <namespace_decl 
0x7ffff6d08098 std>
    full-name "struct std::__is_integer<long double>"
    n_parents=0 use_template=1 interface-unknown
    chain <type_decl 0x7ffff4aa4688 __is_integer>>

This type has fields but no TYPE_SIZE, so it seems odd.  It is an instance, not 
template,
so I think the probablem is that layout_type was not called on it.

I debugged the reason why we get type with to TYPE_SIZE but with BINFO.  The
problem is that dwarf2out is visits this type before it is finished.  The BINFO
is added as:

#0  xref_basetypes (ref=0x7ffff6d24d20, base_list=0x0) at 
../../gcc/cp/decl.c:12525
#1  0x000000000078b786 in instantiate_class_template_1 (type=0x7ffff6d24d20) at 
../../gcc/cp/pt.c:9256
#2  0x000000000078d3e7 in instantiate_class_template (type=0x7ffff6d24d20) at 
../../gcc/cp/pt.c:9650
#3  0x000000000088772c in complete_type (type=0x7ffff6d24d20) at 
../../gcc/cp/typeck.c:146
#4  0x00000000008dba41 in lookup_member (xbasetype=0x0, name=0x7ffff6ea9c08, 
protect=2, want_type=false, complain=3) at ../../gcc/cp/search.c:1213
#5  0x00000000009544db in lookup_qualified_name (scope=0x7ffff6d24d20, 
name=0x7ffff6ea9c08, is_type_p=false, complain=false) at 
../../gcc/cp/name-lookup.c:4540
#6  0x000000000079ca43 in tsubst_qualified_id (qualified_id=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00, done=true, 
address_p=false) at ../../gcc/cp/pt.c:12717
#7  0x00000000007a80df in tsubst_copy_and_build (t=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00, function_p=false, 
integral_constant_expression_p=true)
    at ../../gcc/cp/pt.c:14760
#8  0x00000000007a67b4 in tsubst_expr (t=0x7ffff6d2a4d8, args=0x7ffff6d2caf0, 
complain=3, in_decl=0x7ffff4ac9a00, integral_constant_expression_p=true) at 
../../gcc/cp/pt.c:14367
#9  0x000000000078d491 in tsubst_template_arg (t=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00) at 
../../gcc/cp/pt.c:9669
#10 0x000000000077f3ca in coerce_template_parms (parms=0x7ffff6d2a550, 
args=0x7ffff6e83960, in_decl=0x7ffff4ac9a00, complain=3, require_all_args=true, 
use_default_args=true)
    at ../../gcc/cp/pt.c:7142
#11 0x000000000077fa17 in coerce_innermost_template_parms 
(parms=0x7ffff6d2a578, args=0x7ffff6e83960, in_decl=0x7ffff4ac9a00, complain=3, 
require_all_args=true, use_default_args=true)
    at ../../gcc/cp/pt.c:7252
#12 0x0000000000782455 in lookup_template_class_1 (d1=0x7ffff6eab6e0, 
arglist=0x7ffff6e83960, in_decl=0x0, context=0x7ffff6e5bed8, entering_scope=0, 
complain=3) at ../../gcc/cp/pt.c:7727
#13 0x00000000007854e4 in lookup_template_class (d1=0x7ffff4ac9a00, 
arglist=0x7ffff6e83960, in_decl=0x0, context=0x0, entering_scope=0, 
complain=35) at ../../gcc/cp/pt.c:8043
#14 0x00000000008eaefe in finish_template_type (name=0x7ffff4ac9a00, 
args=0x7ffff6e83960, entering_scope=0) at ../../gcc/cp/semantics.c:3011
#15 0x000000000084c7a4 in cp_parser_template_id (parser=0x7ffff6be8c00, 
template_keyword_p=false, check_dependency_p=false, tag_type=class_type, 
is_declaration=false)
    at ../../gcc/cp/parser.c:13850

and dwarf2out visits it as context when processing another type:

#0  error (gmsgid=0x1abd1a8 "TYPE_BINFO and COMPLETE_TYPE_P mismatch") at 
../../gcc/diagnostic.c:1135
#1  0x00000000012f64c7 in verify_type (t=0x7ffff6d24d20) at 
../../gcc/tree.c:12818
#2  0x0000000000b5a8f6 in gen_type_die_with_usage (type=0x7ffff6d24d20, 
context_die=0x7ffff6d16000, usage=DINFO_USAGE_DIR_USE) at 
../../gcc/dwarf2out.c:20250
#3  0x0000000000b5a6d6 in gen_tagged_type_die (type=0x7ffff6d260a8, 
context_die=0x7ffff6d16000, usage=DINFO_USAGE_DIR_USE) at 
../../gcc/dwarf2out.c:20190
#4  0x0000000000b5afc2 in gen_type_die_with_usage (type=0x7ffff6d260a8, 
context_die=0x7ffff6d16000, usage=DINFO_USAGE_DIR_USE) at 
../../gcc/dwarf2out.c:20381
#5  0x0000000000b5b32d in gen_type_die (type=0x7ffff6d260a8, 
context_die=0x7ffff6d16000) at ../../gcc/dwarf2out.c:20434
#6  0x0000000000b5d061 in gen_decl_die (decl=0x7ffff4aa4da8, origin=0x0, 
context_die=0x7ffff6d16000) at ../../gcc/dwarf2out.c:20987
#7  0x0000000000b5e12a in dwarf2out_decl (decl=0x7ffff4aa4da8) at 
../../gcc/dwarf2out.c:21397
#8  0x0000000000b5d537 in dwarf2out_type_decl (decl=0x7ffff4aa4da8, local=0) at 
../../gcc/dwarf2out.c:21096
#9  0x0000000000ec4baa in rest_of_type_compilation (type=0x7ffff6d260a8, 
toplev=1) at ../../gcc/passes.c:309
#10 0x000000000074abeb in finish_enum_value_list (enumtype=0x7ffff6d260a8) at 
../../gcc/cp/decl.c:13043
#11 0x00000000007c3e53 in tsubst_enum (tag=0x7ffff4a999d8, 
newtag=0x7ffff6d260a8, args=0x7ffff6ea4940) at ../../gcc/cp/pt.c:20711
#12 0x0000000000785369 in lookup_template_class_1 (d1=0x7ffff4a68688, 
arglist=0x7ffff6ea4940, in_decl=0x7ffff4a97850, context=0x7ffff6d24d20, 
entering_scope=0, complain=3)
    at ../../gcc/cp/pt.c:8017
#13 0x00000000007854e4 in lookup_template_class (d1=0x7ffff4a999d8, 
arglist=0x7ffff6ea48e0, in_decl=0x7ffff4a97850, context=0x7ffff6d24d20, 
entering_scope=0, complain=3)
    at ../../gcc/cp/pt.c:8043
#14 0x000000000079090b in tsubst_aggr_type (t=0x7ffff4a999d8, 
args=0x7ffff6e9d840, complain=3, in_decl=0x7ffff4a97850, entering_scope=0) at 
../../gcc/cp/pt.c:10423
#15 0x0000000000798c34 in tsubst (t=0x7ffff4a999d8, args=0x7ffff6e9d840, 
complain=3, in_decl=0x7ffff4a97850) at ../../gcc/cp/pt.c:11872
#16 0x0000000000795eff in tsubst_decl (t=0x7ffff4a97850, args=0x7ffff6e9d840, 
complain=3) at ../../gcc/cp/pt.c:11219
#17 0x000000000079830f in tsubst (t=0x7ffff4a97850, args=0x7ffff6e9d840, 
complain=3, in_decl=0x0) at ../../gcc/cp/pt.c:11793
#18 0x000000000078c5de in instantiate_class_template_1 (type=0x7ffff6d24d20) at 
../../gcc/cp/pt.c:9386
#19 0x000000000078d3e7 in instantiate_class_template (type=0x7ffff6d24d20) at 
../../gcc/cp/pt.c:9650
#20 0x000000000088772c in complete_type (type=0x7ffff6d24d20) at 
../../gcc/cp/typeck.c:146
#21 0x00000000008dba41 in lookup_member (xbasetype=0x0, name=0x7ffff6ea9c08, 
protect=2, want_type=false, complain=3) at ../../gcc/cp/search.c:1213
#22 0x00000000009544db in lookup_qualified_name (scope=0x7ffff6d24d20, 
name=0x7ffff6ea9c08, is_type_p=false, complain=false) at 
../../gcc/cp/name-lookup.c:4540
#23 0x000000000079ca43 in tsubst_qualified_id (qualified_id=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00, done=true, 
address_p=false) at ../../gcc/cp/pt.c:12717
#24 0x00000000007a80df in tsubst_copy_and_build (t=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00, function_p=false, 
integral_constant_expression_p=true)
    at ../../gcc/cp/pt.c:14760
#25 0x00000000007a67b4 in tsubst_expr (t=0x7ffff6d2a4d8, args=0x7ffff6d2caf0, 
complain=3, in_decl=0x7ffff4ac9a00, integral_constant_expression_p=true) at 
../../gcc/cp/pt.c:14367
#26 0x000000000078d491 in tsubst_template_arg (t=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00) at 
../../gcc/cp/pt.c:9669
#27 0x000000000077f3ca in coerce_template_parms (parms=0x7ffff6d2a550, 
args=0x7ffff6e83960, in_decl=0x7ffff4ac9a00, complain=3, require_all_args=true, 
use_default_args=true)
    at ../../gcc/cp/pt.c:7142
#28 0x000000000077fa17 in coerce_innermost_template_parms 
(parms=0x7ffff6d2a578, args=0x7ffff6e83960, in_decl=0x7ffff4ac9a00, complain=3, 
require_all_args=true, use_default_args=true)
    at ../../gcc/cp/pt.c:7252
#29 0x0000000000782455 in lookup_template_class_1 (d1=0x7ffff6eab6e0, 
arglist=0x7ffff6e83960, in_decl=0x0, context=0x7ffff6e5bed8, entering_scope=0, 
complain=3) at ../../gcc/cp/pt.c:7727
#30 0x00000000007854e4 in lookup_template_class (d1=0x7ffff4ac9a00, 
arglist=0x7ffff6e83960, in_decl=0x0, context=0x0, entering_scope=0, 
complain=35) at ../../gcc/cp/pt.c:8043
#31 0x00000000008eaefe in finish_template_type (name=0x7ffff4ac9a00, 
args=0x7ffff6e83960, entering_scope=0) at ../../gcc/cp/semantics.c:3011
#32 0x000000000084c7a4 in cp_parser_template_id (parser=0x7ffff6be8c00, 
template_keyword_p=false, check_dependency_p=false, tag_type=class_type, 
is_declaration=false)
    at ../../gcc/cp/parser.c:13850

notice that the instantiate_template_class is still #18 in backtrace.
If I patch out the ICE the type gets size later:

#0  finalize_record_size (rli=0x22db5e0) at ../../gcc/stor-layout.c:1627
#1  0x0000000000fc2b65 in finish_record_layout (rli=0x22db5e0, free_p=1) at 
../../gcc/stor-layout.c:2070
#2  0x00000000007fa7aa in layout_class_type (t=0x7ffff6d24d20, 
virtuals_p=0x7fffffffcbd0) at ../../gcc/cp/class.c:6477
#3  0x00000000007fb5ff in finish_struct_1 (t=0x7ffff6d24d20) at 
../../gcc/cp/class.c:6607
#4  0x000000000078d1d3 in instantiate_class_template_1 (type=0x7ffff6d24d20) at 
../../gcc/cp/pt.c:9610
#5  0x000000000078d3e7 in instantiate_class_template (type=0x7ffff6d24d20) at 
../../gcc/cp/pt.c:9650
#6  0x000000000088772c in complete_type (type=0x7ffff6d24d20) at 
../../gcc/cp/typeck.c:146
#7  0x00000000008dba41 in lookup_member (xbasetype=0x0, name=0x7ffff6ea9c08, 
protect=2, want_type=false, complain=3) at ../../gcc/cp/search.c:1213
#8  0x00000000009544db in lookup_qualified_name (scope=0x7ffff6d24d20, 
name=0x7ffff6ea9c08, is_type_p=false, complain=false) at 
../../gcc/cp/name-lookup.c:4540
#9  0x000000000079ca43 in tsubst_qualified_id (qualified_id=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00, done=true, 
address_p=false) at ../../gcc/cp/pt.c:12717
#10 0x00000000007a80df in tsubst_copy_and_build (t=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00, function_p=false, 
integral_constant_expression_p=true)
    at ../../gcc/cp/pt.c:14760
#11 0x00000000007a67b4 in tsubst_expr (t=0x7ffff6d2a4d8, args=0x7ffff6d2caf0, 
complain=3, in_decl=0x7ffff4ac9a00, integral_constant_expression_p=true) at 
../../gcc/cp/pt.c:14367
#12 0x000000000078d491 in tsubst_template_arg (t=0x7ffff6d2a4d8, 
args=0x7ffff6d2caf0, complain=3, in_decl=0x7ffff4ac9a00) at 
../../gcc/cp/pt.c:9669
#13 0x000000000077f3ca in coerce_template_parms (parms=0x7ffff6d2a550, 
args=0x7ffff6e83960, in_decl=0x7ffff4ac9a00, complain=3, require_all_args=true, 
use_default_args=true)
    at ../../gcc/cp/pt.c:7142
#14 0x000000000077fa17 in coerce_innermost_template_parms 
(parms=0x7ffff6d2a578, args=0x7ffff6e83960, in_decl=0x7ffff4ac9a00, complain=3, 
require_all_args=true, use_default_args=true)
    at ../../gcc/cp/pt.c:7252
#15 0x0000000000782455 in lookup_template_class_1 (d1=0x7ffff6eab6e0, 
arglist=0x7ffff6e83960, in_decl=0x0, context=0x7ffff6e5bed8, entering_scope=0, 
complain=3) at ../../gcc/cp/pt.c:7727
#16 0x00000000007854e4 in lookup_template_class (d1=0x7ffff4ac9a00, 
arglist=0x7ffff6e83960, in_decl=0x0, context=0x0, entering_scope=0, 
complain=35) at ../../gcc/cp/pt.c:8043
#17 0x00000000008eaefe in finish_template_type (name=0x7ffff4ac9a00, 
args=0x7ffff6e83960, entering_scope=0) at ../../gcc/cp/semantics.c:3011
#18 0x000000000084c7a4 in cp_parser_template_id (parser=0x7ffff6be8c00, 
template_keyword_p=false, check_dependency_p=false, tag_type=class_type, 
is_declaration=false)
    at ../../gcc/cp/parser.c:13850

Is it expected&safe for dwarf2out to process unfinished types?  It seems to me
that we may wan to delay rest_of_type_compilation for time the contexts are
finished, to..

I am attaching the verifier patch that triggers this while building libstdc++
PCH headers.  It will also fire for Java.

Honza

Index: tree.c
===================================================================
--- tree.c      (revision 223100)
+++ tree.c      (working copy)
@@ -12564,12 +12564,8 @@ verify_type_variant (const_tree t, tree
      Also disable the check for Java for now because of parser hack that builds
      first an dummy BINFO and then sometimes replace it by real BINFO in some
      of the copies.  */
-  if (RECORD_OR_UNION_TYPE_P (t) && TYPE_BINFO (t) && TYPE_BINFO (tv)
-      && TYPE_BINFO (t) != TYPE_BINFO (tv)
-      /* FIXME: Java sometimes keep dump TYPE_BINFOs on variant types.
-        Since there is no cheap way to tell C++/Java type w/o LTO, do checking
-        at LTO time only.  */
-      && (in_lto_p && odr_type_p (t)))
+  if (RECORD_OR_UNION_TYPE_P (t) && COMPLETE_TYPE_P (t)
+      && TYPE_BINFO (t) != TYPE_BINFO (tv))
     {
       error ("type variant has different TYPE_BINFO");
       debug_tree (tv);
@@ -12817,6 +12813,12 @@ verify_type (const_tree t)
          debug_tree (TYPE_BINFO (t));
          error_found = true;
        }
+      else if ((TYPE_BINFO (t) != NULL) != COMPLETE_TYPE_P (t))
+       {
+         error ("TYPE_BINFO and COMPLETE_TYPE_P mismatch");
+         debug_tree (TYPE_BINFO (t));
+         error_found = true;
+       }
       /* FIXME: Java builds invalid empty binfos that do not have
          TREE_TYPE set.  */
       else if (TREE_TYPE (TYPE_BINFO (t)) != TYPE_MAIN_VARIANT (t) && 0)

Reply via email to