This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
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.
Do you have an example code?
Created an attachment (id=12360) [edit] compile with "gcc -O -S t.c"
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
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
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
Fixed.
Not yet for -fno-unit-at-a-time.
Reopening because it is not fixed for non unit at a time mode (-O0 for C).
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.
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
Patch for non-unit-at-a-time comitted now.
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