Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[MS ABI] Mangle unnamed enums correctly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
majnemer committed Dec 25, 2016
1 parent 0b48254 commit ee97307
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/AST/MicrosoftMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ">";
Expand Down
4 changes: 4 additions & 0 deletions test/CodeGenCXX/mangle-ms-cxx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(

0 comments on commit ee97307

Please sign in to comment.