From 0e650017acdbbeb0c590e77bbea88c200ea1caef Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 17 May 2009 17:41:20 +0000 Subject: [PATCH] Add support for converting member pointer types to LLVM types. Also mangle pointer to member functions correctly and add tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71981 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 19 +++++++++++++------ lib/CodeGen/Mangle.cpp | 7 ++++++- test/CodeGenCXX/mangle.cpp | 10 +++++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index a9d4615d2a..af791f6318 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -385,12 +385,19 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { return llvm::PointerType::get(PointeeType, FTy.getAddressSpace()); } - case Type::MemberPointer: - // FIXME: Implement C++ pointer-to-member. The GCC representation is - // documented here: - // http://gcc.gnu.org/onlinedocs/gccint/Type-Layout.html#Type-Layout - assert(0 && "FIXME: We can't handle member pointers yet."); - return llvm::OpaqueType::get(); + case Type::MemberPointer: { + // FIXME: This is ABI dependent. We use the Itanium C++ ABI. + // http://www.codesourcery.com/public/cxx-abi/abi.html#member-pointers + // If we ever want to support other ABIs this needs to be abstracted. + + QualType ETy = cast(Ty).getPointeeType(); + if (ETy->isFunctionType()) { + return llvm::StructType::get(ConvertType(Context.getPointerDiffType()), + ConvertType(Context.getPointerDiffType()), + NULL); + } else + return ConvertType(Context.getPointerDiffType()); + } case Type::TemplateSpecialization: assert(false && "Dependent types can't get here"); diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index c27ef4fd97..c09a13a59f 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -608,7 +608,12 @@ void CXXNameMangler::mangleType(const MemberPointerType *T) { // ::= M Out << 'M'; mangleType(QualType(T->getClass(), 0)); - mangleType(T->getPointeeType()); + QualType PointeeType = T->getPointeeType(); + if (const FunctionProtoType *FPT = dyn_cast(PointeeType)) { + mangleCVQualifiers(FPT->getTypeQuals()); + mangleType(FPT); + } else + mangleType(PointeeType); } void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 86a72011da..ef36a8b23c 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -75,5 +75,13 @@ void f(S3) {} // RUN: grep "_Z1f2S3ILb0EE" %t | count 1 && void f(S3) {} -// RUN: grep "_Z2f22S3ILb1EE" %t | count 1 +// RUN: grep "_Z2f22S3ILb1EE" %t | count 1 && void f2(S3<100>) {} + +struct S; + +// RUN: grep "_Z1fM1SKFvvE" %t | count 1 && +void f(void (S::*)() const) {} + +// RUN: grep "_Z1fM1SFvvE" %t | count 1 +void f(void (S::*)()) {} -- 2.40.0