User account creation filtered due to spam.

Bug 54534 - [4.7 Regression] Missing location for unused variable
Summary: [4.7 Regression] Missing location for unused variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.7.2
: P1 normal
Target Milestone: 4.7.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-09 07:41 UTC by Jan Kratochvil
Modified: 2012-09-11 10:43 UTC (History)
4 users (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-09-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2012-09-09 07:41:41 UTC
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
Comment 1 Richard Biener 2012-09-10 10:25:57 UTC
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?
Comment 2 Joel Brobecker 2012-09-10 21:59:26 UTC
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!)
Comment 3 Richard Biener 2012-09-11 09:49:27 UTC
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.
Comment 4 Jan Hubicka 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...
Comment 5 rguenther@suse.de 2012-09-11 10:38:32 UTC
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.
Comment 6 Richard Biener 2012-09-11 10:43:17 UTC
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
Comment 7 Richard Biener 2012-09-11 10:43:40 UTC
Fixed.