static int i; gcc -c -Wall -g 13.c:1:12: warning: ‘i’ defined but not used [-Wunused-variable] PASS: gcc (GCC) 4.5.4 PASS: gcc (GCC) 4.6.4 20120909 (prerelease) PASS: gcc (GCC) 4.8.0 20120909 (experimental) <1><2d>: Abbrev Number: 2 (DW_TAG_variable) <2e> DW_AT_name : i <30> DW_AT_decl_file : 1 <31> DW_AT_decl_line : 1 <32> DW_AT_type : <0x40> <36> DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 (DW_OP_addr: 0) (gdb) p i $1 = 0 FAIL: gcc (GCC) 4.7.2 20120909 (prerelease) <1><1d>: Abbrev Number: 2 (DW_TAG_variable) <1e> DW_AT_name : i <20> DW_AT_decl_file : 1 <21> DW_AT_decl_line : 1 <22> DW_AT_type : <0x26> (gdb) p i No symbol "i" in current context. Regression: 2012-09-07 -> 2012-09-08 It breaks GDB several testfiles such as: gdb.base/memattr.exp
I think reverting r191073 fixes it. Btw, I don't see how we preserve i on trunk. Honza? When reverting r191073 -ftoplevel-reorder breaks it. So IMHO it worked "by accident". How does it continue to work by accident on trunk?
Hello, here is another example in Ada where we are also missing the location information even though, at least on the surface, the variable is used: with Ada.Text_IO; use Ada.Text_IO; procedure Subprogram is X : String := "hello"; Y : String := "goodbye"; Z : constant String := X & Y; begin Put_Line (X); -- BREAK HERE Put_Line (Y); Put_Line (Z); end Subprogram; Trying to print the value of variables X and Y yield the same result (<optimized out>), because the location attribute is missing. I don't think it's a huge loss to not be able to print the value of unused variables, but I think that the example above is more problematic. Restoring the previous behavior, even if accidental, would really help... (thank you!)
I am testing Index: gcc/cgraph.h =================================================================== --- gcc/cgraph.h (revision 191174) +++ gcc/cgraph.h (working copy) @@ -951,7 +951,7 @@ varpool_can_remove_if_no_refs (struct va return (!node->force_output && !node->used_from_other_partition && ((DECL_COMDAT (node->decl) && !varpool_used_from_object_file_p (node)) - || !node->externally_visible + || (flag_toplevel_reorder && !node->externally_visible) || DECL_HAS_VALUE_EXPR_P (node->decl))); } which restores previous behavior.
Well, the patch really is quite symptomatic - i.e. dwarf2out should not forget about the decl when it is removed from varpool. The way things are supposed to work (I believe) is to call global_decl debug hook via emit_debug_global_declarations that is called from frontend at global decl wrapup time (i.e. the thing that is executed after whole compilation and should not be frontend specific :) I made some cleanups in this area as part of symtab work, but I do not see how those should affect the debug output...
On Tue, 11 Sep 2012, hubicka at gcc dot gnu.org wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54534 > > --- Comment #4 from Jan Hubicka <hubicka at gcc dot gnu.org> 2012-09-11 10:19:04 UTC --- > Well, the patch really is quite symptomatic - i.e. dwarf2out should not forget > about the decl when it is removed from varpool. > > The way things are supposed to work (I believe) is to call global_decl debug > hook via emit_debug_global_declarations that is called from frontend at global > decl wrapup time (i.e. the thing that is executed after whole compilation and > should not be frontend specific :) > > I made some cleanups in this area as part of symtab work, but I do not see how > those should affect the debug output... The regression is that it prints <optimized_out> which it really is. But at -O0 we don't IMHO want unused decls to go away. Not sure why it doesn't regress on trunk - somehow the decl is output anyway. Richard.
Author: rguenth Date: Tue Sep 11 10:43:13 2012 New Revision: 191176 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191176 Log: 2012-09-11 Richard Guenther <rguenther@suse.de> PR debug/54534 * cgraph.h (varpool_can_remove_if_no_refs): Restore dependence on flag_toplevel_reorder. Modified: branches/gcc-4_7-branch/gcc/ChangeLog branches/gcc-4_7-branch/gcc/cgraph.h
Fixed.