[PATCH] Anonymous namespaces are missing import DW_TAG_imported_module.

David Blaikie dblaikie at gmail.com
Wed May 13 15:17:23 PDT 2015


On Wed, May 13, 2015 at 3:02 PM, Romanova, Katya <
Katya_Romanova at playstation.sony.com> wrote:

>
>
>
>
> *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> 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.*
>

Sounds plausible - though it may need some extra review from Richard Smith
or someone to check that that's a good thing to do given the broader
surface area. But given that the nested case causes similar behavior to the
behavior this change would create in the non-nested case, I'm fairly
confident.


> * If not, I will figure out a different way to do it.*
>

Feel free to reach out via email on the lists or IRC to talk more if you
run into any hiccups.


>  *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?*
>

Nah - just suppress them all for non-PS4 I think (perhaps we'll be
surprised and GDB tests will fail when we do this - in which case we
probably shouldn't suppress the imported modules at all - nested or
non-nested). When I implemented this I clearly didn't test it enough & it
seemed sufficient to fix the GDB test cases with the current behavior. I
doubt GDB behaves correctly with top level non-imported anonymous
namespaces and then would fail for non-top-level-non-imported anonymous
namespaces.

If that all makes any sense...

(the other thing to do, after enabling this suppression (which you could do
first, to fix the bug in non-top-level-anonymous namespace (the bug that we
emit the imported directive when we needn't), conditionally on non-PS4 (so
we continue to emit them on PS4) - then fix the DeclGroup thing and the
conditional suppression should then fire for top level using directives and
you'll get the behavior you're looking for?) is add the artificial
attribute/flag/thing... but I'm not /too/ fussed about that part of it, if
it's useful for you guys, do it, but if we're just leaving this as a
workaround for your debugger then it doesn't seem too important if it
requires changes to the metadata schema, etc (if it just requires using an
existing flag, etc, then the cost is lower & it might be more worth it))

Sorry if that's a bit rambly... my brain's a bit all over the place today.

- David


>
>
> *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/54282ffe/attachment.html>


More information about the llvm-commits mailing list