Make clang_Cursor_getMangling don't mangle if the declaration isn't mangled

Right now clang_Cursor_getMangling will attempt to mangle any
declaration, even if the declaration isn't mangled (extern "C").  This
results in a partially mangled name which isn't useful for much. This
patch makes clang_Cursor_getMangling return an empty string if the
declaration isn't mangled.

Patch by Michael Wu <mwu@mozilla.com>.

llvm-svn: 249437
This commit is contained in:
Ehsan Akhgari 2015-10-06 18:24:33 +00:00
parent 33bb1a23b3
commit 9d1f05aef8
3 changed files with 12 additions and 1 deletions

View File

@ -29,3 +29,8 @@ int foo(S, S&);
// ITANIUM: mangled=_Z3foo1SRS_
// MACHO: mangled=__Z3foo1SRS_
// MICROSOFT: mangled=?foo@@YAHUS
extern "C" int foo(int);
// ITANIUM: mangled=foo
// MACHO: mangled=_foo
// MICROSOFT: mangled=_foo

View File

@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p,
CXClientData d) {
if (clang_isInvalid(clang_getCursorKind(cursor)))
return CXChildVisit_Recurse;
CXString MangledName;
PrintCursor(cursor, NULL);
MangledName = clang_Cursor_getMangling(cursor);

View File

@ -3890,7 +3890,11 @@ CXString clang_Cursor_getMangling(CXCursor C) {
std::string FrontendBuf;
llvm::raw_string_ostream FrontendBufOS(FrontendBuf);
MC->mangleName(ND, FrontendBufOS);
if (MC->shouldMangleDeclName(ND)) {
MC->mangleName(ND, FrontendBufOS);
} else {
ND->printName(FrontendBufOS);
}
// Now apply backend mangling.
std::unique_ptr<llvm::DataLayout> DL(