Bug 39524 - Duplicate C++ DW_TAG_variable breaking its DW_AT_location resolution
Summary: Duplicate C++ DW_TAG_variable breaking its DW_AT_location resolution
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-23 08:49 UTC by Jan Kratochvil
Modified: 2010-03-22 16:11 UTC (History)
3 users (show)

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


Attachments
gcc44-pr39524.patch (669 bytes, patch)
2009-03-23 10:14 UTC, Jakub Jelinek
Details | Diff
another candidate fix (384 bytes, patch)
2009-03-23 11:20 UTC, Dodji Seketeli
Details | Diff
gcc44-pr39524.patch (709 bytes, patch)
2009-03-23 13:52 UTC, Jakub Jelinek
Details | Diff
gcc44-pr39524.patch (667 bytes, patch)
2009-03-23 14:30 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2009-03-23 08:49:51 UTC
Tested on: GNU C++ 4.4.0 20090323 (experimental)    

Testcase:
------------------------------------------------------------------------------
namespace A
  {
    static int var2 = 2;
  }

int
func (void)
{
  using A::var2;

  return var2;
}
------------------------------------------------------------------------------
will generate (reduced):

 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
    <2f>   DW_AT_name        : (indirect string, offset: 0x42): func    
    <3d>   DW_AT_low_pc      : 0x0      
    <45>   DW_AT_high_pc     : 0xc      
    <4d>   DW_AT_frame_base  : 0x0      (location list)
 <2><55>: Abbrev Number: 3 (DW_TAG_lexical_block)
    <56>   DW_AT_low_pc      : 0x4      
    <5e>   DW_AT_high_pc     : 0xa      
 <3><66>: Abbrev Number: 4 (DW_TAG_imported_declaration)
    <69>   DW_AT_import      : <0x7f>   [Abbrev Number: 7 (DW_TAG_variable)]
 <1><76>: Abbrev Number: 6 (DW_TAG_namespace)
    <77>   DW_AT_name        : A        
 <2><7f>: Abbrev Number: 7 (DW_TAG_variable)
    <80>   DW_AT_name        : (indirect string, offset: 0x34): var2    
    <84>   DW_AT_decl_file   : 1        
    <85>   DW_AT_decl_line   : 3        
    <86>   DW_AT_type        : <0x6f>   
    <8a>   DW_AT_declaration : 1        
 <2><8b>: Abbrev Number: 7 (DW_TAG_variable)
    <8c>   DW_AT_name        : (indirect string, offset: 0x34): var2    
    <84>   DW_AT_decl_file   : 1        
    <85>   DW_AT_decl_line   : 3        
    <92>   DW_AT_type        : <0x6f>   
    <96>   DW_AT_declaration : 1        
 <1><98>: Abbrev Number: 8 (DW_TAG_variable)
    <99>   DW_AT_specification: <0x8b>  
    <9d>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0  (DW_OP_addr: 0)

You can see the code references the <7f> "var" instance but DW_AT_location is given by the <98> completion only for the <8b> "var" instance.

Also <7f> and <8b> have a name conflict as being in the same naming scope.

This problem causes a wrong evaluation by Archer archer-keiths-expr-cumulative branch (which is IMO right) for the more complex testcase - as it cannot find the right DW_AT_location there:
------------------------------------------------------------------------------
# archer-keiths-expr-cumulative=35ca449e9f1a4cd477df644f717bbe4e3362c486/gdb -q ./outer
(gdb) l 1
1       #include <stdlib.h>
2
3       namespace A
4         {
5           static int var = 2;
6         }
7
8       int
9       main (void)
10      {
11        int var = 1;
12      
13        if (var != 1)         /* var-is-1 */
14          abort ();
15      
16        {
17          using A::var;
18      
19          if (var != 2)       /* var-is-2 */
20            abort ();
21        }
22      
23        return 0;             /* break-here */
24      }
(gdb) b 13
Breakpoint 1 at 0x4005a7: file outer.C, line 13.
(gdb) r
Starting program: /tmp/outer 

Breakpoint 1, main () at outer.C:13
13        if (var != 1)         /* var-is-1 */
(gdb) p var
$1 = 1
(gdb) adv 19
main () at outer.C:19
19          if (var != 2)       /* var-is-2 */
(gdb) p var
$2 = 1
^^^^^^ Wrong GDB evaluation.
(gdb) adv 23
main () at outer.C:23
23        return 0;             /* break-here */
(gdb) q
------------------------------------------------------------------------------
Comment 1 Jakub Jelinek 2009-03-23 10:14:57 UTC
Created attachment 17517 [details]
gcc44-pr39524.patch

Could you please test this with gdb/archer testsuite?  I'm going to bootstrap/regtest it in gcc in the mean time.
Comment 2 Dodji Seketeli 2009-03-23 11:20:13 UTC
Created attachment 17518 [details]
another candidate fix

I was looking at this bug when I saw Jakub's patch :)
After talking with Jakub a little bit I felt I could post attch the patch here as well, before full regtest.

Jan, would it be possible to test this patch as well against your gdb environment ? I have regtested it for the c++ FE, but it needs regtesting for all the FEs I think.
Comment 3 Jan Kratochvil 2009-03-23 11:32:32 UTC
One fix should be enough next time, thanks.
Going to gdb-regression test both the patches (in Fedora GCC on Fedora 11).
Comment 4 Jakub Jelinek 2009-03-23 13:52:26 UTC
Created attachment 17520 [details]
gcc44-pr39524.patch

Modified Dodji's patch I've actually bootstrapped/regtested (neither of the patches caused any regressions).  I've moved the test after Fortran COMMON handling, there we update the DW_AT_location if it was missing before etc., and added a check if the preexisting old_die is in the right context just to be sure.
Comment 5 Jakub Jelinek 2009-03-23 14:30:20 UTC
Created attachment 17521 [details]
gcc44-pr39524.patch

Argh, sorry, actually this patch, not the one I've attached in the previous comment.
Comment 6 Jakub Jelinek 2009-03-23 23:21:53 UTC
Subject: Bug 39524

Author: jakub
Date: Mon Mar 23 23:21:38 2009
New Revision: 145018

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145018
Log:
	PR debug/39524
	* dwarf2out.c (gen_variable_die): Avoid adding duplicate declaration
	nodes.

	* g++.dg/debug/dwarf2/imported-decl-1.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/imported-decl-1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Dodji Seketeli 2010-03-22 16:11:59 UTC
This got fixed in 4.4 but the PR never got closed. Closing now.