Unique ASCII name for aggregates?

I need to get a unique string for each aggregate, including template specializations. In the past, I used clang’s name mangling functionality to mangle the name of a record, but this seems to no longer be supported. In particular, in CXXNameMangler::mangle I see llvm_unreachable in the RecordDecl case.

Is there a way to do this now?

It seems like printNameForDiagnostic is close, but it doesn’t distinguish between unnamed entries in a context, e.g. the two anonymous structs in the following example are printed the same way.

struct Foo {
  struct { int x; } X; // Foo::(anonymous)
  struct { int y; } Y; // Foo::(anonymous)

One hack that I’ve come up with is to generate the name of the destructor and then do some surgery since the destructor’s name can be mangled.

The ABI doesn’t need the naked mangling of a type. It’s always the FOO of $TYPE, like (one of) the destructors of $TYPE, the typeinfo of $TYPE, the vtable of $TYPE. The initializer for the typeinfo name field seems like an appropriate ‘unique string’ – if it is indeed an array of chars that you’re looking for? Otherwise, as an identifier, doing surgery on a dtor name is probably a good alternative.

Thanks @urnathan . It seems like clang is providing MangleContext::mangleTypeName which seems to work for my purposes. It is not quite the same as the previous implementation, but I’ve managed to do some hackery there that works.