CVS g++ new warning [-Winline -Werror -O1]

Nathan Sidwell nathan@codesourcery.com
Thu Mar 9 08:44:00 GMT 2000


Mark Mitchell wrote:
>   Could this be related to the __FUNCTION__ handling code?
Here's a patch and testcase. TREE_ASM_WRITTEN is no longer an indication
that this is __FUNCTION__. I skip all artificial decls in maybe_commonize_var.
tsubst_decl also made this assumption, and even though its effects were
harmless I've removed it.

The strange thing here is that you only get the message when the out of line
body of the function is emitted. In the test case, the tree inliner
appears to inline `a.baz ()'. The only way of provoking the warning for
A::baz was to make a pointer to it and use it. This is strange. I think the
functionality of maybe_commonize_var should be run after the tree of the
complete function has been built. At that point we'll really know whether
the static var was used or not and whether the tree inliner can be applied.
But notice that maybe_commonize_var can mangle the static var's name
depending on system characteristics. I suspect the correct solution is
to always mangle the static var's DECL_ASSEMBLER_NAME and set things up as
best one can. Then after the function's tree is built, walk it looking to
see for non-inlinable features. Does that sound right?

Is this patch ok (for now)?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-03-09  Nathan Sidwell  <nathan@codesourcery.com>

	* decl.c (maybe_commonize_var): Skip all artificial decls.
	* pt.c (tsubst_decl): Don't copy TREE_ASM_WRITTEN.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.560
diff -c -3 -p -r1.560 decl.c
*** decl.c	2000/03/08 17:09:15	1.560
--- decl.c	2000/03/09 16:30:14
*************** maybe_commonize_var (decl)
*** 7194,7200 ****
       linkage.  */
    if (TREE_STATIC (decl)
        /* Don't mess with __FUNCTION__.  */
!       && ! TREE_ASM_WRITTEN (decl)
        && current_function_decl
        && DECL_CONTEXT (decl) == current_function_decl
        && (DECL_THIS_INLINE (current_function_decl)
--- 7194,7200 ----
       linkage.  */
    if (TREE_STATIC (decl)
        /* Don't mess with __FUNCTION__.  */
!       && ! DECL_ARTIFICIAL (decl)
        && current_function_decl
        && DECL_CONTEXT (decl) == current_function_decl
        && (DECL_THIS_INLINE (current_function_decl)
*************** maybe_commonize_var (decl)
*** 7229,7235 ****
  	  if (TREE_PUBLIC (decl))
  	    DECL_ASSEMBLER_NAME (decl)
  	      = build_static_name (current_function_decl, DECL_NAME (decl));
! 	  else if (! DECL_ARTIFICIAL (decl))
  	    {
  	      cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
  	      cp_warning_at ("  you can work around this by removing the initializer", decl);
--- 7229,7235 ----
  	  if (TREE_PUBLIC (decl))
  	    DECL_ASSEMBLER_NAME (decl)
  	      = build_static_name (current_function_decl, DECL_NAME (decl));
! 	  else
  	    {
  	      cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl);
  	      cp_warning_at ("  you can work around this by removing the initializer", decl);
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.403
diff -c -3 -p -r1.403 pt.c
*** pt.c	2000/03/05 20:46:17	1.403
--- pt.c	2000/03/09 16:30:18
*************** tsubst_decl (t, args, type, in_decl)
*** 5924,5934 ****
  	    TREE_TYPE (r) = TREE_TYPE (DECL_INITIAL (r));
  	  }
  
- 	/* If the template variable was marked TREE_ASM_WRITTEN, that
- 	   means we don't need to write out any of the instantiations
- 	   either.  (__FUNCTION__ and its ilk are marked thusly.)  */
- 	TREE_ASM_WRITTEN (r) = TREE_ASM_WRITTEN (t);
- 
  	/* Even if the original location is out of scope, the newly
  	   substituted one is not.  */
  	if (TREE_CODE (r) == VAR_DECL)
--- 5924,5929 ----


More information about the Gcc-patches mailing list