[PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled

Michael Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 20:47:32 PDT 2015


michaelwu updated this revision to Diff 36330.
michaelwu added a comment.

Thanks for the review. I switched to shouldMangleDeclName instead of shouldMangleCXXName, and made it skip the frontend mangling instead of returning an empty string. I tried making mangleName do that instead, but it seemed to cause a bunch of test failures..

The nice thing about returning a valid symbol name instead of an empty string is that I discovered my new test was incomplete. This diff also adds a change to properly handle declarations inside an extern "C".


http://reviews.llvm.org/D13317

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

Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3890,7 +3890,11 @@
 
   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(
Index: tools/c-index-test/c-index-test.c
===================================================================
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1429,6 +1429,8 @@
 
 static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p,
                                                 CXClientData d) {
+  if (clang_getCursorKind(cursor) == CXCursor_UnexposedDecl)
+    return CXChildVisit_Recurse;
   CXString MangledName;
   PrintCursor(cursor, NULL);
   MangledName = clang_Cursor_getMangling(cursor);
Index: test/Index/print-mangled-name.cpp
===================================================================
--- test/Index/print-mangled-name.cpp
+++ test/Index/print-mangled-name.cpp
@@ -29,3 +29,8 @@
 // ITANIUM: mangled=_Z3foo1SRS_
 // MACHO: mangled=__Z3foo1SRS_
 // MICROSOFT: mangled=?foo@@YAHUS
+
+extern "C" int foo(int);
+// ITANIUM: mangled=foo
+// MACHO: mangled=_foo
+// MICROSOFT: mangled=_foo


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13317.36330.patch
Type: text/x-patch
Size: 1480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151002/f731e982/attachment-0001.bin>


More information about the cfe-commits mailing list