Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 29299
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Jan Hubicka <hubicka@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Jeremy Fitzhardinge <jeremy@goop.org>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
t.c compile with "gcc -O -S t.c" text/plain 2006-09-30 16:46 67 bytes Edit
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 29299 depends on: Show dependency tree
Show dependency graph
Bug 29299 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2006-10-09 13:04 Opened: 2006-09-30 15:00
Adding the "used" attribute to locally-scoped static variables has no effect,
and they are not emitted into the output .s file.

I am using this in combination with the "section" attribute so I can collect
the data together; it doesn't matter to me that there's no useful mapping
between the C name and the assembler name.

------- Comment #1 From Andrew Pinski 2006-09-30 16:04 -------
Do you have an example code?

------- Comment #2 From Jeremy Fitzhardinge 2006-09-30 16:46 -------
Created an attachment (id=12360) [edit]
compile with "gcc -O -S t.c"

------- Comment #3 From Andrew Pinski 2006-09-30 19:40 -------
4.1.2 works:
        .local  bar.1279
        .comm   bar.1279,4,4
        .local  bof
        .comm   bof,4,4

while 4.2.0 does not:
        .local  bof
        .comm   bof,4,4

------- Comment #4 From Richard Guenther 2006-10-09 13:04 -------
We have

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

with "used" set on bar...

Now, the handler for attribute "used" sets DECL_PRESERVE_P on the decl, so
we might as well check that.

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

------- Comment #5 From Jan Hubicka 2006-10-15 16:20 -------
Subject: Bug 29299

Author: hubicka
Date: Sun Oct 15 16:20:06 2006
New Revision: 117746

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117746
Log:
        PR middle-end/29299
        * cgraphunit.c (cgraph_finalize_compilation_unit): Call
        process_function_and_variable_attributes on all variables, including
        those discovered during cgraph construction phase.

Added:
    trunk/gcc/testsuite/gcc.dg/pr29299.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cgraphunit.c
    trunk/gcc/testsuite/ChangeLog

------- Comment #6 From Andrew Pinski 2006-10-15 16:33 -------
Fixed.

------- Comment #7 From Richard Guenther 2006-10-15 17:03 -------
Not yet for -fno-unit-at-a-time.

------- Comment #8 From Andrew Pinski 2006-10-15 17:23 -------
Reopening because it is not fixed for non unit at a time mode (-O0 for C).

------- Comment #9 From Jan Hubicka 2006-10-15 22:33 -------
Subject: Re:  [4.2 Regresion] gcc "used" attribute has no effect on local-scope
static variables

> Reopening because it is not fixed for non unit at a time mode (-O0 for C).
-O0 gets it right, just -O1 -fno-unit-at-a-time fails, but I am testing
patch for this already.

------- Comment #10 From Jan Hubicka 2006-10-18 21:40 -------
Subject: Bug 29299

Author: hubicka
Date: Wed Oct 18 21:39:52 2006
New Revision: 117863

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117863
Log:
        PR middle-end/29299
        * cfgexpand.c (expand_used_vars_for_block): Vars marked used by user
        are used.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgexpand.c

------- Comment #11 From Jan Hubicka 2006-10-18 21:54 -------
Patch for non-unit-at-a-time comitted now.

------- Comment #12 From Jakub Jelinek 2007-06-26 11:52 -------
Subject: Bug 29299

Author: jakub
Date: Tue Jun 26 11:52:20 2007
New Revision: 126026

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126026
Log:
2006-10-18  Jan Hubicka  <jh@suse.cz>

        PR middle-end/29299
        * cfgexpand.c (expand_used_vars_for_block): Vars marked used by user
        are used.

2006-10-15  Jan Hubicka  <jh@suse.cz>
            Richard Guenther  <rguenther@suse.de>

        PR middle-end/29299
        * cgraphunit.c (cgraph_finalize_compilation_unit): Call
        process_function_and_variable_attributes on all variables, including
        those discovered during cgraph construction phase.

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

Added:
    branches/redhat/gcc-4_1-branch/gcc/testsuite/gcc.dg/pr29299.c
Modified:
    branches/redhat/gcc-4_1-branch/gcc/ChangeLog
    branches/redhat/gcc-4_1-branch/gcc/cfgexpand.c
    branches/redhat/gcc-4_1-branch/gcc/cgraphunit.c
    branches/redhat/gcc-4_1-branch/gcc/testsuite/ChangeLog

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug