Bug 43325 - [4.5 Regression] C++ external inner reference does not override outer scope
Summary: [4.5 Regression] C++ external inner reference does not override outer scope
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Dodji Seketeli
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-10 19:15 UTC by Jan Kratochvil
Modified: 2010-04-01 18:55 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-03-31 09:35:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2010-03-10 19:15:08 UTC
namespace S
  {
    int f ()
      {
        int i = 42;
        {
          extern int i;
          return i;
        }
      }
  }

generates DWARF:
# Grossly simplified.
 <1><2d>: Abbrev Number: 2 (DW_TAG_namespace)
    <2e>   DW_AT_name        : S
 <2><36>: Abbrev Number: 3 (DW_TAG_subprogram)
    <37>   DW_AT_external    : 1
    <38>   DW_AT_name        : f
    <3c>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x49): _ZN1S1fEv
    <61>   DW_AT_low_pc      : 0x0
    <69>   DW_AT_high_pc     : 0x13
    <71>   DW_AT_frame_base  : 0x0      (location list)
 <3><75>: Abbrev Number: 7 (DW_TAG_lexical_block)
    <76>   DW_AT_low_pc      : 0x4
    <7e>   DW_AT_high_pc     : 0x11
 <4><86>: Abbrev Number: 8 (DW_TAG_variable)
    <87>   DW_AT_name        : i
    <8f>   DW_AT_location    : 2 byte block: 91 6c      (DW_OP_fbreg: -20)
 <4><92>: Abbrev Number: 9 (DW_TAG_lexical_block)
    <93>   DW_AT_low_pc      : 0xb
    <9b>   DW_AT_high_pc     : 0x11
 <2><45>: Abbrev Number: 4 (DW_TAG_variable)
    <46>   DW_AT_name        : i
    <4a>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x40): _ZN1S1iE
    <52>   DW_AT_external    : 1
    <53>   DW_AT_declaration : 1

But the last DIE should have been <5><45> being in inner DW_TAG_lexical_block so that debugger would display external variable S::i in the inner block.

(I have inlined the DW_AT_specification reference in the dump above.)

Similar case in C works OK:
int
f (void)
{
  int i = 42;
  {
    extern int i;
    return i;
  }
}
Comment 1 Dodji Seketeli 2010-03-31 10:08:05 UTC
A patch was proposed at http://gcc.gnu.org/ml/gcc-patches/2010-03/msg01473.html
Comment 2 Dodji Seketeli 2010-04-01 18:54:47 UTC
Subject: Bug 43325

Author: dodji
Date: Thu Apr  1 18:54:30 2010
New Revision: 157928

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157928
Log:
Fix for PR debug/43325

gcc/ChangeLog:
	PR debug/43325
	* dwarf2out.c (gen_variable_die): Allow debug info for variable
	re-declaration when it happens in a function.

gcc/testsuite/ChangeLog:
	PR debug/43325
	* c-c++-common/dwarf2/redeclaration-1.C: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/dwarf2/redeclaration-1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Dodji Seketeli 2010-04-01 18:55:29 UTC
Fixed in 4.5 (trunk).