michaelwu created this revision. michaelwu added a subscriber: cfe-commits.
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. http://reviews.llvm.org/D13317 Files: test/Index/print-mangled-name.cpp tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3891,6 +3891,10 @@ ASTContext &Ctx = ND->getASTContext(); std::unique_ptr<MangleContext> MC(Ctx.createMangleContext()); + // Don't mangle if we don't need to. + if (!MC->shouldMangleCXXName(ND)) + return cxstring::createEmpty(); + std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); MC->mangleName(ND, FrontendBufOS); 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= +// MACHO: mangled= +// MICROSOFT: mangled=
Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3891,6 +3891,10 @@ ASTContext &Ctx = ND->getASTContext(); std::unique_ptr<MangleContext> MC(Ctx.createMangleContext()); + // Don't mangle if we don't need to. + if (!MC->shouldMangleCXXName(ND)) + return cxstring::createEmpty(); + std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); MC->mangleName(ND, FrontendBufOS); 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= +// MACHO: mangled= +// MICROSOFT: mangled=
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits