From: David Majnemer <david.majnemer@gmail.com> Date: Sun, 25 Dec 2016 05:26:02 +0000 (+0000) Subject: [MS ABI] Mangle unnamed enums correctly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee97307fb8860b4f721fce8f1a919995452366a4;p=clang [MS ABI] Mangle unnamed enums correctly Unnamed enums take the name of the first enumerator they define. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 27806a7d9e..911b8b471a 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -863,21 +863,28 @@ void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, } } - llvm::SmallString<64> Name("<unnamed-type-"); + llvm::SmallString<64> Name; if (DeclaratorDecl *DD = Context.getASTContext().getDeclaratorForUnnamedTagDecl(TD)) { // Anonymous types without a name for linkage purposes have their // declarator mangled in if they have one. + Name += "<unnamed-type-"; Name += DD->getName(); } else if (TypedefNameDecl *TND = Context.getASTContext().getTypedefNameForUnnamedTagDecl( TD)) { // Anonymous types without a name for linkage purposes have their // associate typedef mangled in if they have one. + Name += "<unnamed-type-"; Name += TND->getName(); + } else if (auto *ED = dyn_cast<EnumDecl>(TD)) { + auto EnumeratorI = ED->enumerator_begin(); + assert(EnumeratorI != ED->enumerator_end()); + Name += "<unnamed-enum-"; + Name += EnumeratorI->getName(); } else { // Otherwise, number the types using a $S prefix. - Name += "$S"; + Name += "<unnamed-type-$S"; Name += llvm::utostr(Context.getAnonymousStructId(TD) + 1); } Name += ">"; diff --git a/test/CodeGenCXX/mangle-ms-cxx11.cpp b/test/CodeGenCXX/mangle-ms-cxx11.cpp index f21012b602..819b0d9c9d 100644 --- a/test/CodeGenCXX/mangle-ms-cxx11.cpp +++ b/test/CodeGenCXX/mangle-ms-cxx11.cpp @@ -343,3 +343,7 @@ A a; int call_it = (A::default_args(), 1); } + +enum { enumerator }; +void f(decltype(enumerator)) {} +// CHECK-DAG: define void @"\01?f@@YAXW4<unnamed-enum-enumerator>@@@Z"(