[PATCH] D12624: Top-level anonymous namespaces are missing import DW_TAG_imported_module and nested anonymous namespaces are not

Katya Romanova via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 3 18:46:15 PDT 2015


kromanova created this revision.
kromanova added reviewers: rsmith, dblaikie, echristo, probinson, aprantl.
kromanova added a subscriber: cfe-commits.


I had a review opened for anonymous namespaces bug in llvm-commits (see http://reviews.llvm.org/D7895). It was opened in llvm-commits is because the first patch that I submitted was in the backend. However it seems that the frontend patch will be more appropriate in this case. David Blaikie advised to get cfe developers opinion, specifically Richard Smith's.
Rather than just adding cfe-dev to the reviewers list, I thought it will be better to open a brand new review.

There was quite a long discussion in llvm-commits list about this bug and several re-implementations of a fix, so it gets confusing after a while. 
I will write a short summary of what was discussed in http://reviews.llvm.org/D7895

Problem #1:

DW_TAG_imported_module is missing from the compile unit's root scope. Without this tag, anonymous namespace is not imported into the root scope by PS4 debugger.

Consider the following testcase. Lack of DW_TAG_imported_module prevents our debugger from displaying the value of ‘a’.

#include <stdio.h>

namespace
{

int a = 5;

}

int main()
{

printf("%d\n", a);

return 0;

}


Problem #2:

Another (more general) problem is that while the clang compiler doesn't generate DW_TAG_imported_module for the top-level anonymous namespace, it generates this tag for nested anonymous namespaces. So, we have an asymmetrical situation.

namespace
{
  namespace {
    int a1 = 5;
  }
  int a2 = 7;
}
int *b1 = &a1;
int *b2 = &a2;



DWARF:
 <1><54>: Abbrev Number: 5 (DW_TAG_namespace)
    <55>   DW_AT_decl_file   : 1
    <56>   DW_AT_decl_line   : 2
 <2><57>: Abbrev Number: 5 (DW_TAG_namespace)
    <58>   DW_AT_decl_file   : 1
    <59>   DW_AT_decl_line   : 3
....
 <2><8d>: Abbrev Number: 7 (DW_TAG_imported_module)
    <8e>   DW_AT_import      : <0x57>   [Abbrev Number: 5 (DW_TAG_namespace)]

Note that DW_TAG_import is not generated for the top-level anonymous namespace.



There was a long discussion if we want to generate explicit imports marked by DW_AT_artificial attribute for anonymous namespaces in Clang or not. Both GCC and ICC compilers generate explicit imports in this case. However, it's an arguable gray area between the compiler and the debugger.  The final decision was *not* to generate DW_TAG_imported_module for all the platforms except PS4. On PS4 we definitely want it, since our debugger doesn't import the anonymous namespace automatically.

There were several different patches for this fix. For this review, I'm providing the latest FE patch only. It takes care of both problem #1 and problem #2.
See http://reviews.llvm.org/D7895 for more details/earlier patches.

Richard, could you please give your opinion on how that problem needs to get taken care of in the FE. I don't mind re-writing patch based on your comments, if necessary.
Thank you!











http://reviews.llvm.org/D12624

Files:
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/debug-info-anon-namespace.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12624.34007.patch
Type: text/x-patch
Size: 10286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150904/819d8f74/attachment-0001.bin>


More information about the cfe-commits mailing list