diff mbox series

Walk pointer_to and reference_to chain in free_lang_data

Message ID 20180821210557.GA30630@kam.mff.cuni.cz
State New
Headers show
Series Walk pointer_to and reference_to chain in free_lang_data | expand

Commit Message

Jan Hubicka Aug. 21, 2018, 9:05 p.m. UTC
Hi,
extra sanity checking I am going to send in followup patch noticed that we
stream pointer types that was never seen by free_lang_data.  This is because
they are referenced by TYPE_POINTER_TO list and are inserted into the gimple
statements later when we wrap everything in MEM_REF (by make_pointer_type).

Bootstrapped/regtested x86_64-linux, OK?

Honza

	* tree.c (find_decls_types_r): Walk also TYPE_NEXT_PTR_TO and
	TYPE_NEXT_REF_TO.

Comments

Richard Biener Aug. 22, 2018, 7:11 a.m. UTC | #1
On Tue, 21 Aug 2018, Jan Hubicka wrote:

> Hi,
> extra sanity checking I am going to send in followup patch noticed that we
> stream pointer types that was never seen by free_lang_data.  This is because
> they are referenced by TYPE_POINTER_TO list and are inserted into the gimple
> statements later when we wrap everything in MEM_REF (by make_pointer_type).
> 
> Bootstrapped/regtested x86_64-linux, OK?

Hmm, but make_pointer_type might as well create new pointer types
that didn't exist before - shouldn't those have the same problem
(which actually is?)?  Note the pointed-to types are already in the IL,
so another option would be to create (and walk) the pointer types
under the same circumstance as streaming creates them when walking the
IL.  Note that new pointer types can be created between free-lang-data
and streaming anyways ...

So again - what's the real reason?  I bet the sanity checking might
trip over late creation of pointer-types so I'd rather fix the
sanity checking and only check the pointed-to types were visited?

Richard.

> Honza
> 
> 	* tree.c (find_decls_types_r): Walk also TYPE_NEXT_PTR_TO and
> 	TYPE_NEXT_REF_TO.
> Index: tree.c
> ===================================================================
> --- tree.c	(revision 263699)
> +++ tree.c	(working copy)
> @@ -5525,9 +5525,14 @@ find_decls_types_r (tree *tp, int *ws, v
>        fld_worklist_push (TYPE_POINTER_TO (t), fld);
>        fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
>        fld_worklist_push (TYPE_NAME (t), fld);
> -      /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO.  We do not stream
> -	 them and thus do not and want not to reach unused pointer types
> -	 this way.  */
> +      /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
> +	 lists, we may look types up in these lists and use them while
> +	 optimizing the function body.  Thus we need to free lang data
> +	 in them.  */
> +      if (TREE_CODE (t) == POINTER_TYPE)
> +        fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
> +      if (TREE_CODE (t) == REFERENCE_TYPE)
> +        fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
>        if (!POINTER_TYPE_P (t))
>  	fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
>        /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types.  */
> 
>
Jan Hubicka Aug. 22, 2018, 7:23 a.m. UTC | #2
> On Tue, 21 Aug 2018, Jan Hubicka wrote:
> 
> > Hi,
> > extra sanity checking I am going to send in followup patch noticed that we
> > stream pointer types that was never seen by free_lang_data.  This is because
> > they are referenced by TYPE_POINTER_TO list and are inserted into the gimple
> > statements later when we wrap everything in MEM_REF (by make_pointer_type).
> > 
> > Bootstrapped/regtested x86_64-linux, OK?
> 
> Hmm, but make_pointer_type might as well create new pointer types
> that didn't exist before - shouldn't those have the same problem
> (which actually is?)?  Note the pointed-to types are already in the IL,

I am now clearing TYPE_STUB_DECL to NULL and check that it is NULL later in
streaming.  There are indeed some other cases where this check triggers.

Pointer types are not problem because they are created w/o stubs.  Other issues
I see with this are backend produced structures - gcov, asan and ubsan all
create structures with non-NULL stubs.  They are DECL_ARTIFICIAL so I am not
quite sure why we set stubs there.

  tree type_decl = build_decl (input_location, TYPE_DECL,                       
                               get_identifier ("__asan_global"), ret);          
  DECL_IGNORED_P (type_decl) = 1;                                               
  DECL_ARTIFICIAL (type_decl) = 1;                                              
  TYPE_FIELDS (ret) = fields[0];                                                
  TYPE_NAME (ret) = type_decl;                                                  
  TYPE_STUB_DECL (ret) = type_decl;                                             

It seems to me that setting TYPE_NAME to identifier node would be easier.
gcov uses finish_builtin_struct which in turn does:

#if 0 /* not yet, should get fixed properly later */                            
  TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
#else
  TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
                                 TYPE_DECL, get_identifier (name), type);
#endif
  TYPE_STUB_DECL (type) = TYPE_NAME (type);

It does not seem to set artificial.  I am not quite sure what to do about
those.

In any case we should free lang data frontend created pointer types that may
get back to IL stream.  C++ will give them TYPE_DECL based TYPE_NAMEs that
we want to translate to identifiers for example.

Honza
Richard Biener Aug. 22, 2018, 7:30 a.m. UTC | #3
On Wed, 22 Aug 2018, Jan Hubicka wrote:

> > On Tue, 21 Aug 2018, Jan Hubicka wrote:
> > 
> > > Hi,
> > > extra sanity checking I am going to send in followup patch noticed that we
> > > stream pointer types that was never seen by free_lang_data.  This is because
> > > they are referenced by TYPE_POINTER_TO list and are inserted into the gimple
> > > statements later when we wrap everything in MEM_REF (by make_pointer_type).
> > > 
> > > Bootstrapped/regtested x86_64-linux, OK?
> > 
> > Hmm, but make_pointer_type might as well create new pointer types
> > that didn't exist before - shouldn't those have the same problem
> > (which actually is?)?  Note the pointed-to types are already in the IL,
> 
> I am now clearing TYPE_STUB_DECL to NULL and check that it is NULL later in
> streaming.  There are indeed some other cases where this check triggers.
> 
> Pointer types are not problem because they are created w/o stubs.  Other issues
> I see with this are backend produced structures - gcov, asan and ubsan all
> create structures with non-NULL stubs.  They are DECL_ARTIFICIAL so I am not
> quite sure why we set stubs there.
> 
>   tree type_decl = build_decl (input_location, TYPE_DECL,                       
>                                get_identifier ("__asan_global"), ret);          
>   DECL_IGNORED_P (type_decl) = 1;                                               
>   DECL_ARTIFICIAL (type_decl) = 1;                                              
>   TYPE_FIELDS (ret) = fields[0];                                                
>   TYPE_NAME (ret) = type_decl;                                                  
>   TYPE_STUB_DECL (ret) = type_decl;                                             
> 
> It seems to me that setting TYPE_NAME to identifier node would be easier.

Yeah.  I probably added the DECL_INGORED_P to most of those so indeed
type_decls are somewhat pointless.

> gcov uses finish_builtin_struct which in turn does:
> 
> #if 0 /* not yet, should get fixed properly later */                            
>   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
> #else
>   TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
>                                  TYPE_DECL, get_identifier (name), type);
> #endif
>   TYPE_STUB_DECL (type) = TYPE_NAME (type);
> 
> It does not seem to set artificial.  I am not quite sure what to do about
> those.

given gcov has a runtime component with debug info did we intend to
make the compiler-generated part debuggable maybe?

> In any case we should free lang data frontend created pointer types that may
> get back to IL stream.  C++ will give them TYPE_DECL based TYPE_NAMEs that
> we want to translate to identifiers for example.

Ah, yes, that makes sense.  Which means your patch is OK if you reflect
the above in the comment (it's about FE generated pointer types).  We
might also somehow forcefully "collect" unused pointer types from the
chains...

Richard.

> Honza
> 
>
Jan Hubicka Aug. 22, 2018, 7:59 a.m. UTC | #4
> >   tree type_decl = build_decl (input_location, TYPE_DECL,                       
> >                                get_identifier ("__asan_global"), ret);          
> >   DECL_IGNORED_P (type_decl) = 1;                                               
> >   DECL_ARTIFICIAL (type_decl) = 1;                                              
> >   TYPE_FIELDS (ret) = fields[0];                                                
> >   TYPE_NAME (ret) = type_decl;                                                  
> >   TYPE_STUB_DECL (ret) = type_decl;                                             
> > 
> > It seems to me that setting TYPE_NAME to identifier node would be easier.
> 
> Yeah.  I probably added the DECL_INGORED_P to most of those so indeed
> type_decls are somewhat pointless.

OK, I will send separate patch and turn those into identifier nodes.
> 
> > gcov uses finish_builtin_struct which in turn does:
> > 
> > #if 0 /* not yet, should get fixed properly later */                            
> >   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
> > #else
> >   TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
> >                                  TYPE_DECL, get_identifier (name), type);
> > #endif
> >   TYPE_STUB_DECL (type) = TYPE_NAME (type);
> > 
> > It does not seem to set artificial.  I am not quite sure what to do about
> > those.
> 
> given gcov has a runtime component with debug info did we intend to
> make the compiler-generated part debuggable maybe?

It never appeared to me that I could debug them and source level :).
Compiling simple main function with profile gnerate we get:
__gcov_.main
__gcov0.main
__gcov7.main
(counters and the structure describing them)
Neither of those seems to be accessible from gdb nor we generate debug info
for the structures we finalize builtins for.

Note that with this patch and sanity check about type_stub_decl being NULL I get the following
errors and the lto-bootstrap passes (which is not too bad I would say):

 
 Running target unix
+FAIL: gcc.c-torture/compile/pr44686.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: gcc.c-torture/compile/pr44686.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: gcc.c-torture/compile/pr44686.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: gcc.c-torture/compile/pr44686.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
 XPASS: gcc.dg/guality/example.c   -O0  execution test
 XPASS: gcc.dg/guality/example.c   -O1  -DPREVENT_OPTIMIZATION  execution test
 XPASS: gcc.dg/guality/example.c  -Og -DPREVENT_OPTIMIZATION  execution test
@@ -136,15 +140,81 @@
 FAIL: gcc.dg/guality/vla-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  -DPREVENT_OPTIMIZATION line 17 sizeof (a) == 6
 FAIL: gcc.dg/guality/vla-1.c   -O3 -g  -DPREVENT_OPTIMIZATION  line 17 sizeof (a) == 6
 FAIL: gcc.dg/guality/vla-1.c   -Os  -DPREVENT_OPTIMIZATION  line 17 sizeof (a) == 6
+FAIL: gcc.dg/lto/20100430-1 c_lto_20100430-1_0.o assemble, -O2 -fprofile-arcs -flto -r -nostdlib (internal compiler error)
+UNRESOLVED: gcc.dg/lto/20100430-1 c_lto_20100430-1_0.o-c_lto_20100430-1_0.o execute -O2 -fprofile-arcs -flto -r -nostdlib
+UNRESOLVED: gcc.dg/lto/20100430-1 c_lto_20100430-1_0.o-c_lto_20100430-1_0.o link -O2 -fprofile-arcs -flto -r -nostdlib
+FAIL: gcc.dg/lto/pr69188 c_lto_pr69188_0.o assemble,  -flto -O0 -fprofile-generate  (internal compiler error)
+UNRESOLVED: gcc.dg/lto/pr69188 c_lto_pr69188_0.o-c_lto_pr69188_1.o execute  -flto -O0 -fprofile-generate 
+UNRESOLVED: gcc.dg/lto/pr69188 c_lto_pr69188_0.o-c_lto_pr69188_1.o link  -flto -O0 -fprofile-generate 
+FAIL: gcc.dg/lto/pr69188 c_lto_pr69188_1.o assemble,  -flto -O0 -fprofile-generate  (internal compiler error)
+FAIL: gcc.dg/torture/pr41261.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: gcc.dg/torture/pr41261.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: gcc.dg/torture/pr41261.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: gcc.dg/torture/pr41261.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: gcc.dg/torture/pr83055.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: gcc.dg/torture/pr83055.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: gcc.dg/torture/pr83055.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: gcc.dg/torture/pr83055.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: gcc.dg/tree-prof/crossmodule-indircall-1.c compilation,  -fprofile-generate -D_PROFILE_GENERATE (internal compiler error)
+UNRESOLVED: gcc.dg/tree-prof/crossmodule-indircall-1.c compilation,  -fprofile-use -D_PROFILE_USE
+UNRESOLVED: gcc.dg/tree-prof/crossmodule-indircall-1.c execution,    -fprofile-generate -D_PROFILE_GENERATE
+UNRESOLVED: gcc.dg/tree-prof/crossmodule-indircall-1.c execution,    -fprofile-use -D_PROFILE_USE
+FAIL: gcc.dg/tree-prof/pr79587.c compilation,  -fprofile-generate -D_PROFILE_GENERATE (internal compiler error)
+UNRESOLVED: gcc.dg/tree-prof/pr79587.c compilation,  -fprofile-use -D_PROFILE_USE
+UNRESOLVED: gcc.dg/tree-prof/pr79587.c execution,    -fprofile-generate -D_PROFILE_GENERATE
+UNRESOLVED: gcc.dg/tree-prof/pr79587.c execution,    -fprofile-use -D_PROFILE_USE
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: gcc.dg/vect/bb-slp-pr80705.c -flto -ffat-lto-objects  scan-tree-dump slp1 "base object not addressable"
+UNRESOLVED: gcc.dg/vect/bb-slp-pr80705.c -flto -ffat-lto-objects  scan-tree-dump-not slp1 "MEM[^\\r\\n]*__gcov[^\\r\\n]* = vect_cst"
+FAIL: gcc.dg/vect/bb-slp-pr80705.c -flto -ffat-lto-objects (internal compiler error)
+FAIL: gcc.dg/vect/bb-slp-pr80705.c -flto -ffat-lto-objects (test for excess errors)
 
 		=== gcc Summary ===
 
-# of expected passes		137922
-# of unexpected failures	95
+# of expected passes		137890
+# of unexpected failures	142
 # of unexpected successes	23
 # of expected failures		469
+# of unresolved testcases	22
 # of unsupported tests		2265
-/aux/hubicka/trunk3/build-lto2/gcc/xgcc  version 9.0.0 20180820 (experimental) (GCC) 
+/aux/hubicka/trunk3/build-lto-new/gcc/xgcc  version 9.0.0 20180821 (experimental) (GCC) 
 
 		=== gfortran tests ===
 
@@ -156,7 +226,7 @@
 # of expected passes		47667
 # of expected failures		104
 # of unsupported tests		81
-/aux/hubicka/trunk3/build-lto2/gcc/gfortran  version 9.0.0 20180820 (experimental) (GCC) 
+/aux/hubicka/trunk3/build-lto-new/gcc/gfortran  version 9.0.0 20180821 (experimental) (GCC) 
 
 		=== g++ tests ===
 
@@ -167,14 +237,88 @@
 FAIL: g++.dg/pr80481.C  -std=gnu++98  scan-assembler-not vmovaps
 FAIL: g++.dg/pr83239.C  -std=gnu++98 (test for excess errors)
 FAIL: g++.dg/guality/pr55665.C   -O2  line 23 p == 40
+FAIL: g++.dg/lto/pr65316 cp_lto_pr65316_0.o assemble,  -flto -std=c++11 -g2 -fno-lto-odr-type-merging -O2 -Wno-return-type  (internal compiler error)
+UNRESOLVED: g++.dg/lto/pr65316 cp_lto_pr65316_0.o-cp_lto_pr65316_1.o execute  -flto -std=c++11 -g2 -fno-lto-odr-type-merging -O2 -Wno-return-type 
+UNRESOLVED: g++.dg/lto/pr65316 cp_lto_pr65316_0.o-cp_lto_pr65316_1.o link  -flto -std=c++11 -g2 -fno-lto-odr-type-merging -O2 -Wno-return-type 
+FAIL: g++.dg/torture/pr39732.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: g++.dg/torture/pr39732.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: g++.dg/torture/pr39732.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: g++.dg/torture/pr39732.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: g++.dg/torture/pr40642.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: g++.dg/torture/pr40642.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: g++.dg/torture/pr40642.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: g++.dg/torture/pr40642.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: g++.dg/torture/pr53321.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: g++.dg/torture/pr53321.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: g++.dg/torture/pr53321.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: g++.dg/torture/pr53321.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/builtin-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/load-bool-enum.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: c-c++-common/ubsan/nonnull-3.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr65984.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr78858.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr79897.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr79897.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: c-c++-common/ubsan/pr79897.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: c-c++-common/ubsan/pr79897.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63913.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: g++.dg/ubsan/pr63913.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+FAIL: g++.dg/ubsan/pr63913.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: g++.dg/ubsan/pr63913.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+FAIL: g++.dg/ubsan/pr82353-2.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: g++.dg/ubsan/pr82353-2.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: g++.dg/ubsan/pr82353-2.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  compilation failed to produce executable
+FAIL: g++.dg/ubsan/pr82353-2.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: g++.dg/ubsan/pr82353-2.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
+UNRESOLVED: g++.dg/ubsan/pr82353-2.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  compilation failed to produce executable
+UNRESOLVED: g++.dg/ubsan/pr82353.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none   scan-rtl-dump-not reload "Inserting rematerialization insn"
+FAIL: g++.dg/ubsan/pr82353.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (internal compiler error)
+FAIL: g++.dg/ubsan/pr82353.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  (test for excess errors)
+UNRESOLVED: g++.dg/ubsan/pr82353.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects   scan-rtl-dump-not reload "Inserting rematerialization insn"
+FAIL: g++.dg/ubsan/pr82353.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (internal compiler error)
+FAIL: g++.dg/ubsan/pr82353.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  (test for excess errors)
 
 		=== g++ Summary ===
 

Honza
> 
> > In any case we should free lang data frontend created pointer types that may
> > get back to IL stream.  C++ will give them TYPE_DECL based TYPE_NAMEs that
> > we want to translate to identifiers for example.
> 
> Ah, yes, that makes sense.  Which means your patch is OK if you reflect
> the above in the comment (it's about FE generated pointer types).  We
> might also somehow forcefully "collect" unused pointer types from the
> chains...
> 
> Richard.
> 
> > Honza
> > 
> > 
> 
> -- 
> Richard Biener <rguenther@suse.de>
> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
Jan Hubicka Aug. 23, 2018, noon UTC | #5
> >   tree type_decl = build_decl (input_location, TYPE_DECL,                       
> >                                get_identifier ("__asan_global"), ret);          
> >   DECL_IGNORED_P (type_decl) = 1;                                               
> >   DECL_ARTIFICIAL (type_decl) = 1;                                              
> >   TYPE_FIELDS (ret) = fields[0];                                                
> >   TYPE_NAME (ret) = type_decl;                                                  
> >   TYPE_STUB_DECL (ret) = type_decl;                                             
> > 
> > It seems to me that setting TYPE_NAME to identifier node would be easier.
> 
> Yeah.  I probably added the DECL_INGORED_P to most of those so indeed
> type_decls are somewhat pointless.

OK, I have tried to remove them and it passes bootstrap/regtest x86-64.
Looks sane?

Honza

	* asan.c (asan_global_struct): Turn TYPE_NAME into identifier.
	(ubsan_get_type_descriptor_type,
	ubsan_get_source_location_type,
	ubsan_create_data): Likewise.
Index: asan.c
===================================================================
--- asan.c	(revision 263696)
+++ asan.c	(working copy)
@@ -2515,13 +2515,8 @@ asan_global_struct (void)
       if (i)
 	DECL_CHAIN (fields[i - 1]) = fields[i];
     }
-  tree type_decl = build_decl (input_location, TYPE_DECL,
-			       get_identifier ("__asan_global"), ret);
-  DECL_IGNORED_P (type_decl) = 1;
-  DECL_ARTIFICIAL (type_decl) = 1;
   TYPE_FIELDS (ret) = fields[0];
-  TYPE_NAME (ret) = type_decl;
-  TYPE_STUB_DECL (ret) = type_decl;
+  TYPE_NAME (ret) = get_identifier ("__asan_global");
   layout_type (ret);
   return ret;
 }
Index: ubsan.c
===================================================================
--- ubsan.c	(revision 263696)
+++ ubsan.c	(working copy)
@@ -221,14 +221,8 @@ ubsan_get_type_descriptor_type (void)
       if (i)
 	DECL_CHAIN (fields[i - 1]) = fields[i];
     }
-  tree type_decl = build_decl (input_location, TYPE_DECL,
-			       get_identifier ("__ubsan_type_descriptor"),
-			       ret);
-  DECL_IGNORED_P (type_decl) = 1;
-  DECL_ARTIFICIAL (type_decl) = 1;
   TYPE_FIELDS (ret) = fields[0];
-  TYPE_NAME (ret) = type_decl;
-  TYPE_STUB_DECL (ret) = type_decl;
+  TYPE_NAME (ret) = get_identifier ("__ubsan_type_descriptor");
   layout_type (ret);
   ubsan_type_descriptor_type = ret;
   return ret;
@@ -269,14 +263,8 @@ ubsan_get_source_location_type (void)
       if (i)
 	DECL_CHAIN (fields[i - 1]) = fields[i];
     }
-  tree type_decl = build_decl (input_location, TYPE_DECL,
-			       get_identifier ("__ubsan_source_location"),
-			       ret);
-  DECL_IGNORED_P (type_decl) = 1;
-  DECL_ARTIFICIAL (type_decl) = 1;
   TYPE_FIELDS (ret) = fields[0];
-  TYPE_NAME (ret) = type_decl;
-  TYPE_STUB_DECL (ret) = type_decl;
+  TYPE_NAME (ret) = get_identifier ("__ubsan_source_location");
   layout_type (ret);
   ubsan_source_location_type = ret;
   return ret;
@@ -586,13 +574,8 @@ ubsan_create_data (const char *name, int
     }
   va_end (args);
 
-  tree type_decl = build_decl (input_location, TYPE_DECL,
-			       get_identifier (name), ret);
-  DECL_IGNORED_P (type_decl) = 1;
-  DECL_ARTIFICIAL (type_decl) = 1;
   TYPE_FIELDS (ret) = fields[0];
-  TYPE_NAME (ret) = type_decl;
-  TYPE_STUB_DECL (ret) = type_decl;
+  TYPE_NAME (ret) = get_identifier (name);
   layout_type (ret);
 
   /* Now, fill in the type.  */
Richard Biener Aug. 23, 2018, 12:06 p.m. UTC | #6
On Thu, 23 Aug 2018, Jan Hubicka wrote:

> > >   tree type_decl = build_decl (input_location, TYPE_DECL,                       
> > >                                get_identifier ("__asan_global"), ret);          
> > >   DECL_IGNORED_P (type_decl) = 1;                                               
> > >   DECL_ARTIFICIAL (type_decl) = 1;                                              
> > >   TYPE_FIELDS (ret) = fields[0];                                                
> > >   TYPE_NAME (ret) = type_decl;                                                  
> > >   TYPE_STUB_DECL (ret) = type_decl;                                             
> > > 
> > > It seems to me that setting TYPE_NAME to identifier node would be easier.
> > 
> > Yeah.  I probably added the DECL_INGORED_P to most of those so indeed
> > type_decls are somewhat pointless.
> 
> OK, I have tried to remove them and it passes bootstrap/regtest x86-64.
> Looks sane?

OK.

Richard.

> Honza
> 
> 	* asan.c (asan_global_struct): Turn TYPE_NAME into identifier.
> 	(ubsan_get_type_descriptor_type,
> 	ubsan_get_source_location_type,
> 	ubsan_create_data): Likewise.
> Index: asan.c
> ===================================================================
> --- asan.c	(revision 263696)
> +++ asan.c	(working copy)
> @@ -2515,13 +2515,8 @@ asan_global_struct (void)
>        if (i)
>  	DECL_CHAIN (fields[i - 1]) = fields[i];
>      }
> -  tree type_decl = build_decl (input_location, TYPE_DECL,
> -			       get_identifier ("__asan_global"), ret);
> -  DECL_IGNORED_P (type_decl) = 1;
> -  DECL_ARTIFICIAL (type_decl) = 1;
>    TYPE_FIELDS (ret) = fields[0];
> -  TYPE_NAME (ret) = type_decl;
> -  TYPE_STUB_DECL (ret) = type_decl;
> +  TYPE_NAME (ret) = get_identifier ("__asan_global");
>    layout_type (ret);
>    return ret;
>  }
> Index: ubsan.c
> ===================================================================
> --- ubsan.c	(revision 263696)
> +++ ubsan.c	(working copy)
> @@ -221,14 +221,8 @@ ubsan_get_type_descriptor_type (void)
>        if (i)
>  	DECL_CHAIN (fields[i - 1]) = fields[i];
>      }
> -  tree type_decl = build_decl (input_location, TYPE_DECL,
> -			       get_identifier ("__ubsan_type_descriptor"),
> -			       ret);
> -  DECL_IGNORED_P (type_decl) = 1;
> -  DECL_ARTIFICIAL (type_decl) = 1;
>    TYPE_FIELDS (ret) = fields[0];
> -  TYPE_NAME (ret) = type_decl;
> -  TYPE_STUB_DECL (ret) = type_decl;
> +  TYPE_NAME (ret) = get_identifier ("__ubsan_type_descriptor");
>    layout_type (ret);
>    ubsan_type_descriptor_type = ret;
>    return ret;
> @@ -269,14 +263,8 @@ ubsan_get_source_location_type (void)
>        if (i)
>  	DECL_CHAIN (fields[i - 1]) = fields[i];
>      }
> -  tree type_decl = build_decl (input_location, TYPE_DECL,
> -			       get_identifier ("__ubsan_source_location"),
> -			       ret);
> -  DECL_IGNORED_P (type_decl) = 1;
> -  DECL_ARTIFICIAL (type_decl) = 1;
>    TYPE_FIELDS (ret) = fields[0];
> -  TYPE_NAME (ret) = type_decl;
> -  TYPE_STUB_DECL (ret) = type_decl;
> +  TYPE_NAME (ret) = get_identifier ("__ubsan_source_location");
>    layout_type (ret);
>    ubsan_source_location_type = ret;
>    return ret;
> @@ -586,13 +574,8 @@ ubsan_create_data (const char *name, int
>      }
>    va_end (args);
>  
> -  tree type_decl = build_decl (input_location, TYPE_DECL,
> -			       get_identifier (name), ret);
> -  DECL_IGNORED_P (type_decl) = 1;
> -  DECL_ARTIFICIAL (type_decl) = 1;
>    TYPE_FIELDS (ret) = fields[0];
> -  TYPE_NAME (ret) = type_decl;
> -  TYPE_STUB_DECL (ret) = type_decl;
> +  TYPE_NAME (ret) = get_identifier (name);
>    layout_type (ret);
>  
>    /* Now, fill in the type.  */
> 
>
Jan Hubicka Aug. 23, 2018, 12:06 p.m. UTC | #7
Hi
this patch takes care of gcov.  There are two oddities. First that gcov uses
langhook to produce new records while asan gets around with make_node.
I think both are middle-end types and in the direction of separating front-ends
and middle-ends better the langhooks are not desirable.

The TYPE_STUB_DECL is produced by finish_builtin_struct.  This is function used
just few times but I am not sure if we don't want debug info on some of the
builtins, so I have added extra parameter.

config/darwin.c:  finish_builtin_struct (cfstring_type_node, "__builtin_CFString",
config/i386/i386.c:  finish_builtin_struct (type, "__processor_model", field_chain, NULL_TREE);
coverage.c:  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE, true);
coverage.c:  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE, true);
coverage.c:  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE, true);
cp/decl.c:  finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
cp/rtti.c:  finish_builtin_struct (pseudo_type, pseudo_name, fields, NULL_TREE);
hsa-brig.c:  finish_builtin_struct (variable_info_type, "__hsa_variable_info", id_f2,
hsa-brig.c:  finish_builtin_struct (kernel_info_type, "__hsa_kernel_info", id_f5,
hsa-brig.c:  finish_builtin_struct (hsa_image_desc_type, "__hsa_image_desc", id_f5,
hsa-gen.c:      finish_builtin_struct (*hsa_kernel_dispatch_type, "__hsa_kernel_dispatch",
objc/objc-act.c:  /* NB: The finish_builtin_struct() routine expects FIELD_DECLs in
objc/objc-act.c:  finish_builtin_struct (type, "__builtin_ObjCString",
omp-expand.c:  finish_builtin_struct (grid_attr_trees->kernel_launch_attributes_type,
stor-layout.c:finish_builtin_struct (tree type, const char *name, tree fields,
stor-layout.h:extern void finish_builtin_struct (tree, const char *, tree, tree,

Perhaps we could make them all to just use identifier_node
but I am honestly not sure :)

Bootstrapped/regtested x86_64-linux, OK?

Honza

	* coverage.c (build_fn_info_type, build_info, coverage_obj_init):
	Use make_node to build record type and pass true to
	finish_builtin_struct.
	* stor-layout.c (finish_record_layout): Add nodebug parameter.
	* stor-layout.h (finish_builtin_struct): Likewise.
Index: coverage.c
===================================================================
--- coverage.c	(revision 263696)
+++ coverage.c	(working copy)
@@ -780,7 +780,7 @@ build_var (tree fn_decl, tree type, int
 static void
 build_fn_info_type (tree type, unsigned counters, tree gcov_info_type)
 {
-  tree ctr_info = lang_hooks.types.make_type (RECORD_TYPE);
+  tree ctr_info = make_node (RECORD_TYPE);
   tree field, fields;
   tree array_type;
 
@@ -797,7 +797,7 @@ build_fn_info_type (tree type, unsigned
   DECL_CHAIN (field) = fields;
   fields = field;
   
-  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE);
+  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE, true);
 
   /* key */
   field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
@@ -831,7 +831,7 @@ build_fn_info_type (tree type, unsigned
   DECL_CHAIN (field) = fields;
   fields = field;
 
-  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE);
+  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE, true);
 }
 
 /* Returns a CONSTRUCTOR for a gcov_fn_info.  DATA is
@@ -963,7 +963,7 @@ build_info_type (tree type, tree fn_info
   DECL_CHAIN (field) = fields;
   fields = field;
 
-  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE);
+  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE, true);
 }
 
 /* Returns a CONSTRUCTOR for the gcov_info object.  INFO_TYPE is the
@@ -1020,8 +1020,6 @@ build_info (tree info_type, tree fn_ary)
 				      get_identifier (ctr_merge_functions[ix]),
 				      TREE_TYPE (merge_fn_type));
 	  DECL_EXTERNAL (merge_fn) = 1;
-	  TREE_PUBLIC (merge_fn) = 1;
-	  DECL_ARTIFICIAL (merge_fn) = 1;
 	  TREE_NOTHROW (merge_fn) = 1;
 	  /* Initialize assembler name so we can stream out. */
 	  DECL_ASSEMBLER_NAME (merge_fn);
@@ -1140,10 +1138,10 @@ coverage_obj_init (void)
       n_counters++;
   
   /* Build the info and fn_info types.  These are mutually recursive.  */
-  gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
-  gcov_fn_info_type = lang_hooks.types.make_type (RECORD_TYPE);
+  gcov_info_type = make_node (RECORD_TYPE);
+  gcov_fn_info_type = make_node (RECORD_TYPE);
   build_fn_info_type (gcov_fn_info_type, n_counters, gcov_info_type);
-  gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
+  gcov_info_type = make_node (RECORD_TYPE);
   gcov_fn_info_ptr_type = build_pointer_type
     (build_qualified_type (gcov_fn_info_type, TYPE_QUAL_CONST));
   build_info_type (gcov_info_type, gcov_fn_info_ptr_type);
Index: stor-layout.c
===================================================================
--- stor-layout.c	(revision 263696)
+++ stor-layout.c	(working copy)
@@ -2224,13 +2224,14 @@ finish_record_layout (record_layout_info
 
 /* Finish processing a builtin RECORD_TYPE type TYPE.  It's name is
    NAME, its fields are chained in reverse on FIELDS.
+   If NODEBUG is set, do not produce TYPE_DECL and STUB.
 
    If ALIGN_TYPE is non-null, it is given the same alignment as
    ALIGN_TYPE.  */
 
 void
 finish_builtin_struct (tree type, const char *name, tree fields,
-		       tree align_type)
+		       tree align_type, bool nodebug)
 {
   tree tail, next;
 
@@ -2251,14 +2252,15 @@ finish_builtin_struct (tree type, const
     }
 
   layout_type (type);
-#if 0 /* not yet, should get fixed properly later */
-  TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
-#else
-  TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
-				 TYPE_DECL, get_identifier (name), type);
-#endif
-  TYPE_STUB_DECL (type) = TYPE_NAME (type);
-  layout_decl (TYPE_NAME (type), 0);
+  if (nodebug)
+    TYPE_NAME (type) = get_identifier (name);
+  else
+    {
+      TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
+				     TYPE_DECL, get_identifier (name), type);
+      TYPE_STUB_DECL (type) = TYPE_NAME (type);
+      layout_decl (TYPE_NAME (type), 0);
+    }
 }
 
 /* Calculate the mode, size, and alignment for TYPE.
Index: stor-layout.h
===================================================================
--- stor-layout.h	(revision 263696)
+++ stor-layout.h	(working copy)
@@ -43,7 +43,8 @@ extern void initialize_sizetypes (void);
 
 /* Finish up a builtin RECORD_TYPE. Give it a name and provide its
    fields. Optionally specify an alignment, and then lay it out.  */
-extern void finish_builtin_struct (tree, const char *, tree, tree);
+extern void finish_builtin_struct (tree, const char *, tree, tree,
+				   bool nodebug = false);
 
 /* Given a VAR_DECL, PARM_DECL, RESULT_DECL or FIELD_DECL node,
    calculates the DECL_SIZE, DECL_SIZE_UNIT, DECL_ALIGN and DECL_MODE
Richard Biener Aug. 23, 2018, 12:20 p.m. UTC | #8
On Thu, 23 Aug 2018, Jan Hubicka wrote:

> Hi
> this patch takes care of gcov.  There are two oddities. First that gcov uses
> langhook to produce new records while asan gets around with make_node.
> I think both are middle-end types and in the direction of separating front-ends
> and middle-ends better the langhooks are not desirable.
> 
> The TYPE_STUB_DECL is produced by finish_builtin_struct.  This is function used
> just few times but I am not sure if we don't want debug info on some of the
> builtins, so I have added extra parameter.
> 
> config/darwin.c:  finish_builtin_struct (cfstring_type_node, "__builtin_CFString",
> config/i386/i386.c:  finish_builtin_struct (type, "__processor_model", field_chain, NULL_TREE);
> coverage.c:  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE, true);
> coverage.c:  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE, true);
> coverage.c:  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE, true);
> cp/decl.c:  finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
> cp/rtti.c:  finish_builtin_struct (pseudo_type, pseudo_name, fields, NULL_TREE);
> hsa-brig.c:  finish_builtin_struct (variable_info_type, "__hsa_variable_info", id_f2,
> hsa-brig.c:  finish_builtin_struct (kernel_info_type, "__hsa_kernel_info", id_f5,
> hsa-brig.c:  finish_builtin_struct (hsa_image_desc_type, "__hsa_image_desc", id_f5,
> hsa-gen.c:      finish_builtin_struct (*hsa_kernel_dispatch_type, "__hsa_kernel_dispatch",
> objc/objc-act.c:  /* NB: The finish_builtin_struct() routine expects FIELD_DECLs in
> objc/objc-act.c:  finish_builtin_struct (type, "__builtin_ObjCString",
> omp-expand.c:  finish_builtin_struct (grid_attr_trees->kernel_launch_attributes_type,
> stor-layout.c:finish_builtin_struct (tree type, const char *name, tree fields,
> stor-layout.h:extern void finish_builtin_struct (tree, const char *, tree, tree,
> 
> Perhaps we could make them all to just use identifier_node
> but I am honestly not sure :)

Given finish_builtin_struct uses BUILTINS_LOCATION for the TYPE_DECL
and dwarf2out.c does

    case TYPE_DECL:
      /* Don't emit stubs for types unless they are needed by other DIEs.  
*/
      if (TYPE_DECL_SUPPRESS_DEBUG (decl))
        return;

      /* Don't bother trying to generate any DIEs to represent any of the
         normal built-in types for the language we are compiling.  */
      if (DECL_IS_BUILTIN (decl))
        return;

making them just all IDENTIFIER_NODE is fine I think.  At least for
the debuginfo part it shouldn't make any difference ...

Richard.

> Bootstrapped/regtested x86_64-linux, OK?
> 
> Honza
> 
> 	* coverage.c (build_fn_info_type, build_info, coverage_obj_init):
> 	Use make_node to build record type and pass true to
> 	finish_builtin_struct.
> 	* stor-layout.c (finish_record_layout): Add nodebug parameter.
> 	* stor-layout.h (finish_builtin_struct): Likewise.
> Index: coverage.c
> ===================================================================
> --- coverage.c	(revision 263696)
> +++ coverage.c	(working copy)
> @@ -780,7 +780,7 @@ build_var (tree fn_decl, tree type, int
>  static void
>  build_fn_info_type (tree type, unsigned counters, tree gcov_info_type)
>  {
> -  tree ctr_info = lang_hooks.types.make_type (RECORD_TYPE);
> +  tree ctr_info = make_node (RECORD_TYPE);
>    tree field, fields;
>    tree array_type;
>  
> @@ -797,7 +797,7 @@ build_fn_info_type (tree type, unsigned
>    DECL_CHAIN (field) = fields;
>    fields = field;
>    
> -  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE);
> +  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE, true);
>  
>    /* key */
>    field = build_decl (BUILTINS_LOCATION, FIELD_DECL, NULL_TREE,
> @@ -831,7 +831,7 @@ build_fn_info_type (tree type, unsigned
>    DECL_CHAIN (field) = fields;
>    fields = field;
>  
> -  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE);
> +  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE, true);
>  }
>  
>  /* Returns a CONSTRUCTOR for a gcov_fn_info.  DATA is
> @@ -963,7 +963,7 @@ build_info_type (tree type, tree fn_info
>    DECL_CHAIN (field) = fields;
>    fields = field;
>  
> -  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE);
> +  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE, true);
>  }
>  
>  /* Returns a CONSTRUCTOR for the gcov_info object.  INFO_TYPE is the
> @@ -1020,8 +1020,6 @@ build_info (tree info_type, tree fn_ary)
>  				      get_identifier (ctr_merge_functions[ix]),
>  				      TREE_TYPE (merge_fn_type));
>  	  DECL_EXTERNAL (merge_fn) = 1;
> -	  TREE_PUBLIC (merge_fn) = 1;
> -	  DECL_ARTIFICIAL (merge_fn) = 1;
>  	  TREE_NOTHROW (merge_fn) = 1;
>  	  /* Initialize assembler name so we can stream out. */
>  	  DECL_ASSEMBLER_NAME (merge_fn);
> @@ -1140,10 +1138,10 @@ coverage_obj_init (void)
>        n_counters++;
>    
>    /* Build the info and fn_info types.  These are mutually recursive.  */
> -  gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
> -  gcov_fn_info_type = lang_hooks.types.make_type (RECORD_TYPE);
> +  gcov_info_type = make_node (RECORD_TYPE);
> +  gcov_fn_info_type = make_node (RECORD_TYPE);
>    build_fn_info_type (gcov_fn_info_type, n_counters, gcov_info_type);
> -  gcov_info_type = lang_hooks.types.make_type (RECORD_TYPE);
> +  gcov_info_type = make_node (RECORD_TYPE);
>    gcov_fn_info_ptr_type = build_pointer_type
>      (build_qualified_type (gcov_fn_info_type, TYPE_QUAL_CONST));
>    build_info_type (gcov_info_type, gcov_fn_info_ptr_type);
> Index: stor-layout.c
> ===================================================================
> --- stor-layout.c	(revision 263696)
> +++ stor-layout.c	(working copy)
> @@ -2224,13 +2224,14 @@ finish_record_layout (record_layout_info
>  
>  /* Finish processing a builtin RECORD_TYPE type TYPE.  It's name is
>     NAME, its fields are chained in reverse on FIELDS.
> +   If NODEBUG is set, do not produce TYPE_DECL and STUB.
>  
>     If ALIGN_TYPE is non-null, it is given the same alignment as
>     ALIGN_TYPE.  */
>  
>  void
>  finish_builtin_struct (tree type, const char *name, tree fields,
> -		       tree align_type)
> +		       tree align_type, bool nodebug)
>  {
>    tree tail, next;
>  
> @@ -2251,14 +2252,15 @@ finish_builtin_struct (tree type, const
>      }
>  
>    layout_type (type);
> -#if 0 /* not yet, should get fixed properly later */
> -  TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
> -#else
> -  TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
> -				 TYPE_DECL, get_identifier (name), type);
> -#endif
> -  TYPE_STUB_DECL (type) = TYPE_NAME (type);
> -  layout_decl (TYPE_NAME (type), 0);
> +  if (nodebug)
> +    TYPE_NAME (type) = get_identifier (name);
> +  else
> +    {
> +      TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
> +				     TYPE_DECL, get_identifier (name), type);
> +      TYPE_STUB_DECL (type) = TYPE_NAME (type);
> +      layout_decl (TYPE_NAME (type), 0);
> +    }
>  }
>  
>  /* Calculate the mode, size, and alignment for TYPE.
> Index: stor-layout.h
> ===================================================================
> --- stor-layout.h	(revision 263696)
> +++ stor-layout.h	(working copy)
> @@ -43,7 +43,8 @@ extern void initialize_sizetypes (void);
>  
>  /* Finish up a builtin RECORD_TYPE. Give it a name and provide its
>     fields. Optionally specify an alignment, and then lay it out.  */
> -extern void finish_builtin_struct (tree, const char *, tree, tree);
> +extern void finish_builtin_struct (tree, const char *, tree, tree,
> +				   bool nodebug = false);
>  
>  /* Given a VAR_DECL, PARM_DECL, RESULT_DECL or FIELD_DECL node,
>     calculates the DECL_SIZE, DECL_SIZE_UNIT, DECL_ALIGN and DECL_MODE
> 
>
Jan Hubicka Aug. 23, 2018, 12:25 p.m. UTC | #9
> On Thu, 23 Aug 2018, Jan Hubicka wrote:
> 
> > Hi
> > this patch takes care of gcov.  There are two oddities. First that gcov uses
> > langhook to produce new records while asan gets around with make_node.
> > I think both are middle-end types and in the direction of separating front-ends
> > and middle-ends better the langhooks are not desirable.
> > 
> > The TYPE_STUB_DECL is produced by finish_builtin_struct.  This is function used
> > just few times but I am not sure if we don't want debug info on some of the
> > builtins, so I have added extra parameter.
> > 
> > config/darwin.c:  finish_builtin_struct (cfstring_type_node, "__builtin_CFString",
> > config/i386/i386.c:  finish_builtin_struct (type, "__processor_model", field_chain, NULL_TREE);
> > coverage.c:  finish_builtin_struct (ctr_info, "__gcov_ctr_info", fields, NULL_TREE, true);
> > coverage.c:  finish_builtin_struct (type, "__gcov_fn_info", fields, NULL_TREE, true);
> > coverage.c:  finish_builtin_struct (type, "__gcov_info", fields, NULL_TREE, true);
> > cp/decl.c:  finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
> > cp/rtti.c:  finish_builtin_struct (pseudo_type, pseudo_name, fields, NULL_TREE);
> > hsa-brig.c:  finish_builtin_struct (variable_info_type, "__hsa_variable_info", id_f2,
> > hsa-brig.c:  finish_builtin_struct (kernel_info_type, "__hsa_kernel_info", id_f5,
> > hsa-brig.c:  finish_builtin_struct (hsa_image_desc_type, "__hsa_image_desc", id_f5,
> > hsa-gen.c:      finish_builtin_struct (*hsa_kernel_dispatch_type, "__hsa_kernel_dispatch",
> > objc/objc-act.c:  /* NB: The finish_builtin_struct() routine expects FIELD_DECLs in
> > objc/objc-act.c:  finish_builtin_struct (type, "__builtin_ObjCString",
> > omp-expand.c:  finish_builtin_struct (grid_attr_trees->kernel_launch_attributes_type,
> > stor-layout.c:finish_builtin_struct (tree type, const char *name, tree fields,
> > stor-layout.h:extern void finish_builtin_struct (tree, const char *, tree, tree,
> > 
> > Perhaps we could make them all to just use identifier_node
> > but I am honestly not sure :)
> 
> Given finish_builtin_struct uses BUILTINS_LOCATION for the TYPE_DECL
> and dwarf2out.c does
> 
>     case TYPE_DECL:
>       /* Don't emit stubs for types unless they are needed by other DIEs.  
> */
>       if (TYPE_DECL_SUPPRESS_DEBUG (decl))
>         return;
> 
>       /* Don't bother trying to generate any DIEs to represent any of the
>          normal built-in types for the language we are compiling.  */
>       if (DECL_IS_BUILTIN (decl))
>         return;
> 
> making them just all IDENTIFIER_NODE is fine I think.  At least for
> the debuginfo part it shouldn't make any difference ...

OK, that is a good observation :) I will re-test variant of patch doing
identifier pointers.   I am bit concerned about the C++/objc use that may later 
use the type produced with the assumtion that it looks like C++/objc type :)

Honza
diff mbox series

Patch

Index: tree.c
===================================================================
--- tree.c	(revision 263699)
+++ tree.c	(working copy)
@@ -5525,9 +5525,14 @@  find_decls_types_r (tree *tp, int *ws, v
       fld_worklist_push (TYPE_POINTER_TO (t), fld);
       fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
       fld_worklist_push (TYPE_NAME (t), fld);
-      /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO.  We do not stream
-	 them and thus do not and want not to reach unused pointer types
-	 this way.  */
+      /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
+	 lists, we may look types up in these lists and use them while
+	 optimizing the function body.  Thus we need to free lang data
+	 in them.  */
+      if (TREE_CODE (t) == POINTER_TYPE)
+        fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
+      if (TREE_CODE (t) == REFERENCE_TYPE)
+        fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
       if (!POINTER_TYPE_P (t))
 	fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
       /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types.  */