Patchwork [C] Always use TRANSLATION_UNIT_DECL as context

login
register
mail settings
Submitter Richard Guenther
Date Sept. 27, 2010, 9:25 a.m.
Message ID <alpine.LNX.2.00.1009271117180.8982@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/65823/
State New
Headers show

Comments

Richard Guenther - Sept. 27, 2010, 9:25 a.m.
On Mon, 27 Sep 2010, Jie Zhang wrote:

> On 09/27/2010 04:49 PM, Richard Guenther wrote:
> > On Sat, 25 Sep 2010, Jie Zhang wrote:
> > 
> > > On 09/17/2010 08:18 PM, Richard Guenther wrote:
> > > > 	* c-decl.c (pop_scope): Always set file-scope DECL_CONTEXT.
> > > 
> > > This change causes regressions on arm-none-eabi:
> > > 
> > > FAIL: gcc.c-torture/execute/builtins/abs-1.c compilation,  -O2 -flto
> > > UNRESOLVED: gcc.c-torture/execute/builtins/abs-1.c execution,  -O2 -flto
> > > 
> > > The compiler error messages are:
> > > 
> > > testsuite/gcc.c-torture/execute/builtins/abs-1.c:22:1: sorry,
> > > unimplemented:
> > > gimple bytecode streams do not support machine specific builtin functions
> > > on
> > > this target
> > > testsuite/gcc.c-torture/execute/builtins/abs-1-lib.c:22:1: sorry,
> > > unimplemented: gimple bytecode streams do not support machine specific
> > > builtin
> > > functions on this target
> > > testsuite/gcc.c-torture/execute/builtins/lib/main.c:13:1: sorry,
> > > unimplemented: gimple bytecode streams do not support machine specific
> > > builtin
> > > functions on this target
> > > compiler exited with status 1
> > > 
> > > I did some investigation, but don't know how to fix it.
> > > 
> > > The above change makes GCC always set file-scope DECL_CONTEXT. So when
> > > come to
> > > 
> > > static void
> > > lto_output_ts_decl_minimal_tree_pointers (struct output_block *ob, tree
> > > expr,
> > > 					  bool ref_p)
> > > {
> > >    lto_output_tree_or_ref (ob, DECL_NAME (expr), ref_p);
> > >    lto_output_tree_or_ref (ob, DECL_CONTEXT (expr), ref_p);
> > >    lto_output_location (ob, DECL_SOURCE_LOCATION (expr));
> > > }
> > > 
> > > with EXPR being a file scope function, DECL_CONEXT (expr) is the
> > > translation
> > > unit which contains the function. Then
> > > 
> > >    lto_output_tree_or_ref (ob, DECL_CONTEXT (expr), ref_p);
> > > 
> > > writes out the whole translation unit including all the builtin functions.
> > > Finally, in lto_output_builtin_tree, a "sorry" is called with the above
> > > error
> > > message since ARM target does not have targetm.builtin_decl.
> > > 
> > > I don't know how to fix this. Defining targetm.builtin_decl for ARM should
> > > fix
> > > it. But I'm not sure if we really want to output all builtins for each
> > > translation unit. This regression should exist for all targets which don't
> > > provide targetm.builtin_decl.
> > 
> > Yes, this writes all declarations in the TRANSLATION_UNIT_DECLs BLOCK
> > tree.  Does the following fix it?
> > 
> > Index: tree.c
> > ===================================================================
> > --- tree.c      (revision 164590)
> > +++ tree.c      (working copy)
> > @@ -4585,6 +4690,8 @@ free_lang_data_in_decl (tree decl)
> >           nesting beyond this point. */
> >         DECL_CONTEXT (decl) = NULL_TREE;
> >       }
> > +  else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL)
> > +    DECL_INITIAL (decl) = NULL_TREE;
> >   }
> > 
> Not yet. This change causes an ICE.

Ick ...

so I guess we should instead try to not push builtins to the global
scope.  Like with

 

Joseph might have an idea here (I also see external_scope being used,
but I'm not sure what functions actually end up in that).

Does the above help?

Thanks,
Richard.
Jie Zhang - Sept. 27, 2010, 9:44 a.m.
On 09/27/2010 05:25 PM, Richard Guenther wrote:
> so I guess we should instead try to not push builtins to the global
> scope.  Like with
>
> Index: c-decl.c
> ===================================================================
> --- c-decl.c    (revision 164591)
> +++ c-decl.c    (working copy)
> @@ -1142,6 +1142,10 @@ pop_scope (void)
>                           "inline function %q+D declared but never
> defined", p);
>                DECL_EXTERNAL (p) = 1;
>              }
> +         else if (TREE_CODE (p) == FUNCTION_DECL
> +&&  DECL_BUILT_IN (p))
> +           /* Do not put builtin functions into the outermost BLOCK.  */
> +           continue;
>
>            goto common_symbol;
>
>
> Joseph might have an idea here (I also see external_scope being used,
> but I'm not sure what functions actually end up in that).
>
> Does the above help?
>
This change fixed the original regression. But it caused some new ICEs. Like

Run cc1 under GDB:

(gdb) set args -fpreprocessed memcpy-chk-lib.i -quiet -dumpbase 
memcpy-chk-lib.c -auxbase memcpy-chk-lib -O3 -fomit-frame-pointer -o 
memcpy-chk-lib.s
(gdb) r
Starting program: 
/home/jie/sources/gcc/builds/build-arm-eabi.git/gcc/cc1 -fpreprocessed 
memcpy-chk-lib.i -quiet -dumpbase memcpy-chk-lib.c -auxbase 
memcpy-chk-lib -O3 -fomit-frame-pointer -o memcpy-chk-lib.s

Program received signal SIGSEGV, Segmentation fault.
0x00000000004c0931 in gt_ggc_mx_c_binding (x_p=0x7ffff6f771e0) at 
./gt-c-decl.h:92
(gdb) bt
#0  0x00000000004c0931 in gt_ggc_mx_c_binding (x_p=0x7ffff6f771e0) at 
./gt-c-decl.h:92
#1  0x00000000004c3027 in gt_ggc_mx_lang_tree_node (x_p=0x7ffff6f40b90) 
at ./gt-c-decl.h:561
#2  0x00000000004c215f in gt_ggc_mx_lang_tree_node (x_p=0x7ffff6f43700) 
at ./gt-c-decl.h:370
#3  0x000000000084b4ff in gt_ggc_mx_cgraph_node (x_p=0x7ffff6f92000) at 
gtype-desc.c:524
#4  0x0000000000851920 in gt_ggc_m_P11cgraph_node4htab 
(x_p=0x7ffff6e9e930) at gtype-desc.c:2432
#5  0x00000000007e722f in ggc_mark_root_tab (rt=0x11afce0) at 
../../../git/gcc/ggc-common.c:159
#6  0x00000000007e72cb in ggc_mark_roots () at 
../../../git/gcc/ggc-common.c:178
#7  0x000000000059c45f in ggc_collect () at ../../../git/gcc/ggc-page.c:1950
#8  0x00000000008f74b9 in execute_todo (flags=2083) at 
../../../git/gcc/passes.c:1306
#9  0x00000000008f7cef in execute_one_pass (pass=0x166c180) at 
../../../git/gcc/passes.c:1592
#10 0x00000000008f7e1b in execute_pass_list (pass=0x166c180) at 
../../../git/gcc/passes.c:1624
#11 0x00000000008f7e3c in execute_pass_list (pass=0x166bfa0) at 
../../../git/gcc/passes.c:1625
#12 0x00000000008f7e3c in execute_pass_list (pass=0x166b640) at 
../../../git/gcc/passes.c:1625
#13 0x0000000000a7e6e4 in tree_rest_of_compilation 
(fndecl=0x7ffff6f2af00) at ../../../git/gcc/tree-optimize.c:419
#14 0x0000000000cf1413 in cgraph_expand_function (node=0x7ffff6d952c0) 
at ../../../git/gcc/cgraphunit.c:1477
#15 0x0000000000cf16ab in cgraph_expand_all_functions () at 
../../../git/gcc/cgraphunit.c:1556
#16 0x0000000000cf1cd0 in cgraph_optimize () at 
../../../git/gcc/cgraphunit.c:1812
#17 0x0000000000cef817 in cgraph_finalize_compilation_unit () at 
../../../git/gcc/cgraphunit.c:1020
#18 0x00000000004c044c in c_write_global_declarations () at 
../../../git/gcc/c-decl.c:9748
#19 0x00000000009eb15f in compile_file () at ../../../git/gcc/toplev.c:967
#20 0x00000000009ed64a in do_compile () at ../../../git/gcc/toplev.c:2394
#21 0x00000000009ed718 in toplev_main (argc=12, argv=0x7fffffffe1b8) at 
../../../git/gcc/toplev.c:2435
#22 0x0000000000593d8c in main (argc=12, argv=0x7fffffffe1b8) at 
../../../git/gcc/main.c:36
(gdb) l
87	  struct c_binding * xlimit = x;
88	  while (ggc_test_and_set_mark (xlimit))
89	   xlimit = ((*xlimit).prev);
90	  while (x != xlimit)
91	    {
92	      switch (TREE_CODE ((*x).decl) == LABEL_DECL)
93	        {
94	        case 0:
95	          gt_ggc_m_9tree_node ((*x).u.type);
96	          break;
(gdb) p *x
$1 = {u = {type = 0x0, label = 0x0}, decl = 0x0, id = 0x0, prev = 
0x7ffff6f77210, shadowed = 0x0, depth = 0, invisible = 0, nested = 0, 
inner_comp = 0, in_struct = 0, locus = 0}
(gdb)
Richard Guenther - Sept. 27, 2010, 9:56 a.m.
On Mon, 27 Sep 2010, Jie Zhang wrote:

> On 09/27/2010 05:25 PM, Richard Guenther wrote:
> > so I guess we should instead try to not push builtins to the global
> > scope.  Like with
> > 
> > Index: c-decl.c
> > ===================================================================
> > --- c-decl.c    (revision 164591)
> > +++ c-decl.c    (working copy)
> > @@ -1142,6 +1142,10 @@ pop_scope (void)
> >                           "inline function %q+D declared but never
> > defined", p);
> >                DECL_EXTERNAL (p) = 1;
> >              }
> > +         else if (TREE_CODE (p) == FUNCTION_DECL
> > +&&  DECL_BUILT_IN (p))
> > +           /* Do not put builtin functions into the outermost BLOCK.  */
> > +           continue;
> > 
> >            goto common_symbol;
> > 
> > 
> > Joseph might have an idea here (I also see external_scope being used,
> > but I'm not sure what functions actually end up in that).
> > 
> > Does the above help?
> > 
> This change fixed the original regression. But it caused some new ICEs. Like
> 
> Run cc1 under GDB:

Hm, I will later look into this.  Btw, as arm has vectorizing intrinsics
it should better implement targetm.builtin_decl - that there is no
LTO testcase using those builtins is no execuse for it to not do that ;)

Richard.

> (gdb) set args -fpreprocessed memcpy-chk-lib.i -quiet -dumpbase
> memcpy-chk-lib.c -auxbase memcpy-chk-lib -O3 -fomit-frame-pointer -o
> memcpy-chk-lib.s
> (gdb) r
> Starting program: /home/jie/sources/gcc/builds/build-arm-eabi.git/gcc/cc1
> -fpreprocessed memcpy-chk-lib.i -quiet -dumpbase memcpy-chk-lib.c -auxbase
> memcpy-chk-lib -O3 -fomit-frame-pointer -o memcpy-chk-lib.s
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x00000000004c0931 in gt_ggc_mx_c_binding (x_p=0x7ffff6f771e0) at
> ./gt-c-decl.h:92
> (gdb) bt
> #0  0x00000000004c0931 in gt_ggc_mx_c_binding (x_p=0x7ffff6f771e0) at
> ./gt-c-decl.h:92
> #1  0x00000000004c3027 in gt_ggc_mx_lang_tree_node (x_p=0x7ffff6f40b90) at
> ./gt-c-decl.h:561
> #2  0x00000000004c215f in gt_ggc_mx_lang_tree_node (x_p=0x7ffff6f43700) at
> ./gt-c-decl.h:370
> #3  0x000000000084b4ff in gt_ggc_mx_cgraph_node (x_p=0x7ffff6f92000) at
> gtype-desc.c:524
> #4  0x0000000000851920 in gt_ggc_m_P11cgraph_node4htab (x_p=0x7ffff6e9e930) at
> gtype-desc.c:2432
> #5  0x00000000007e722f in ggc_mark_root_tab (rt=0x11afce0) at
> ../../../git/gcc/ggc-common.c:159
> #6  0x00000000007e72cb in ggc_mark_roots () at
> ../../../git/gcc/ggc-common.c:178
> #7  0x000000000059c45f in ggc_collect () at ../../../git/gcc/ggc-page.c:1950
> #8  0x00000000008f74b9 in execute_todo (flags=2083) at
> ../../../git/gcc/passes.c:1306
> #9  0x00000000008f7cef in execute_one_pass (pass=0x166c180) at
> ../../../git/gcc/passes.c:1592
> #10 0x00000000008f7e1b in execute_pass_list (pass=0x166c180) at
> ../../../git/gcc/passes.c:1624
> #11 0x00000000008f7e3c in execute_pass_list (pass=0x166bfa0) at
> ../../../git/gcc/passes.c:1625
> #12 0x00000000008f7e3c in execute_pass_list (pass=0x166b640) at
> ../../../git/gcc/passes.c:1625
> #13 0x0000000000a7e6e4 in tree_rest_of_compilation (fndecl=0x7ffff6f2af00) at
> ../../../git/gcc/tree-optimize.c:419
> #14 0x0000000000cf1413 in cgraph_expand_function (node=0x7ffff6d952c0) at
> ../../../git/gcc/cgraphunit.c:1477
> #15 0x0000000000cf16ab in cgraph_expand_all_functions () at
> ../../../git/gcc/cgraphunit.c:1556
> #16 0x0000000000cf1cd0 in cgraph_optimize () at
> ../../../git/gcc/cgraphunit.c:1812
> #17 0x0000000000cef817 in cgraph_finalize_compilation_unit () at
> ../../../git/gcc/cgraphunit.c:1020
> #18 0x00000000004c044c in c_write_global_declarations () at
> ../../../git/gcc/c-decl.c:9748
> #19 0x00000000009eb15f in compile_file () at ../../../git/gcc/toplev.c:967
> #20 0x00000000009ed64a in do_compile () at ../../../git/gcc/toplev.c:2394
> #21 0x00000000009ed718 in toplev_main (argc=12, argv=0x7fffffffe1b8) at
> ../../../git/gcc/toplev.c:2435
> #22 0x0000000000593d8c in main (argc=12, argv=0x7fffffffe1b8) at
> ../../../git/gcc/main.c:36
> (gdb) l
> 87	  struct c_binding * xlimit = x;
> 88	  while (ggc_test_and_set_mark (xlimit))
> 89	   xlimit = ((*xlimit).prev);
> 90	  while (x != xlimit)
> 91	    {
> 92	      switch (TREE_CODE ((*x).decl) == LABEL_DECL)
> 93	        {
> 94	        case 0:
> 95	          gt_ggc_m_9tree_node ((*x).u.type);
> 96	          break;
> (gdb) p *x
> $1 = {u = {type = 0x0, label = 0x0}, decl = 0x0, id = 0x0, prev =
> 0x7ffff6f77210, shadowed = 0x0, depth = 0, invisible = 0, nested = 0,
> inner_comp = 0, in_struct = 0, locus = 0}
> (gdb)
> 
> 
>
Richard Guenther - Sept. 27, 2010, 11:31 a.m.
On Mon, 27 Sep 2010, Richard Guenther wrote:

> On Mon, 27 Sep 2010, Jie Zhang wrote:
> 
> > On 09/27/2010 05:25 PM, Richard Guenther wrote:
> > > so I guess we should instead try to not push builtins to the global
> > > scope.  Like with
> > > 
> > > Index: c-decl.c
> > > ===================================================================
> > > --- c-decl.c    (revision 164591)
> > > +++ c-decl.c    (working copy)
> > > @@ -1142,6 +1142,10 @@ pop_scope (void)
> > >                           "inline function %q+D declared but never
> > > defined", p);
> > >                DECL_EXTERNAL (p) = 1;
> > >              }
> > > +         else if (TREE_CODE (p) == FUNCTION_DECL
> > > +&&  DECL_BUILT_IN (p))
> > > +           /* Do not put builtin functions into the outermost BLOCK.  */
> > > +           continue;
> > > 
> > >            goto common_symbol;
> > > 
> > > 
> > > Joseph might have an idea here (I also see external_scope being used,
> > > but I'm not sure what functions actually end up in that).
> > > 
> > > Does the above help?
> > > 
> > This change fixed the original regression. But it caused some new ICEs. Like
> > 
> > Run cc1 under GDB:
> 
> Hm, I will later look into this.  Btw, as arm has vectorizing intrinsics
> it should better implement targetm.builtin_decl - that there is no
> LTO testcase using those builtins is no execuse for it to not do that ;)

It works on x86-64 if I comment its builtin_decl support with the
single expected FAIL of gcc.dg/lto/20090206-1_0.c
(which relies on proper target builtin streaming).

So I think this is ineed an issue of the backend not properly keeping
the builtins life if they are not used.

Richard.

> Richard.
> 
> > (gdb) set args -fpreprocessed memcpy-chk-lib.i -quiet -dumpbase
> > memcpy-chk-lib.c -auxbase memcpy-chk-lib -O3 -fomit-frame-pointer -o
> > memcpy-chk-lib.s
> > (gdb) r
> > Starting program: /home/jie/sources/gcc/builds/build-arm-eabi.git/gcc/cc1
> > -fpreprocessed memcpy-chk-lib.i -quiet -dumpbase memcpy-chk-lib.c -auxbase
> > memcpy-chk-lib -O3 -fomit-frame-pointer -o memcpy-chk-lib.s
> > 
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x00000000004c0931 in gt_ggc_mx_c_binding (x_p=0x7ffff6f771e0) at
> > ./gt-c-decl.h:92
> > (gdb) bt
> > #0  0x00000000004c0931 in gt_ggc_mx_c_binding (x_p=0x7ffff6f771e0) at
> > ./gt-c-decl.h:92
> > #1  0x00000000004c3027 in gt_ggc_mx_lang_tree_node (x_p=0x7ffff6f40b90) at
> > ./gt-c-decl.h:561
> > #2  0x00000000004c215f in gt_ggc_mx_lang_tree_node (x_p=0x7ffff6f43700) at
> > ./gt-c-decl.h:370
> > #3  0x000000000084b4ff in gt_ggc_mx_cgraph_node (x_p=0x7ffff6f92000) at
> > gtype-desc.c:524
> > #4  0x0000000000851920 in gt_ggc_m_P11cgraph_node4htab (x_p=0x7ffff6e9e930) at
> > gtype-desc.c:2432
> > #5  0x00000000007e722f in ggc_mark_root_tab (rt=0x11afce0) at
> > ../../../git/gcc/ggc-common.c:159
> > #6  0x00000000007e72cb in ggc_mark_roots () at
> > ../../../git/gcc/ggc-common.c:178
> > #7  0x000000000059c45f in ggc_collect () at ../../../git/gcc/ggc-page.c:1950
> > #8  0x00000000008f74b9 in execute_todo (flags=2083) at
> > ../../../git/gcc/passes.c:1306
> > #9  0x00000000008f7cef in execute_one_pass (pass=0x166c180) at
> > ../../../git/gcc/passes.c:1592
> > #10 0x00000000008f7e1b in execute_pass_list (pass=0x166c180) at
> > ../../../git/gcc/passes.c:1624
> > #11 0x00000000008f7e3c in execute_pass_list (pass=0x166bfa0) at
> > ../../../git/gcc/passes.c:1625
> > #12 0x00000000008f7e3c in execute_pass_list (pass=0x166b640) at
> > ../../../git/gcc/passes.c:1625
> > #13 0x0000000000a7e6e4 in tree_rest_of_compilation (fndecl=0x7ffff6f2af00) at
> > ../../../git/gcc/tree-optimize.c:419
> > #14 0x0000000000cf1413 in cgraph_expand_function (node=0x7ffff6d952c0) at
> > ../../../git/gcc/cgraphunit.c:1477
> > #15 0x0000000000cf16ab in cgraph_expand_all_functions () at
> > ../../../git/gcc/cgraphunit.c:1556
> > #16 0x0000000000cf1cd0 in cgraph_optimize () at
> > ../../../git/gcc/cgraphunit.c:1812
> > #17 0x0000000000cef817 in cgraph_finalize_compilation_unit () at
> > ../../../git/gcc/cgraphunit.c:1020
> > #18 0x00000000004c044c in c_write_global_declarations () at
> > ../../../git/gcc/c-decl.c:9748
> > #19 0x00000000009eb15f in compile_file () at ../../../git/gcc/toplev.c:967
> > #20 0x00000000009ed64a in do_compile () at ../../../git/gcc/toplev.c:2394
> > #21 0x00000000009ed718 in toplev_main (argc=12, argv=0x7fffffffe1b8) at
> > ../../../git/gcc/toplev.c:2435
> > #22 0x0000000000593d8c in main (argc=12, argv=0x7fffffffe1b8) at
> > ../../../git/gcc/main.c:36
> > (gdb) l
> > 87	  struct c_binding * xlimit = x;
> > 88	  while (ggc_test_and_set_mark (xlimit))
> > 89	   xlimit = ((*xlimit).prev);
> > 90	  while (x != xlimit)
> > 91	    {
> > 92	      switch (TREE_CODE ((*x).decl) == LABEL_DECL)
> > 93	        {
> > 94	        case 0:
> > 95	          gt_ggc_m_9tree_node ((*x).u.type);
> > 96	          break;
> > (gdb) p *x
> > $1 = {u = {type = 0x0, label = 0x0}, decl = 0x0, id = 0x0, prev =
> > 0x7ffff6f77210, shadowed = 0x0, depth = 0, invisible = 0, nested = 0,
> > inner_comp = 0, in_struct = 0, locus = 0}
> > (gdb)
> > 
> > 
> > 
> 
>
Steve Ellcey - Sept. 27, 2010, 7:35 p.m.
FYI: I am getting the gimple bytecode messages on my IA64 Linux and
HP-UX platforms as well when running the testsuite.

/proj/opensrc_nobackup/nightly2/src/trunk/gcc/testsuite/gcc.c-torture/compile/20000105-1.c:25:1: sorry, unimplemented: gimple bytecode streams do not support machine specific builtin functions on this target

Steve Ellcey
sje@cup.hp.com
Richard Guenther - Sept. 28, 2010, 8:36 a.m.
On Mon, 27 Sep 2010, Steve Ellcey wrote:

> FYI: I am getting the gimple bytecode messages on my IA64 Linux and
> HP-UX platforms as well when running the testsuite.
> 
> /proj/opensrc_nobackup/nightly2/src/trunk/gcc/testsuite/gcc.c-torture/compile/20000105-1.c:25:1: sorry, unimplemented: gimple bytecode streams do not support machine specific builtin functions on this target

Yep, that's a known issue now.  Really all targets with builtins
need to implement targetm.builtin_decl for LTO to work for them.

Richard.

Patch

Index: c-decl.c
===================================================================
--- c-decl.c    (revision 164591)
+++ c-decl.c    (working copy)
@@ -1142,6 +1142,10 @@  pop_scope (void)
                         "inline function %q+D declared but never 
defined", p);
              DECL_EXTERNAL (p) = 1;
            }
+         else if (TREE_CODE (p) == FUNCTION_DECL
+                  && DECL_BUILT_IN (p))
+           /* Do not put builtin functions into the outermost BLOCK.  */
+           continue;
 
          goto common_symbol;