Bug 39471 - DW_TAG_imported_module should be used (not DW_TAG_imported_declaration)
Summary: DW_TAG_imported_module should be used (not DW_TAG_imported_declaration)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-16 14:41 UTC by Jan Kratochvil
Modified: 2009-03-17 17:56 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-pr39471.patch (835 bytes, patch)
2009-03-16 20:55 UTC, Jakub Jelinek
Details | Diff
gcc44-pr39471.patch (1006 bytes, patch)
2009-03-17 07:46 UTC, Jakub Jelinek
Details | Diff
gcc44-local-imported-decl.patch (932 bytes, patch)
2009-03-17 08:52 UTC, Jakub Jelinek
Details | Diff
gcc44-local-imported-decl.patch (1.22 KB, patch)
2009-03-17 12:28 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-16 14:41:52 UTC
Regression from g++-4.3 for GNU C++ 4.4.0 20090315 (experimental)
(+also for 4.4.0 20090313 (Red Hat 4.4.0-0.26))
For full namespace import one should use DW_TAG_imported_module.

1:namespace A
2:{
3:  int i = 1;
4:}
5:
6:int
7:main ()
8:{
9:  using namespace A;
10:  i = 2;
11:  return 0;
12:}

Using g++-4.4 DWARF one must use `A::i' at `main' in the debugger.
The whole namespace `A' should be imported there instead.

WRONG g++-4.4 debuginfo:
    < c>   DW_AT_producer    : (indirect string, offset: 0x0): GNU C++ 4.4.0 20090315 (experimental)
 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
    <2f>   DW_AT_name        : (indirect string, offset: 0x7d): main    
 <2><51>: Abbrev Number: 3 (DW_TAG_lexical_block)
    <52>   DW_AT_low_pc      : 0x4      
    <5a>   DW_AT_high_pc     : 0x13     
 <3><62>: Abbrev Number: 4 (DW_TAG_imported_declaration)
    <65>   DW_AT_name        : A        
    <67>   DW_AT_import      : <0x74>   [Abbrev Number: 6 (DW_TAG_namespace)]
 <1><74>: Abbrev Number: 6 (DW_TAG_namespace)
    <75>   DW_AT_name        : A        
 <2><7d>: Abbrev Number: 7 (DW_TAG_variable)
    <7e>   DW_AT_name        : i        
    <82>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x74): _ZN1A1iE   

Correct g++-4.3 debuginfo:
    < c>   DW_AT_producer    : (indirect string, offset: 0x0): GNU C++ 4.3.2 20081105 (Red Hat 4.3.2-7)
 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
    <2f>   DW_AT_name        : (indirect string, offset: 0x80): main    
 <2><51>: Abbrev Number: 3 (DW_TAG_imported_module)
    <54>   DW_AT_import      : <0x60>   [Abbrev Number: 5 (DW_TAG_namespace)]
 <1><60>: Abbrev Number: 5 (DW_TAG_namespace)
    <61>   DW_AT_name        : A        
 <2><69>: Abbrev Number: 6 (DW_TAG_variable)
    <6a>   DW_AT_name        : i        
    <6e>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x77): _ZN1A1iE   
    <72>   DW_AT_type        : <0x59>   

It causes regressions on gdb.cp/namespace-using.exp for the GDB project Archer.
Comment 1 Jakub Jelinek 2009-03-16 20:55:54 UTC
Created attachment 17469 [details]
gcc44-pr39471.patch

Untested patch.  Dodji, any reason why you started emitting DW_TAG_imported_declaration for this instead of DW_TAG_imported_module?

Also, looking at the http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37410#c6
comment, I'm wondering about the "C++ doesn't allow that usage" part in the comment.  Isn't:

namespace A
{
  int i = 1;
  int j = 2;
}

namespace B
{
  int k = 3;
}

int k = 13;

int
main ()
{
  using namespace A;
  i++;
  j++;
  k++;
  {
    using B::k;
    k++;
  }
  return 0;
}

a testcase which needs IMPORTED_DECL with non-NAMESPACE_DECL IMPORTED_DECL_ASSOCIATED_DECL?
Comment 2 Jan Kratochvil 2009-03-16 21:37:44 UTC
Thanks although there is still excessive DW_AT_name:
 <3><422>: Abbrev Number: 12 (DW_TAG_imported_module)
    <425>   DW_AT_name        : A
    <427>   DW_AT_import      : <0x113> [Abbrev Number: 2 (DW_TAG_namespace)]

DW_AT_name looks as undefined for me for DW_TAG_imported_module and it certainly breaks the current Archer C++ implementation.
Comment 3 Jakub Jelinek 2009-03-17 07:46:14 UTC
Created attachment 17471 [details]
gcc44-pr39471.patch

So this patch instead?  C++ will never need non-NULL DECL_NAME on IMPORTED_DECL,
as it doesn't have the ability to rename imports like Fortran does.
Comment 4 Dodji Seketeli 2009-03-17 07:54:09 UTC
Subject: Re:  DW_TAG_imported_module should be used (not
 DW_TAG_imported_declaration)

jakub at gcc dot gnu dot org a écrit :
> ------- Comment #1 from jakub at gcc dot gnu dot org  2009-03-16 20:55 -------
> Created an attachment (id=17469)
>  --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17469&action=view)
> gcc44-pr39471.patch
> 
> Untested patch.  Dodji, any reason why you started emitting
> DW_TAG_imported_declaration for this instead of DW_TAG_imported_module?

I think this was just a confusion on my part.

Comment 5 Dodji Seketeli 2009-03-17 07:59:22 UTC
Subject: Re:  DW_TAG_imported_module should be used (not
 DW_TAG_imported_declaration)

jakub at gcc dot gnu dot org a écrit :

> So this patch instead?  C++ will never need non-NULL DECL_NAME on
> IMPORTED_DECL,
> as it doesn't have the ability to rename imports like Fortran does.

Hmmh, I think the non null name there is useful for namespace aliases in
C++, e.g.

namespace A {
  int foo;
}

void
f ()
{
  namespace B  =  A;
}

That namespace alias will be represented by a
DW_TAG_imported_declaration which DW_AT_name set to "B" and which
DW_AT_import is set to a reference to namespace A.

FWIW, the DWARF3 spec says at 3.2.3:

"A C++ namespace alias may be represented by an imported declaration
entry with a name attribute whose value is a null-terminated string
containing the alias name as it appears in the source program and an
import attribute whose value is a reference to the applicable original
namespace or namespace extension entry."
Comment 6 Dodji Seketeli 2009-03-17 08:08:55 UTC
Subject: Re:  DW_TAG_imported_module should be used (not
 DW_TAG_imported_declaration)

dodji at redhat dot com a écrit :

> Hmmh, I think the non null name there is useful for namespace aliases in
> C++

Ah, no. We won't be going through the USING_STMT code path in case of
namespace aliases, sorry. My last comment was irrelevant.


Comment 7 Jakub Jelinek 2009-03-17 08:52:49 UTC
Created attachment 17472 [details]
gcc44-local-imported-decl.patch

Incremental patch to emit DW_TAG_imported_declaration DIEs (other than namespace aliases) in the right lexical blocks.

Possible testcase for gdb:
namespace A
{
  int i = 1;
  int j = 2;
}

namespace B
{
  int k = 3;
}

int k = 13;

void
foo ()
{
  using namespace A;
  i++;
  j++;
  k++;
  {
    using B::k;
    k++;
  }
}

template <int N>
void
bar ()
{
  using namespace A;
  i++;
  j++;
  k++;
  {
    using B::k;
    k++;
  }
}

int
main ()
{
  foo ();
  bar<0> ();
  bar<6> ();
}

Concerning:
"We won't be going through the USING_STMT code path in case of We won't be going through the USING_STMT code path in case of namespace aliases, sorry. My last comment was irrelevant."
we really should be going through USING_STMT or something similar for namespace aliases as well, see PR37890.  Given that namespace aliases are just emitted using gen_namespace_die, perhaps just adding the NAMESPACE_DECL to BLOCK_VARS would be sufficient.
Comment 8 Dodji Seketeli 2009-03-17 10:02:12 UTC
Subject: Re:  DW_TAG_imported_module should be used (not
 DW_TAG_imported_declaration)

jakub at gcc dot gnu dot org a écrit :
> ------- Comment #7 from jakub at gcc dot gnu dot org  2009-03-17 08:52 -------
> Created an attachment (id=17472)
>  --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17472&action=view)
> gcc44-local-imported-decl.patch
> 
> Incremental patch to emit DW_TAG_imported_declaration DIEs (other than
> namespace aliases) in the right lexical blocks.
>

I am wondering what happens when cp_emit_debug_info_for_using is called
for a using declaration that appears at global scope. Once we are in the
USING_STMT case of cp_gimplify_expr, will there be an enclosing
GIMPLE_BIND for the USING_STMT generated for the global using declaration ?

For the record, cp_parser_using_declaration calls either
do_local_using_decl or do_toplevel_using_decl, depending on if we are at
local or global scope. Both do_local_using_decl and
do_toplevel_using_decl end up calling cp_parser_using_declaration.


> 
> Concerning:
> "We won't be going through the USING_STMT code path in case of We won't be
> going through the USING_STMT code path in case of namespace aliases, sorry. My
> last comment was irrelevant."
> we really should be going through USING_STMT or something similar for namespace
> aliases as well, see PR37890.  Given that namespace aliases are just emitted
> using gen_namespace_die, perhaps just adding the NAMESPACE_DECL to BLOCK_VARS

Yeah I should try something like that in cp_gimplify_expr whenever we
are handed BIND_EXPR. In that case, I can wall the BIND_EXPR_VARS of the
of the BIND_EXPR and add any NAMESPACE_DECL to the BLOCK_VARS of the
matching block. Would that make sense ?
Comment 9 Jan Kratochvil 2009-03-17 10:05:00 UTC
I no longer see any DWARF problem there but Archer C++ still does not work with g++-4.4.  Assuming an Archer bug due to the new DW_TAG_lexical_block block.
Comment 10 Jan Kratochvil 2009-03-17 12:24:34 UTC
ICE: Comment 7 patch (applied together with the Comment 3 patch) on:
--------------------------------------------------------------------------------
namespace A
{
  class B
  {
  };
};

extern void g ();

void
f ()
{
  using A::B;

  g ();
}
--------------------------------------------------------------------------------
1.C: In function ‘void f()’:
1.C:16: internal compiler error: in force_decl_die, at dwarf2out.c:15092
g++ (GCC) 4.4.0 20090316 (experimental)
Comment 11 Jakub Jelinek 2009-03-17 12:28:43 UTC
Created attachment 17477 [details]
gcc44-local-imported-decl.patch

Yeah, I know, found that out already during my regtest.  Here is what I'm bootstrapping/regtesting instead.
Comment 12 sami 2009-03-17 15:17:50 UTC
(In reply to comment #9)
> I no longer see any DWARF problem there but Archer C++ still does not work with
> g++-4.4.  Assuming an Archer bug due to the new DW_TAG_lexical_block block.
> 

Yes there are a couple I am looking at them.

Comment 13 Jakub Jelinek 2009-03-17 17:49:42 UTC
Subject: Bug 39471

Author: jakub
Date: Tue Mar 17 17:49:28 2009
New Revision: 144911

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144911
Log:
	PR debug/39471
	* dwarf2out.c (dwarf2out_imported_module_or_decl_1): Emit
	DW_TAG_imported_module even if decl is IMPORTED_DECL with
	NAMESPACE_DECL in its DECL_INITIAL.

	* cp-gimplify.c (cp_gimplify_expr): Don't set DECL_NAME
	on IMPORTED_DECL.

	* g++.dg/debug/dwarf2/imported-module-2.C: Expect
	DW_TAG_imported_module, not just any DW_TAG_imported prefixed tag.
	* g++.dg/debug/dwarf2/imported-module-3.C: Likewise.
	* g++.dg/debug/dwarf2/imported-module-4.C: Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-gimplify.c
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/imported-module-2.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/imported-module-3.C
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/imported-module-4.C

Comment 14 Jakub Jelinek 2009-03-17 17:56:19 UTC
Fixed.