[cfe-commits] r71972 - in /cfe/trunk: lib/AST/ASTContext.cpp test/SemaCXX/member-pointer-size.cpp
Anders Carlsson
andersca at mac.com
Sat May 16 19:06:04 PDT 2009
Author: andersca
Date: Sat May 16 21:06:04 2009
New Revision: 71972
URL: http://llvm.org/viewvc/llvm-project?rev=71972&view=rev
Log:
Use the Itanium ABI for member pointers. Add a missing 'break' statement and a test case
Added:
cfe/trunk/test/SemaCXX/member-pointer-size.cpp
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=71972&r1=71971&r2=71972&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat May 16 21:06:04 2009
@@ -475,18 +475,18 @@
// pointer size.
return getTypeInfo(cast<ReferenceType>(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<MemberPointerType>(T)->getPointeeType();
- unsigned AS = Pointee.getAddressSpace();
- Width = Target.getPointerWidth(AS);
+ std::pair<uint64_t, unsigned> 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
Added: cfe/trunk/test/SemaCXX/member-pointer-size.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointer-size.cpp?rev=71972&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/member-pointer-size.cpp (added)
+++ cfe/trunk/test/SemaCXX/member-pointer-size.cpp Sat May 16 21:06:04 2009
@@ -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 <stddef.h>
+
+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];
+}
+
More information about the cfe-commits
mailing list