[PATCH] Anonymous namespaces are missing import DW_TAG_imported_module.

Romanova, Katya Katya_Romanova at playstation.sony.com
Wed May 13 15:02:44 PDT 2015



From: David Blaikie [mailto:dblaikie at gmail.com]
Sent: Wednesday, May 13, 2015 11:06 AM
To: reviews+D7895+public+7827be49c0b04087 at reviews.llvm.org
Cc: Romanova, Katya; Eric Christopher; Frédéric Riss; Duncan P. N. Exon Smith; Robinson, Paul; Adrian Prantl; llvm-commits at cs.uiuc.edu
Subject: Re: [PATCH] Anonymous namespaces are missing import DW_TAG_imported_module.



On Wed, May 13, 2015 at 10:56 AM, Katya Romanova <Katya_Romanova at playstation.sony.com<mailto:Katya_Romanova at playstation.sony.com>> wrote:
Hi David,
Sorry for the delay answering your question about AST.

> > One question, if you're up for it - there is actually an implicit UsingDirectiveDecl in the AST
>..
> > It's possible we could figure out why that decl is being skipped normally? & avoid skipping it/filter it out later for non-ps4 while leaving it in for ps4, rather than synthesizing the extra
>
> >  imported module from scratch in the debug info code gen?
>
> >  I took a glance & didn't immediately see why we weren't already visiting this implicit decl - I guess something is filtering out implicit decls somewhere?
>


Implicit UsingDirectiveDecl is generated by Sema::ActOnStartNamespaceDef() when it’s given an anonymous namespace.
The UsingDirectedDecl is added to the Parent (top level) which is why you see it in AST dump.

Above function is called from ParseNamespace(), which is called by ParseDeclaration(). ParseDeclaration() returns DeclGroup.
The problem is that group is populated with a SingleDecl that ParseNamespace returns ([anonymous] NamespaceDecl).

ParseDeclaration doesn’t know anything about the UsingNamespaceDecl that ParseNamespace implicitly generated
and added to the parent.. This implicit declaration is not added to the DeclGroup and thus you don’t generate
debug node for it.

If we want ParseNamespace to generate both NamespaceDecl AND an implicit UsingNamespaceDecl
then the following piece of code:

  case tok::kw_namespace:
    ProhibitAttributes(attrs);
    SingleDecl = ParseNamespace(Context, DeclEnd);
    break;

should return not the SingleDecl (converted to DeclGroup), but a DeclGroup containing both NamespaceDecl AND UsingNamespaceDecl.

I think that this fix (conditional for PS4 only) will be more complicated and more invasive solution than FE solution that I implemented before.

I saw that you already accepted my latest FE patch. Please confirm that you didn't change your mind about how this bug should get fixed after your saw this explanation about AST.

After seeing Clang's output on some other code, I'm not sure this fix is correct.

Could you add a test case with an anonymous namespace inside another namespace? When I tried that with ToT, we /do/ emit the (implicit) using directive today. So your change might cause us to emit two using directives (one marked artificial, and one not).

[Katya Romanova]
I have tried anonymous namespace inside another anonymous namespace like you suggested . You are right. I can see that implicit using directive is always emitted for a nested namespace. That means, that for PS4 we will emit duplicate using directive for a nested anonymous namespace.

So it might be worth figuring out how to plumb through the implicit using directive for the top level namespace so we treat anonymous namespaces the same whether or not they are at the top level, and when making this change - then deliberately suppress the implicit using directive for an anonymous namespace except when targeting PS4/SCE.

[Katya Romanova]
So the current plan is to add an implicit using directive for the top level anonymous namespace to the DeclGroup containing top level decls. Hopefully, it could be done by changing ParseNamespace to return a DeclGroup containing both NamespaceDecl and UsingDirectiveDecl. If not, I will figure out a different way to do it.
After that, I need to suppress generation of a using directive for *top level* implicit anonymous namespace (except for PS4). I assume we still want to keep generating  implicit using directive for the *nested* anonymous namespace. Rright?

Let me know if this solution sounds reasonable. I will implement the  patch.
ParseDeclaration doesn’t know anything about the UsingNamespaceDecl that ParseNamespace implicitly generated
and added to the parent.. This implicit declaration is not added to the DeclGroup and thus you don’t generate
debug node for it.
If we want ParseNamespace to generate both NamespaceDecl AND an implicit UsingNamespaceDecl
then the following piece of code:
case tok::kw_namespace:
  ProhibitAttributes(attrs);
  SingleDecl = ParseNamespace(Context, DeclEnd);
  break;
should return not the SingleDecl (converted to DeclGroup), but a DeclGroup containing both NamespaceDecl AND UsingNamespaceDecl.


- David


If everything is OK, I will rebase and commit my latest FE patch.
Thanks for reviewing!


http://reviews.llvm.org/D7895

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150513/6011446b/attachment.html>


More information about the llvm-commits mailing list