Patchwork [C] Always use TRANSLATION_UNIT_DECL as context

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

Comments

Richard Guenther - Sept. 27, 2010, 8:49 a.m.
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?


Richard.
Jie Zhang - Sept. 27, 2010, 9:14 a.m.
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.

Run cc1 under GDB:

(gdb) set args -fpreprocessed main.i -quiet -dumpbase main.c -auxbase 
main -O2 -w -version -flto -fno-builtin-abs -o main.s
(gdb) r
Starting program: 
/home/jie/sources/gcc/builds/build-arm-eabi.git/gcc/cc1 -fpreprocessed 
main.i -quiet -dumpbase main.c -auxbase main -O2 -w -version -flto 
-fno-builtin-abs -o main.s
Program received signal SIGSEGV, Segmentation fault.
0x00000000004c044d in c_write_global_declarations () at 
../../../git/gcc/c-decl.c:9750
(gdb) bt
#0  0x00000000004c044d in c_write_global_declarations () at 
../../../git/gcc/c-decl.c:9750
#1  0x00000000009eb0e7 in compile_file () at ../../../git/gcc/toplev.c:967
#2  0x00000000009ed5d2 in do_compile () at ../../../git/gcc/toplev.c:2394
#3  0x00000000009ed6a0 in toplev_main (argc=15, argv=0x7fffffffe1c8) at 
../../../git/gcc/toplev.c:2435
#4  0x0000000000593d14 in main (argc=15, argv=0x7fffffffe1c8) at 
../../../git/gcc/main.c:36
(gdb) l
9745	     be emitted, output debug information for globals.  */
9746	  if (!seen_error ())
9747	    {
9748	      timevar_push (TV_SYMOUT);
9749	      FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
9750		c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
9751	      c_write_global_declarations_2 (BLOCK_VARS (ext_block));
9752	      timevar_pop (TV_SYMOUT);
9753	    }
9754

Patch

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;
 }