From 1cca74ef3627a3a0ab14501d23e336548f6611b2 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 17 May 2009 02:06:04 +0000 Subject: [PATCH] Use the Itanium ABI for member pointers. Add a missing 'break' statement and a test case git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71972 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 18 +++++++++--------- test/SemaCXX/member-pointer-size.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 test/SemaCXX/member-pointer-size.cpp diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ccd3762da0..329d6c478d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -475,18 +475,18 @@ ASTContext::getTypeInfo(const Type *T) { // pointer size. return getTypeInfo(cast(T)->getPointeeType()); case Type::MemberPointer: { - // FIXME: This is not only platform- but also ABI-dependent. We follow - // the GCC ABI, where pointers to data are one pointer large, pointers to - // functions two pointers. But if we want to support ABI compatibility with - // other compilers too, we need to delegate this completely to TargetInfo - // or some ABI abstraction layer. + // 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 Pointee = cast(T)->getPointeeType(); - unsigned AS = Pointee.getAddressSpace(); - Width = Target.getPointerWidth(AS); + std::pair PtrDiffInfo = + getTypeInfo(getPointerDiffType()); + Width = PtrDiffInfo.first; if (Pointee->isFunctionType()) Width *= 2; - Align = Target.getPointerAlign(AS); - // GCC aligns at single pointer width. + Align = PtrDiffInfo.second; + break; } case Type::Complex: { // Complex types have the same alignment as their elements, but twice the diff --git a/test/SemaCXX/member-pointer-size.cpp b/test/SemaCXX/member-pointer-size.cpp new file mode 100644 index 0000000000..f86e72b288 --- /dev/null +++ b/test/SemaCXX/member-pointer-size.cpp @@ -0,0 +1,15 @@ +// RUN: clang-cc -triple x86_64-unknown-unknown %s -fsyntax-only -verify && +// RUN: clang-cc -triple i686-unknown-unknown %s -fsyntax-only -verify +#include + +struct A; + +void f() { + int A::*dataMember; + + int (A::*memberFunction)(); + + typedef int assert1[sizeof(dataMember) == sizeof(ptrdiff_t) ? 1 : -1]; + typedef int assert2[sizeof(memberFunction) == sizeof(ptrdiff_t) * 2 ? 1 : -1]; +} + -- 2.40.0