[PATCH] D59620: [llvm-pdbutil] Add -type-ref-stats to help find unused type info

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 10:41:24 PDT 2019


zturner added a comment.

In D59620#1438210 <https://reviews.llvm.org/D59620#1438210>, @rnk wrote:

> In D59620#1438190 <https://reviews.llvm.org/D59620#1438190>, @zturner wrote:
>
> > I don't think you can have a cycle to an unnamed type though because it's impossible to reference it.
>
>
> In C, yes, so far as I can tell it's impossible to reference an unnamed struct or union from inside it.
>
> > Or maybe you can, by doing something like:
> > 
> >   struct {
> >     auto foo() { return this; }
> >     
> >     decltype(foo()) node;
> >   };
> > 
> > 
> > I'd be curious to see how well the debugger handles that.
>
> The decltype bit isn't necessary, just having a method is enough to make a cycle between the method type and the class. So, since pretty much all types in C++ have methods, MSVC gives all C++ types "unique" names. Of course, if they are at global scope, they may not in fact be unique across the whole program, but that just means there might type confusion later on during a debugging session.
>
> For this example, MSVC creates a fwd decl with the unique name `.?AU<unnamed-type-node>@@`:
>
>   struct {
>     auto foo() { return this; }
>     int x;
>   } node;
>   int bar() { return node.foo()->x; }
>


The reason I put the variable with the decltype is because it's the easiest way to force the debugger to deal with the cycle.  Without that, sure you can generate a cycle in the debug info, but it's not clear under what conditions the debugger would actually require that record.

This way, it's easy to add a watch in the debugger for `foo.node` and the debugger is forced to resolve the cycle.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59620/new/

https://reviews.llvm.org/D59620





More information about the llvm-commits mailing list