<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 17, 2015 at 5:07 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">This introduced a memory leak, which I'm testing a patch for.<br></div></blockquote><div><br></div><div>Oops, thanks.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Aside from that, did you get Doug to review this? We probably want to be really careful about changing libclang's C API, so you should be more cautious here than you would be normally.</div></blockquote><div><br></div><div>I had discussed this with Argyrios Kyrtzidis. Is he not the current owner for libclang? Ill happily speak to Doug in the future if he is a better contact for new API introductions for libclang.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 11, 2015 at 7:57 PM, Saleem Abdulrasool via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: compnerd<br>
Date: Wed Nov 11 21:57:22 2015<br>
New Revision: 252853<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252853&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252853&view=rev</a><br>
Log:<br>
libclang: add clang_Cursor_getCXXManglings<br>
<br>
This function permits the mangling of a C++ 'structor. Depending on the ABI and<br>
the declaration, the declaration may contain more than one associated symbol for<br>
a given declaration. This allows the consumer to retrieve all of the associated<br>
symbols for the declaration the cursor points to.<br>
<br>
Added:<br>
cfe/trunk/test/Index/print-cxx-manglings.cpp<br>
Modified:<br>
cfe/trunk/include/clang-c/Index.h<br>
cfe/trunk/tools/c-index-test/c-index-test.c<br>
cfe/trunk/tools/libclang/CIndex.cpp<br>
cfe/trunk/tools/libclang/libclang.exports<br>
<br>
Modified: cfe/trunk/include/clang-c/Index.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=252853&r1=252852&r2=252853&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=252853&r1=252852&r2=252853&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang-c/Index.h (original)<br>
+++ cfe/trunk/include/clang-c/Index.h Wed Nov 11 21:57:22 2015<br>
@@ -3863,6 +3863,12 @@ CINDEX_LINKAGE CXString clang_Cursor_get<br>
CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor);<br>
<br>
/**<br>
+ * \brief Retrieve the CXStrings representing the mangled symbols of the C++<br>
+ * constructor or destructor at the cursor.<br>
+ */<br>
+CINDEX_LINKAGE CXStringSet *clang_Cursor_getCXXManglings(CXCursor);<br>
+<br>
+/**<br>
* @}<br>
*/<br>
<br>
<br>
Added: cfe/trunk/test/Index/print-cxx-manglings.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-cxx-manglings.cpp?rev=252853&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-cxx-manglings.cpp?rev=252853&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Index/print-cxx-manglings.cpp (added)<br>
+++ cfe/trunk/test/Index/print-cxx-manglings.cpp Wed Nov 11 21:57:22 2015<br>
@@ -0,0 +1,66 @@<br>
+// REQUIRES: x86-registered-target<br>
+<br>
+// RUN: c-index-test -write-pch %t.itanium.ast -target i686-pc-linux-gnu -fdeclspec %s<br>
+// RUN: c-index-test -test-print-manglings %t.itanium.ast | FileCheck --check-prefix=ITANIUM %s<br>
+<br>
+// RUN: c-index-test -write-pch %t.macho.ast -target i686-apple-darwin -fdeclspec %s<br>
+// RUN: c-index-test -test-print-manglings %t.macho.ast | FileCheck --check-prefix=MACHO %s<br>
+<br>
+// RUN: c-index-test -write-pch %t.msvc.ast -target i686-pc-windows %s<br>
+// RUN: c-index-test -test-print-manglings %t.msvc.ast | FileCheck --check-prefix=MSVC %s<br>
+<br>
+struct s {<br>
+ s(int);<br>
+ ~s();<br>
+ int m(int);<br>
+};<br>
+<br>
+// ITANIUM: CXXConstructor=s{{.*}}[mangled=_ZN1sC2Ei] [mangled=_ZN1sC1Ei]<br>
+// ITANIUM: CXXDestructor=~s{{.*}}[mangled=_ZN1sD2Ev] [mangled=_ZN1sD1Ev] [mangled=_ZN1sD0Ev]<br>
+<br>
+// MACHO: CXXConstructor=s{{.*}}[mangled=__ZN1sC2Ei] [mangled=__ZN1sC1Ei]<br>
+// MACHO: CXXDestructor=~s{{.*}}[mangled=__ZN1sD2Ev] [mangled=__ZN1sD1Ev] [mangled=__ZN1sD0Ev]<br>
+<br>
+// MSVC: CXXConstructor=s{{.*}}[mangled=??0s@@QAE@H@Z]<br>
+// MSVC: CXXDestructor=~s{{.*}}[mangled=??1s@@QAE@XZ]<br>
+<br>
+struct t {<br>
+ t(int);<br>
+ virtual ~t();<br>
+ int m(int);<br>
+};<br>
+<br>
+// ITANIUM: CXXConstructor=t{{.*}}[mangled=_ZN1tC2Ei] [mangled=_ZN1tC1Ei]<br>
+// ITANIUM: CXXDestructor=~t{{.*}}[mangled=_ZN1tD2Ev] [mangled=_ZN1tD1Ev]<br>
+<br>
+// MACHO: CXXConstructor=t{{.*}}[mangled=__ZN1tC2Ei] [mangled=__ZN1tC1Ei]<br>
+// MACHO: CXXDestructor=~t{{.*}}[mangled=__ZN1tD2Ev] [mangled=__ZN1tD1Ev]<br>
+<br>
+// MSVC: CXXConstructor=t{{.*}}[mangled=??0t@@QAE@H@Z]<br>
+// MSVC: CXXDestructor=~t{{.*}}[mangled=??1t@@UAE@XZ]<br>
+<br>
+struct u {<br>
+ u();<br>
+ virtual ~u();<br>
+ virtual int m(int) = 0;<br>
+};<br>
+<br>
+// ITANIUM: CXXConstructor=u{{.*}}[mangled=_ZN1uC2Ev]<br>
+// ITANIUM: CXXDestructor=~u{{.*}}[mangled=_ZN1uD2Ev] [mangled=_ZN1uD1Ev]<br>
+<br>
+// MACHO: CXXConstructor=u{{.*}}[mangled=__ZN1uC2Ev]<br>
+// MACHO: CXXDestructor=~u{{.*}}[mangled=__ZN1uD2Ev] [mangled=__ZN1uD1Ev]<br>
+<br>
+// MSVC: CXXConstructor=u{{.*}}[mangled=??0u@@QAE@XZ]<br>
+// MSVC: CXXDestructor=~u{{.*}}[mangled=??1u@@UAE@XZ]<br>
+<br>
+struct v {<br>
+ __declspec(dllexport) v(int = 0);<br>
+};<br>
+<br>
+// ITANIUM: CXXConstructor=v{{.*}}[mangled=_ZN1vC2Ei] [mangled=_ZN1vC1Ei]<br>
+<br>
+// MACHO: CXXConstructor=v{{.*}}[mangled=__ZN1vC2Ei] [mangled=__ZN1vC1Ei]<br>
+<br>
+// MSVC: CXXConstructor=v{{.*}}[mangled=??0v@@QAE@H@Z] [mangled=??_Fv@@QAEXXZ]<br>
+<br>
<br>
Modified: cfe/trunk/tools/c-index-test/c-index-test.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=252853&r1=252852&r2=252853&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=252853&r1=252852&r2=252853&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)<br>
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Nov 11 21:57:22 2015<br>
@@ -1441,6 +1441,25 @@ static enum CXChildVisitResult PrintMang<br>
return CXChildVisit_Continue;<br>
}<br>
<br>
+static enum CXChildVisitResult PrintManglings(CXCursor cursor, CXCursor p,<br>
+ CXClientData d) {<br>
+ unsigned I, E;<br>
+ CXStringSet *Manglings = NULL;<br>
+ if (clang_isUnexposed(clang_getCursorKind(cursor)))<br>
+ return CXChildVisit_Recurse;<br>
+ if (!clang_isDeclaration(clang_getCursorKind(cursor)))<br>
+ return CXChildVisit_Recurse;<br>
+ if (clang_getCursorKind(cursor) == CXCursor_ParmDecl)<br>
+ return CXChildVisit_Continue;<br>
+ PrintCursor(cursor, NULL);<br>
+ Manglings = clang_Cursor_getCXXManglings(cursor);<br>
+ for (I = 0, E = Manglings->Count; I < E; ++I)<br>
+ printf(" [mangled=%s]", clang_getCString(Manglings->Strings[I]));<br>
+ clang_disposeStringSet(Manglings);<br>
+ printf("\n");<br>
+ return CXChildVisit_Recurse;<br>
+}<br>
+<br>
/******************************************************************************/<br>
/* Bitwidth testing. */<br>
/******************************************************************************/<br>
@@ -4163,6 +4182,8 @@ int cindextest_main(int argc, const char<br>
PrintBitWidth, 0);<br>
else if (argc > 2 && strcmp(argv[1], "-test-print-mangle") == 0)<br>
return perform_test_load_tu(argv[2], "all", NULL, PrintMangledName, NULL);<br>
+ else if (argc > 2 && strcmp(argv[1], "-test-print-manglings") == 0)<br>
+ return perform_test_load_tu(argv[2], "all", NULL, PrintManglings, NULL);<br>
else if (argc > 1 && strcmp(argv[1], "-print-usr") == 0) {<br>
if (argc > 2)<br>
return print_usrs(argv + 2, argv + argc);<br>
<br>
Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=252853&r1=252852&r2=252853&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=252853&r1=252852&r2=252853&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Nov 11 21:57:22 2015<br>
@@ -3911,6 +3911,75 @@ CXString clang_Cursor_getMangling(CXCurs<br>
return cxstring::createDup(FinalBufOS.str());<br>
}<br>
<br>
+static std::string getMangledStructor(std::unique_ptr<MangleContext> &M,<br>
+ std::unique_ptr<llvm::DataLayout> &DL,<br>
+ const NamedDecl *ND,<br>
+ unsigned StructorType) {<br>
+ std::string FrontendBuf;<br>
+ llvm::raw_string_ostream FOS(FrontendBuf);<br>
+<br>
+ if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND))<br>
+ M->mangleCXXCtor(CD, static_cast<CXXCtorType>(StructorType), FOS);<br>
+ else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND))<br>
+ M->mangleCXXDtor(DD, static_cast<CXXDtorType>(StructorType), FOS);<br>
+<br>
+ std::string BackendBuf;<br>
+ llvm::raw_string_ostream BOS(BackendBuf);<br>
+<br>
+ llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL);<br>
+<br>
+ return BOS.str();<br>
+}<br>
+<br>
+CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {<br>
+ if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))<br>
+ return nullptr;<br>
+<br>
+ const Decl *D = getCursorDecl(C);<br>
+ if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D)))<br>
+ return nullptr;<br>
+<br>
+ const NamedDecl *ND = cast<NamedDecl>(D);<br>
+<br>
+ ASTContext &Ctx = ND->getASTContext();<br>
+ std::unique_ptr<MangleContext> M(Ctx.createMangleContext());<br>
+ std::unique_ptr<llvm::DataLayout> DL(<br>
+ new llvm::DataLayout(Ctx.getTargetInfo().getDataLayoutString()));<br>
+<br>
+ std::vector<std::string> Manglings;<br>
+<br>
+ auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {<br>
+ auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,<br>
+ /*IsCSSMethod=*/true);<br>
+ auto CC = MD->getType()->getAs<FunctionProtoType>()->getCallConv();<br>
+ return CC == DefaultCC;<br>
+ };<br>
+<br>
+ if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND)) {<br>
+ Manglings.emplace_back(getMangledStructor(M, DL, CD, Ctor_Base));<br>
+<br>
+ if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily())<br>
+ if (!CD->getParent()->isAbstract())<br>
+ Manglings.emplace_back(getMangledStructor(M, DL, CD, Ctor_Complete));<br>
+<br>
+ if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())<br>
+ if (CD->hasAttr<DLLExportAttr>() && CD->isDefaultConstructor())<br>
+ if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0))<br>
+ Manglings.emplace_back(getMangledStructor(M, DL, CD,<br>
+ Ctor_DefaultClosure));<br>
+ } else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND)) {<br>
+ Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Base));<br>
+ if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {<br>
+ Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Complete));<br>
+<br>
+ if (!DD->isVirtual())<br>
+ Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Deleting));<br>
+ }<br>
+ }<br>
+<br>
+ return cxstring::createSet(Manglings);<br>
+}<br>
+<br>
CXString clang_getCursorDisplayName(CXCursor C) {<br>
if (!clang_isDeclaration(C.kind))<br>
return clang_getCursorSpelling(C);<br>
<br>
Modified: cfe/trunk/tools/libclang/libclang.exports<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=252853&r1=252852&r2=252853&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=252853&r1=252852&r2=252853&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/libclang.exports (original)<br>
+++ cfe/trunk/tools/libclang/libclang.exports Wed Nov 11 21:57:22 2015<br>
@@ -15,6 +15,7 @@ clang_Cursor_getTemplateArgumentValue<br>
clang_Cursor_getTemplateArgumentUnsignedValue<br>
clang_Cursor_getBriefCommentText<br>
clang_Cursor_getCommentRange<br>
+clang_Cursor_getCXXManglings<br>
clang_Cursor_getMangling<br>
clang_Cursor_getParsedComment<br>
clang_Cursor_getRawCommentText<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>