]> granicus.if.org Git - clang/commitdiff
Make clang_Cursor_getMangling not mangle if the declaration isn't mangled
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Thu, 8 Oct 2015 00:01:20 +0000 (00:01 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Thu, 8 Oct 2015 00:01:20 +0000 (00:01 +0000)
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>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249639 91177308-0d34-0410-b5e6-96231b3b80d8

test/Index/print-mangled-name.cpp
tools/c-index-test/c-index-test.c
tools/libclang/CIndex.cpp

index 3d74fe5520cc2b69d151145112ba88c90c8d2144..dc6f734dfb734cf8ca1980e04d9ccff4296ff388 100644 (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
index eeeb832cd873890f3439da8311fd5fb479185a82..346bcc657948a1ad7d0d587707a813a58ee7a52a 100644 (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_isUnexposed(clang_getCursorKind(cursor)))
+    return CXChildVisit_Recurse;
   CXString MangledName;
   PrintCursor(cursor, NULL);
   MangledName = clang_Cursor_getMangling(cursor);
index 7a1fb5b966787451859ee8c61f597487bf542bb4..9e66d0c653c85477d72b34c90c23772f668f3461 100644 (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(