[PATCH] Fix PR29299

Richard Guenther rguenther@suse.de
Mon Oct 9 15:34:00 GMT 2006


This fixes PR29299 where we failed to honor "used" attribute on function
local statics.  Fixed by looking at DECL_PRESERVE_P in the varpool
machinery.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs


2006-10-09  Richard Guenther  <rguenther@suse.de>

	PR middle-end/29299
	* cgraph.c (decide_is_variable_needed): Use DECL_PRESERVE_P to
	check for "used" attribute.  Do so for -funit-at-a-time, too.

	* gcc.dg/pr29299.c: New testcase.

Index: cgraph.c
===================================================================
*** cgraph.c	(revision 117569)
--- cgraph.c	(working copy)
*************** bool
*** 939,948 ****
  decide_is_variable_needed (struct cgraph_varpool_node *node, tree decl)
  {
    /* If the user told us it is used, then it must be so.  */
!   if (node->externally_visible || node->force_output)
!     return true;
!   if (!flag_unit_at_a_time
!       && lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
      return true;
  
    /* ??? If the assembler name is set by hand, it is possible to assemble
--- 939,947 ----
  decide_is_variable_needed (struct cgraph_varpool_node *node, tree decl)
  {
    /* If the user told us it is used, then it must be so.  */
!   if (node->externally_visible
!       || node->force_output
!       || DECL_PRESERVE_P (decl))
      return true;
  
    /* ??? If the assembler name is set by hand, it is possible to assemble

/* { dg-do compile } */
/* { dg-options "-O" } */

static int bof __attribute__((used));
int foo()
{
	static int barbarbarbar __attribute__((used));
};

/* { dg-final { scan-assembler "barbarbarbar" } } */



More information about the Gcc-patches mailing list