Implement Microsoft-compatible mangling for decomposition declarations.
Match cl.exe's mangling for decomposition declarations.
Decomposition declarations are considered to be anonymous structs,
and use the same convention as for anonymous struct/union declarations.
Naming confirmed to match https://godbolt.org/z/K2osJa
Patch from Eric Astor <epastor@google.com>!
Differential Revision: https://reviews.llvm.org/D67202
llvm-svn: 371124
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index f7a456e..7ad8b52 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -868,16 +868,11 @@
}
if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(ND)) {
- // FIXME: Invented mangling for decomposition declarations:
- // [X,Y,Z]
- // where X,Y,Z are the names of the bindings.
- llvm::SmallString<128> Name("[");
- for (auto *BD : DD->bindings()) {
- if (Name.size() > 1)
- Name += ',';
- Name += BD->getDeclName().getAsIdentifierInfo()->getName();
- }
- Name += ']';
+ // Decomposition declarations are considered anonymous, and get
+ // numbered with a $S prefix.
+ llvm::SmallString<64> Name("$S");
+ // Get a unique id for the anonymous struct.
+ Name += llvm::utostr(Context.getAnonymousStructId(DD) + 1);
mangleSourceName(Name);
break;
}