Dang, forgot to attach the patch...
On 8/15/10 7:16 PM, Charles Davis wrote:
> On 8/15/10 12:24 AM, Charles Davis wrote:
>> On 8/15/10 12:20 AM, Sean Hunt wrote:
>>> On 08/15/2010 12:18 AM, Charles Davis wrote:
>>>> This patch gives member pointers the correct size when the Microsoft ABI
>>>> is active. This only implements the Sema/AST side (CodeGen coming soon).
>>>>
>>>> Chip
>>>
>>> Is it possible to make this a function of the ABI, rather than
>>> hardcoding values into ASTContext?
>> Yeah, but we'd need an AST-side CXXABI object.
>>
>> I need to fix the patch anyway. In my haste, I forgot to test before
>> sending. :\
> Patch fixed. It adds this AST-side CXXABI object (and renames the
> CodeGen one to 'CGCXXABI' to avoid conflicts).
>
> On 8/15/10 12:34 AM, Eli Friedman wrote:
>> It would be nice to add the appropriate warning about constructing a
>> member pointer to an incomplete type along with this... otherwise we
>> can end up silently generating bad code.
> It would be, but I don't know how to issue a diagnostic from the AST
> library, so I've left that out for now.
>
> Chip
Index: include/clang/AST/ASTContext.h
===================================================================
--- include/clang/AST/ASTContext.h (revision 111114)
+++ include/clang/AST/ASTContext.h (working copy)
@@ -50,6 +50,7 @@
class SelectorTable;
class SourceManager;
class TargetInfo;
+ class CXXABI;
// Decls
class DeclContext;
class CXXMethodDecl;
@@ -283,6 +284,10 @@
/// \brief Allocator for partial diagnostics.
PartialDiagnostic::StorageAllocator DiagAllocator;
+
+ /// \brief The current C++ ABI.
+ CXXABI *ABI;
+ CXXABI *createCXXABI(const TargetInfo &T);
public:
const TargetInfo &Target;
Index: lib/AST/MicrosoftCXXABI.cpp
===================================================================
--- lib/AST/MicrosoftCXXABI.cpp (revision 0)
+++ lib/AST/MicrosoftCXXABI.cpp (revision 0)
@@ -0,0 +1,48 @@
+//===------- MicrosoftCXXABI.cpp - AST support for the Microsoft C++ ABI
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides C++ AST support targetting the Microsoft Visual C++
+// ABI.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CXXABI.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/DeclCXX.h"
+
+using namespace clang;
+
+namespace {
+class MicrosoftCXXABI : public CXXABI {
+ ASTContext &Context;
+public:
+ MicrosoftCXXABI(ASTContext &Ctx) : Context(Ctx) { }
+
+ unsigned getMemberPointerSize(const MemberPointerType *MPT) const;
+};
+}
+
+unsigned MicrosoftCXXABI::getMemberPointerSize(const MemberPointerType *MPT)
const {
+ QualType Pointee = MPT->getPointeeType();
+ CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
+ if (RD->getNumVBases() > 0) {
+ if (Pointee->isFunctionType())
+ return 3;
+ else
+ return 2;
+ } else if (RD->getNumBases() > 1 && Pointee->isFunctionType())
+ return 2;
+ return 1;
+}
+
+CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) {
+ return new MicrosoftCXXABI(Ctx);
+}
+
Index: lib/AST/ItaniumCXXABI.cpp
===================================================================
--- lib/AST/ItaniumCXXABI.cpp (revision 0)
+++ lib/AST/ItaniumCXXABI.cpp (revision 0)
@@ -0,0 +1,39 @@
+//===------- ItaniumCXXABI.cpp - AST support for the Itanium C++ ABI
------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides C++ AST support targetting the Itanium C++ ABI, which is
+// documented at:
+// http://www.codesourcery.com/public/cxx-abi/abi.html
+// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
+//===----------------------------------------------------------------------===//
+
+#include "CXXABI.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+
+using namespace clang;
+
+namespace {
+class ItaniumCXXABI : public CXXABI {
+ ASTContext &Context;
+public:
+ ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { }
+
+ unsigned getMemberPointerSize(const MemberPointerType *MPT) const {
+ QualType Pointee = MPT->getPointeeType();
+ if (Pointee->isFunctionType()) return 2;
+ return 1;
+ }
+};
+}
+
+CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
+ return new ItaniumCXXABI(Ctx);
+}
+
Index: lib/AST/CMakeLists.txt
===================================================================
--- lib/AST/CMakeLists.txt (revision 111114)
+++ lib/AST/CMakeLists.txt (working copy)
@@ -23,6 +23,8 @@
ExprCXX.cpp
FullExpr.cpp
InheritViz.cpp
+ ItaniumCXXABI.cpp
+ MicrosoftCXXABI.cpp
NestedNameSpecifier.cpp
ParentMap.cpp
RecordLayout.cpp
Index: lib/AST/CXXABI.h
===================================================================
--- lib/AST/CXXABI.h (revision 0)
+++ lib/AST/CXXABI.h (revision 0)
@@ -0,0 +1,38 @@
+//===----- CXXABI.h - Interface to C++ ABIs ---------------------*- C++
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides an abstract class for C++ AST support. Concrete
+// subclasses of this implement AST support for specific C++ ABIs.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_CXXABI_H
+#define LLVM_CLANG_AST_CXXABI_H
+
+namespace clang {
+
+class ASTContext;
+class MemberPointerType;
+
+/// Implements C++ ABI-specific semantic analysis functions.
+class CXXABI {
+public:
+ virtual ~CXXABI();
+
+ /// Returns the size of a member pointer in multiples of the target
+ /// pointer size.
+ virtual unsigned getMemberPointerSize(const MemberPointerType *MPT) const =
0;
+};
+
+/// Creates an instance of a C++ ABI class.
+CXXABI *CreateItaniumCXXABI(ASTContext &Ctx);
+CXXABI *CreateMicrosoftCXXABI(ASTContext &Ctx);
+}
+
+#endif
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp (revision 111114)
+++ lib/AST/ASTContext.cpp (working copy)
@@ -28,6 +28,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
+#include "CXXABI.h"
using namespace clang;
@@ -134,6 +135,14 @@
return CanonTTP;
}
+CXXABI *ASTContext::createCXXABI(const TargetInfo &T) {
+ if (!LangOpts.CPlusPlus) return NULL;
+ if (T.getCXXABI() == "microsoft")
+ return CreateMicrosoftCXXABI(*this);
+ else
+ return CreateItaniumCXXABI(*this);
+}
+
ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
const TargetInfo &t,
IdentifierTable &idents, SelectorTable &sels,
@@ -146,7 +155,7 @@
ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0),
sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0),
NullTypeSourceInfo(QualType()),
- SourceMgr(SM), LangOpts(LOpts), Target(t),
+ SourceMgr(SM), LangOpts(LOpts), ABI(createCXXABI(t)), Target(t),
Idents(idents), Selectors(sels),
BuiltinInfo(builtins),
DeclarationNames(*this),
@@ -700,12 +709,10 @@
break;
}
case Type::MemberPointer: {
- QualType Pointee = cast<MemberPointerType>(T)->getPointeeType();
+ const MemberPointerType *MPT = cast<MemberPointerType>(T);
std::pair<uint64_t, unsigned> PtrDiffInfo =
getTypeInfo(getPointerDiffType());
- Width = PtrDiffInfo.first;
- if (Pointee->isFunctionType())
- Width *= 2;
+ Width = PtrDiffInfo.first * ABI->getMemberPointerSize(MPT);
Align = PtrDiffInfo.second;
break;
}
@@ -5640,3 +5647,5 @@
return true;
}
+
+CXXABI::~CXXABI() {}
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- lib/CodeGen/MicrosoftCXXABI.cpp (revision 111114)
+++ lib/CodeGen/MicrosoftCXXABI.cpp (working copy)
@@ -110,7 +110,7 @@
llvm::SmallVectorImpl<char> &);
};
-class MicrosoftCXXABI : public CXXABI {
+class MicrosoftCXXABI : public CGCXXABI {
MicrosoftMangleContext MangleCtx;
public:
MicrosoftCXXABI(CodeGenModule &CGM)
@@ -1185,7 +1185,7 @@
assert(false && "Can't yet mangle destructors!");
}
-CXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
+CGCXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
return new MicrosoftCXXABI(CGM);
}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- lib/CodeGen/ItaniumCXXABI.cpp (revision 111114)
+++ lib/CodeGen/ItaniumCXXABI.cpp (working copy)
@@ -21,7 +21,7 @@
using namespace clang;
namespace {
-class ItaniumCXXABI : public CodeGen::CXXABI {
+class ItaniumCXXABI : public CodeGen::CGCXXABI {
CodeGen::MangleContext MangleCtx;
public:
ItaniumCXXABI(CodeGen::CodeGenModule &CGM) :
@@ -33,7 +33,7 @@
};
}
-CodeGen::CXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
+CodeGen::CGCXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
return new ItaniumCXXABI(CGM);
}
Index: lib/CodeGen/CGCXX.cpp
===================================================================
--- lib/CodeGen/CGCXX.cpp (revision 111114)
+++ lib/CodeGen/CGCXX.cpp (working copy)
@@ -356,4 +356,4 @@
return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
}
-CXXABI::~CXXABI() {}
+CGCXXABI::~CGCXXABI() {}
Index: lib/CodeGen/CodeGenModule.h
===================================================================
--- lib/CodeGen/CodeGenModule.h (revision 111114)
+++ lib/CodeGen/CodeGenModule.h (working copy)
@@ -116,7 +116,7 @@
friend class CodeGenVTables;
CGObjCRuntime* Runtime;
- CXXABI* ABI;
+ CGCXXABI* ABI;
CGDebugInfo* DebugInfo;
// WeakRefReferences - A set of references that have only been seen via
@@ -230,7 +230,7 @@
/// getCXXABI() - Return a reference to the configured
/// C++ ABI.
- CXXABI &getCXXABI() {
+ CGCXXABI &getCXXABI() {
if (!ABI) createCXXABI();
return *ABI;
}
Index: lib/CodeGen/CGCXXABI.h
===================================================================
--- lib/CodeGen/CGCXXABI.h (revision 111114)
+++ lib/CodeGen/CGCXXABI.h (working copy)
@@ -21,17 +21,17 @@
class MangleContext;
/// Implements C++ ABI-specific code generation functions.
-class CXXABI {
+class CGCXXABI {
public:
- virtual ~CXXABI();
+ virtual ~CGCXXABI();
/// Gets the mangle context.
virtual MangleContext &getMangleContext() = 0;
};
/// Creates an instance of a C++ ABI class.
-CXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
-CXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
+CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
+CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
}
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits