r260011 - Index: provide adjustment thunk information for C++ manglings
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 6 14:36:34 PST 2016
Author: compnerd
Date: Sat Feb 6 16:36:34 2016
New Revision: 260011
URL: http://llvm.org/viewvc/llvm-project?rev=260011&view=rev
Log:
Index: provide adjustment thunk information for C++ manglings
Add support for exposing the adjustment thunk for virtual methods as
appropriate.
Modified:
cfe/trunk/test/Index/print-cxx-manglings.cpp
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/test/Index/print-cxx-manglings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-cxx-manglings.cpp?rev=260011&r1=260010&r2=260011&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-cxx-manglings.cpp (original)
+++ cfe/trunk/test/Index/print-cxx-manglings.cpp Sat Feb 6 16:36:34 2016
@@ -64,3 +64,33 @@ struct v {
// MSVC: CXXConstructor=v{{.*}}[mangled=??0v@@QAE at H@Z] [mangled=??_Fv@@QAEXXZ]
+struct w {
+ virtual int m(int);
+};
+
+// ITANIUM: CXXMethod=m{{.*}} (virtual) [mangled=_ZN1w1mEi]
+
+// MACHO: CXXMethod=m{{.*}} (virtual) [mangled=__ZN1w1mEi]
+
+// MSVC: CXXMethod=m{{.*}} (virtual) [mangled=?m at w@@UAEHH at Z]
+
+struct x {
+ virtual int m(int);
+};
+
+// ITANIUM: CXXMethod=m{{.*}} (virtual) [mangled=_ZN1x1mEi]
+
+// MACHO: CXXMethod=m{{.*}} (virtual) [mangled=__ZN1x1mEi]
+
+// MSVC: CXXMethod=m{{.*}} (virtual) [mangled=?m at x@@UAEHH at Z]
+
+struct y : w, x {
+ virtual int m(int);
+};
+
+// ITANIUM: CXXMethod=m{{.*}} (virtual) {{.*}} [mangled=_ZN1y1mEi] [mangled=_ZThn4_N1y1mEi]
+
+// MACHO: CXXMethod=m{{.*}} (virtual) {{.*}} [mangled=__ZN1y1mEi] [mangled=__ZThn4_N1y1mEi]
+
+// MSVC: CXXMethod=m{{.*}} (virtual) {{.*}} [mangled=?m at y@@UAEHH at Z] [mangled=?m at y@@W3AEHH at Z]
+
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=260011&r1=260010&r2=260011&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sat Feb 6 16:36:34 2016
@@ -24,6 +24,7 @@
#include "clang/AST/Attr.h"
#include "clang/AST/Mangle.h"
#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/VTableBuilder.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticCategories.h"
#include "clang/Basic/DiagnosticIDs.h"
@@ -4368,6 +4369,38 @@ CXString clang_Cursor_getMangling(CXCurs
return cxstring::createDup(FinalBufOS.str());
}
+static std::string getMangledName(std::unique_ptr<MangleContext> &M,
+ std::unique_ptr<llvm::DataLayout> &DL,
+ const NamedDecl *ND) {
+ std::string FrontendBuf;
+ llvm::raw_string_ostream FOS(FrontendBuf);
+
+ M->mangleName(ND, FOS);
+
+ std::string BackendBuf;
+ llvm::raw_string_ostream BOS(BackendBuf);
+
+ llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL);
+
+ return BOS.str();
+}
+
+static std::string getMangledThunk(std::unique_ptr<MangleContext> &M,
+ std::unique_ptr<llvm::DataLayout> &DL,
+ const CXXMethodDecl *MD, const ThunkInfo &T) {
+ std::string FrontendBuf;
+ llvm::raw_string_ostream FOS(FrontendBuf);
+
+ M->mangleThunk(MD, T, FOS);
+
+ std::string BackendBuf;
+ llvm::raw_string_ostream BOS(BackendBuf);
+
+ llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL);
+
+ return BOS.str();
+}
+
CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {
if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
return nullptr;
@@ -4411,6 +4444,12 @@ CXStringSet *clang_Cursor_getCXXMangling
if (DD->isVirtual())
Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Deleting));
}
+ } else if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(ND)) {
+ Manglings.emplace_back(getMangledName(M, DL, ND));
+ if (MD->isVirtual())
+ if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD))
+ for (const auto &T : *TIV)
+ Manglings.emplace_back(getMangledThunk(M, DL, MD, T));
}
return cxstring::createSet(Manglings);
More information about the cfe-commits
mailing list