From 70e8b815c5b9b9f0eab8792ef149e8e7a0654947 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 6 Oct 2015 18:24:33 +0000 Subject: [PATCH] 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 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249437 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Index/print-mangled-name.cpp | 5 +++++ tools/c-index-test/c-index-test.c | 2 ++ tools/libclang/CIndex.cpp | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/Index/print-mangled-name.cpp b/test/Index/print-mangled-name.cpp index 3d74fe5520..dc6f734dfb 100644 --- a/test/Index/print-mangled-name.cpp +++ b/test/Index/print-mangled-name.cpp @@ -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 diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index eeeb832cd8..6292f73068 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -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); diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 7a1fb5b966..9e66d0c653 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -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 DL( -- 2.40.0