C++ PATCH: PR 11530

Mark Mitchell mark@codesourcery.com
Tue Jul 29 02:03:00 GMT 2003


This patch fixes PR c++/11530, which Jan correctly deduced was coming
from a missing call to mark_used.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-07-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/11530
	* parser.c (cp_parser_postfix_expression): Do not call mark_used.
	* semantics.c (finish_id_expression): Call mark_used for all
	declarations.

2003-07-28  Jan Hubicka  <jh@suse.cz>

	PR c++/11530
	* g++.dg/opt/call1.C: New test.

Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.90
diff -c -5 -p -r1.90 parser.c
*** cp/parser.c	28 Jul 2003 11:06:30 -0000	1.90
--- cp/parser.c	29 Jul 2003 01:55:40 -0000
*************** cp_parser_postfix_expression (cp_parser 
*** 3426,3439 ****
  						     address_p);
        if (done)
  	return postfix_expression;
      }
  
-   /* Remember that there was a reference to this entity.  */
-   if (DECL_P (postfix_expression))
-     mark_used (postfix_expression);
- 
    /* Keep looping until the postfix-expression is complete.  */
    while (true)
      {
        if (idk == CP_ID_KIND_UNQUALIFIED
  	  && TREE_CODE (postfix_expression) == IDENTIFIER_NODE
--- 3426,3435 ----
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.337
diff -c -5 -p -r1.337 semantics.c
*** cp/semantics.c	28 Jul 2003 11:06:31 -0000	1.337
--- cp/semantics.c	29 Jul 2003 01:55:41 -0000
*************** finish_id_expression (tree id_expression
*** 2484,2506 ****
  		  return error_mark_node;
  		}
  	      *non_constant_expression_p = true;
  	    }
  	}
! 
!       if (scope)
! 	{
! 	  decl = (adjust_result_of_qualified_name_lookup 
! 		  (decl, scope, current_class_type));
! 	  if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
! 	    *qualifying_class = scope;
! 	  else if (!processing_template_decl)
! 	    decl = convert_from_reference (decl);
! 	  else if (TYPE_P (scope))
! 	    decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl);
! 	}
!       else if (TREE_CODE (decl) == NAMESPACE_DECL)
  	{
  	  error ("use of namespace `%D' as expression", decl);
  	  return error_mark_node;
  	}
        else if (DECL_CLASS_TEMPLATE_P (decl))
--- 2484,2495 ----
  		  return error_mark_node;
  		}
  	      *non_constant_expression_p = true;
  	    }
  	}
!       
!       if (TREE_CODE (decl) == NAMESPACE_DECL)
  	{
  	  error ("use of namespace `%D' as expression", decl);
  	  return error_mark_node;
  	}
        else if (DECL_CLASS_TEMPLATE_P (decl))
*************** finish_id_expression (tree id_expression
*** 2514,2543 ****
  	  error ("request for member `%D' is ambiguous in "
  		 "multiple inheritance lattice", id_expression);
  	  print_candidates (decl);
  	  return error_mark_node;
  	}
        else if (TREE_CODE (decl) == FIELD_DECL)
  	decl = finish_non_static_data_member (decl, current_class_ref,
  					      /*qualifying_scope=*/NULL_TREE);
        else if (is_overloaded_fn (decl))
  	{
  	  tree first_fn = OVL_CURRENT (decl);
  
  	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
  	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
! 	  
  	  if (TREE_CODE (first_fn) == FUNCTION_DECL
  	      && DECL_FUNCTION_MEMBER_P (first_fn))
  	    {
  	      /* A set of member functions.  */
  	      decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
  	      return finish_class_member_access_expr (decl, id_expression);
  	    }
- 	  else if (!really_overloaded_fn (decl))
- 	    /* not really overloaded function */
- 	    mark_used (first_fn);
  	}
        else
  	{
  	  if (TREE_CODE (decl) == VAR_DECL
  	      || TREE_CODE (decl) == PARM_DECL
--- 2503,2551 ----
  	  error ("request for member `%D' is ambiguous in "
  		 "multiple inheritance lattice", id_expression);
  	  print_candidates (decl);
  	  return error_mark_node;
  	}
+ 
+       /* Mark variable-like entities as used.  Functions are similarly
+ 	 marked either below or after overload resolution.  */
+       if (TREE_CODE (decl) == VAR_DECL
+ 	  || TREE_CODE (decl) == PARM_DECL
+ 	  || TREE_CODE (decl) == RESULT_DECL)
+ 	mark_used (decl);
+ 
+       if (scope)
+ 	{
+ 	  decl = (adjust_result_of_qualified_name_lookup 
+ 		  (decl, scope, current_class_type));
+ 	  if (TREE_CODE (decl) == FIELD_DECL || BASELINK_P (decl))
+ 	    *qualifying_class = scope;
+ 	  else if (!processing_template_decl)
+ 	    decl = convert_from_reference (decl);
+ 	  else if (TYPE_P (scope))
+ 	    decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl);
+ 	}
        else if (TREE_CODE (decl) == FIELD_DECL)
  	decl = finish_non_static_data_member (decl, current_class_ref,
  					      /*qualifying_scope=*/NULL_TREE);
        else if (is_overloaded_fn (decl))
  	{
  	  tree first_fn = OVL_CURRENT (decl);
  
  	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
  	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
! 
! 	  if (!really_overloaded_fn (decl))
! 	    mark_used (first_fn);
! 
  	  if (TREE_CODE (first_fn) == FUNCTION_DECL
  	      && DECL_FUNCTION_MEMBER_P (first_fn))
  	    {
  	      /* A set of member functions.  */
  	      decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
  	      return finish_class_member_access_expr (decl, id_expression);
  	    }
  	}
        else
  	{
  	  if (TREE_CODE (decl) == VAR_DECL
  	      || TREE_CODE (decl) == PARM_DECL
*************** finish_id_expression (tree id_expression
*** 2563,2574 ****
  	      tree path;
  	      
  	      path = currently_open_derived_class (DECL_CONTEXT (decl));
  	      perform_or_defer_access_check (TYPE_BINFO (path), decl);
  	    }
- 	  
- 	  mark_used (decl);
  	  
  	  if (! processing_template_decl)
  	    decl = convert_from_reference (decl);
  	}
        
--- 2571,2580 ----
Index: testsuite/g++.dg/opt/call1.C
===================================================================
RCS file: testsuite/g++.dg/opt/call1.C
diff -N testsuite/g++.dg/opt/call1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/opt/call1.C	29 Jul 2003 01:55:48 -0000
***************
*** 0 ****
--- 1,21 ----
+ // { dg-options "-O2" }
+ 
+ void a (void (*f)())
+ {
+   f();
+ }
+ 
+ struct RunState
+ {
+   static void runcallback() { }
+   static void wait()
+   {
+     a (runcallback);
+   }
+ };
+ 
+ int main()
+ {
+   RunState::wait();
+   return 0;
+ }



More information about the Gcc-patches mailing list