This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C linkage patch


rest_of_decl_compilation was making the invalid assumption that a VAR_DECL
with a null DECL_INIT was a 'tentative definition', a concept that only
applies to C.  This was causing unnecessary deferral of things in C++, and
presumably other languages as well.

This patch also extends the handling of DECL_COMDAT in
wrapup_global_declarations to VAR_DECLs as well as FUNCTION_DECLs.

Applied to trunk only.

2001-02-26  Jason Merrill  <jason@redhat.com>

	* c-decl.c (finish_decl): Set DECL_DEFER_OUTPUT on tentative file-scope
	definitions.
	* toplev.c (rest_of_decl_compilation): Check DECL_DEFER_OUTPUT to
	recognize a tentative definition.  Lose obsolete code.

	* toplev.c (wrapup_global_declarations): Don't emit DECL_COMDAT
	variables unless necessary, either.

*** c-decl.c.~1~	Wed Feb 21 11:50:00 2001
--- c-decl.c	Mon Feb 26 11:02:10 2001
*************** finish_decl (decl, init, asmspec_tree)
*** 3608,3616 ****
        maybe_objc_check_decl (decl);
  
        if (!DECL_CONTEXT (decl))
! 	rest_of_decl_compilation (decl, asmspec,
! 				  (DECL_CONTEXT (decl) == 0
! 				   || TREE_ASM_WRITTEN (decl)), 0);
        else
  	{
  	  if (asmspec)
--- 3612,3628 ----
        maybe_objc_check_decl (decl);
  
        if (!DECL_CONTEXT (decl))
! 	{
! 	  if (DECL_INITIAL (decl) == NULL_TREE
! 	      || DECL_INITIAL (decl) == error_mark_node)
! 	    /* Don't output anything
! 	       when a tentative file-scope definition is seen.
! 	       But at end of compilation, do output code for them.  */
! 	    DECL_DEFER_OUTPUT (decl) = 1;
! 	  rest_of_decl_compilation (decl, asmspec,
! 				    (DECL_CONTEXT (decl) == 0
! 				     || TREE_ASM_WRITTEN (decl)), 0);
! 	}
        else
  	{
  	  if (asmspec)
*** toplev.c.~1~	Wed Feb 21 11:50:01 2001
--- toplev.c	Mon Feb 26 11:02:17 2001
*************** wrapup_global_declarations (vec, len)
*** 1940,1947 ****
  	     defined in a main file, as opposed to an include file.  */
  
  	  if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
! 	      && (! TREE_READONLY (decl)
! 		  || TREE_PUBLIC (decl)
  		  || (!optimize
  		      && flag_keep_static_consts
  		      && !DECL_ARTIFICIAL (decl))
--- 1940,1947 ----
  	     defined in a main file, as opposed to an include file.  */
  
  	  if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
! 	      && (((! TREE_READONLY (decl) || TREE_PUBLIC (decl))
! 		   && !DECL_COMDAT (decl))
  		  || (!optimize
  		      && flag_keep_static_consts
  		      && !DECL_ARTIFICIAL (decl))
*************** rest_of_decl_compilation (decl, asmspec,
*** 2562,2581 ****
      {
        timevar_push (TV_VARCONST);
        make_decl_rtl (decl, asmspec);
!       /* Initialized extern variable exists to be replaced
! 	 with its value, or represents something that will be
! 	 output in another file.  */
!       if (! (TREE_CODE (decl) == VAR_DECL
! 	     && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
! 	     && DECL_INITIAL (decl) != 0
! 	     && DECL_INITIAL (decl) != error_mark_node))
! 	/* Don't output anything
! 	     when a tentative file-scope definition is seen.
! 	     But at end of compilation, do output code for them.  */
! 	if (! (! at_end && top_level
! 	       && (DECL_INITIAL (decl) == 0
! 		   || DECL_INITIAL (decl) == error_mark_node)))
! 	  assemble_variable (decl, top_level, at_end, 0);
        if (decl == last_assemble_variable_decl)
  	{
  	  ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
--- 2562,2572 ----
      {
        timevar_push (TV_VARCONST);
        make_decl_rtl (decl, asmspec);
!       /* Don't output anything
! 	 when a tentative file-scope definition is seen.
! 	 But at end of compilation, do output code for them.  */
!       if (at_end || !DECL_DEFER_OUTPUT (decl))
! 	assemble_variable (decl, top_level, at_end, 0);
        if (decl == last_assemble_variable_decl)
  	{
  	  ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]