[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
This revision was automatically updated to reflect the committed changes. Closed by commit rL371124: Implement Microsoft-compatible mangling for decomposition declarations. (authored by nico, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D67202?vs=218934=218978#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67202/new/ https://reviews.llvm.org/D67202 Files: cfe/trunk/include/clang/AST/Mangle.h cfe/trunk/lib/AST/MicrosoftMangle.cpp cfe/trunk/test/CodeGenCXX/mangle-ms-cxx17.cpp Index: cfe/trunk/lib/AST/MicrosoftMangle.cpp === --- cfe/trunk/lib/AST/MicrosoftMangle.cpp +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp @@ -868,16 +868,11 @@ } if (const DecompositionDecl *DD = dyn_cast(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; } Index: cfe/trunk/include/clang/AST/Mangle.h === --- cfe/trunk/include/clang/AST/Mangle.h +++ cfe/trunk/include/clang/AST/Mangle.h @@ -56,7 +56,7 @@ llvm::DenseMap GlobalBlockIds; llvm::DenseMap LocalBlockIds; - llvm::DenseMap AnonStructIds; + llvm::DenseMap AnonStructIds; public: ManglerKind getKind() const { return Kind; } @@ -82,9 +82,9 @@ return Result.first->second; } - uint64_t getAnonymousStructId(const TagDecl *TD) { -std::pair::iterator, bool> -Result = AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); + uint64_t getAnonymousStructId(const NamedDecl *D) { +std::pair::iterator, bool> +Result = AnonStructIds.insert(std::make_pair(D, AnonStructIds.size())); return Result.first->second; } Index: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx17.cpp === --- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx17.cpp +++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx17.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++1z -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.10 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=CHECK --check-prefix=MSVC2017 +// RUN: %clang_cc1 -std=c++1z -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=CHECK --check-prefix=MSVC2015 + +struct S { +int x; +double y; +}; +S f(); + +// CHECK-DAG: "?$S1@@3US@@B" +const auto [x0, y0] = f(); +// CHECK-DAG: "?$S2@@3US@@B" +const auto [x1, y1] = f(); + +static union { +int a; +double b; +}; + +// CHECK-DAG: "?$S4@@3US@@B" +const auto [x2, y2] = f(); Index: cfe/trunk/lib/AST/MicrosoftMangle.cpp === --- cfe/trunk/lib/AST/MicrosoftMangle.cpp +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp @@ -868,16 +868,11 @@ } if (const DecompositionDecl *DD = dyn_cast(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; } Index: cfe/trunk/include/clang/AST/Mangle.h === --- cfe/trunk/include/clang/AST/Mangle.h +++ cfe/trunk/include/clang/AST/Mangle.h @@ -56,7 +56,7 @@ llvm::DenseMap GlobalBlockIds; llvm::DenseMap LocalBlockIds; - llvm::DenseMap AnonStructIds; + llvm::DenseMap AnonStructIds; public: ManglerKind getKind() const { return Kind; } @@ -82,9 +82,9 @@ return Result.first->second; } - uint64_t getAnonymousStructId(const TagDecl *TD) { -std::pair::iterator, bool> -
[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
thakis accepted this revision. thakis added a comment. This revision is now accepted and ready to land. Thanks! Re llvm-undname: That seems to match behavior of MSVC's undname, so I'd say that's all good :) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67202/new/ https://reviews.llvm.org/D67202 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
epastor added a comment. The change passes ninja check-clang - and I've added a test per your suggestions. Thanks! As for llvm-undname: it works reasonably well, but these are anonymous names. It successfully recognizes $S1, etc. as the "name", though! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67202/new/ https://reviews.llvm.org/D67202 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
epastor updated this revision to Diff 218934. epastor added a comment. - Add testing for the new deprecation declarations mangling Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67202/new/ https://reviews.llvm.org/D67202 Files: clang/include/clang/AST/Mangle.h clang/lib/AST/MicrosoftMangle.cpp clang/test/CodeGenCXX/mangle-ms-cxx17.cpp Index: clang/test/CodeGenCXX/mangle-ms-cxx17.cpp === --- /dev/null +++ clang/test/CodeGenCXX/mangle-ms-cxx17.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++1z -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.10 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=CHECK --check-prefix=MSVC2017 +// RUN: %clang_cc1 -std=c++1z -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=CHECK --check-prefix=MSVC2015 + +struct S { +int x; +double y; +}; +S f(); + +// CHECK-DAG: "?$S1@@3US@@B" +const auto [x0, y0] = f(); +// CHECK-DAG: "?$S2@@3US@@B" +const auto [x1, y1] = f(); + +static union { +int a; +double b; +}; + +// CHECK-DAG: "?$S4@@3US@@B" +const auto [x2, y2] = f(); Index: clang/lib/AST/MicrosoftMangle.cpp === --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -868,16 +868,11 @@ } if (const DecompositionDecl *DD = dyn_cast(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; } Index: clang/include/clang/AST/Mangle.h === --- clang/include/clang/AST/Mangle.h +++ clang/include/clang/AST/Mangle.h @@ -56,7 +56,7 @@ llvm::DenseMap GlobalBlockIds; llvm::DenseMap LocalBlockIds; - llvm::DenseMap AnonStructIds; + llvm::DenseMap AnonStructIds; public: ManglerKind getKind() const { return Kind; } @@ -82,9 +82,9 @@ return Result.first->second; } - uint64_t getAnonymousStructId(const TagDecl *TD) { -std::pair::iterator, bool> -Result = AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); + uint64_t getAnonymousStructId(const NamedDecl *D) { +std::pair::iterator, bool> +Result = AnonStructIds.insert(std::make_pair(D, AnonStructIds.size())); return Result.first->second; } Index: clang/test/CodeGenCXX/mangle-ms-cxx17.cpp === --- /dev/null +++ clang/test/CodeGenCXX/mangle-ms-cxx17.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++1z -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.10 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=CHECK --check-prefix=MSVC2017 +// RUN: %clang_cc1 -std=c++1z -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=CHECK --check-prefix=MSVC2015 + +struct S { +int x; +double y; +}; +S f(); + +// CHECK-DAG: "?$S1@@3US@@B" +const auto [x0, y0] = f(); +// CHECK-DAG: "?$S2@@3US@@B" +const auto [x1, y1] = f(); + +static union { +int a; +double b; +}; + +// CHECK-DAG: "?$S4@@3US@@B" +const auto [x2, y2] = f(); Index: clang/lib/AST/MicrosoftMangle.cpp === --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -868,16 +868,11 @@ } if (const DecompositionDecl *DD = dyn_cast(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);
[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
thakis added a comment. Does this pass `ninja check-clang`? If so, can you add a test for the new mangling, based on the manglings in the godbolt example? See `clang/test/CodeGenCXX/mangle-ms-*` for many examples; a new file mangle-ms-cxx20.cpp might be appropriate here. You can run `bin/llvm-lit -vv clang/test/CodeGenCXX/foo.cpp` to run a single lit test for iterating on the local test. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67202/new/ https://reviews.llvm.org/D67202 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
thakis added a comment. ps: Thanks for the patch, this is great :) pps: Since this uses struct mangling, `llvm-undname` can already demangle these names, right? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67202/new/ https://reviews.llvm.org/D67202 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D67202: Implement Microsoft-compatible mangling for decomposition declarations.
epastor created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. 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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D67202 Files: clang/include/clang/AST/Mangle.h clang/lib/AST/MicrosoftMangle.cpp Index: clang/lib/AST/MicrosoftMangle.cpp === --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -868,16 +868,11 @@ } if (const DecompositionDecl *DD = dyn_cast(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; } Index: clang/include/clang/AST/Mangle.h === --- clang/include/clang/AST/Mangle.h +++ clang/include/clang/AST/Mangle.h @@ -56,7 +56,7 @@ llvm::DenseMap GlobalBlockIds; llvm::DenseMap LocalBlockIds; - llvm::DenseMap AnonStructIds; + llvm::DenseMap AnonStructIds; public: ManglerKind getKind() const { return Kind; } @@ -82,9 +82,9 @@ return Result.first->second; } - uint64_t getAnonymousStructId(const TagDecl *TD) { -std::pair::iterator, bool> -Result = AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); + uint64_t getAnonymousStructId(const NamedDecl *D) { +std::pair::iterator, bool> +Result = AnonStructIds.insert(std::make_pair(D, AnonStructIds.size())); return Result.first->second; } Index: clang/lib/AST/MicrosoftMangle.cpp === --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -868,16 +868,11 @@ } if (const DecompositionDecl *DD = dyn_cast(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; } Index: clang/include/clang/AST/Mangle.h === --- clang/include/clang/AST/Mangle.h +++ clang/include/clang/AST/Mangle.h @@ -56,7 +56,7 @@ llvm::DenseMap GlobalBlockIds; llvm::DenseMap LocalBlockIds; - llvm::DenseMap AnonStructIds; + llvm::DenseMap AnonStructIds; public: ManglerKind getKind() const { return Kind; } @@ -82,9 +82,9 @@ return Result.first->second; } - uint64_t getAnonymousStructId(const TagDecl *TD) { -std::pair::iterator, bool> -Result = AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); + uint64_t getAnonymousStructId(const NamedDecl *D) { +std::pair::iterator, bool> +Result = AnonStructIds.insert(std::make_pair(D, AnonStructIds.size())); return Result.first->second; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits