]> granicus.if.org Git - clang/commitdiff
Implement support for member pointers under the Microsoft C++ ABI in the
authorCharles Davis <cdavis@mines.edu>
Mon, 16 Aug 2010 03:33:14 +0000 (03:33 +0000)
committerCharles Davis <cdavis@mines.edu>
Mon, 16 Aug 2010 03:33:14 +0000 (03:33 +0000)
AST library.

This also adds infrastructure for supporting multiple C++ ABIs in the AST.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111117 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/AST/CMakeLists.txt
lib/AST/CXXABI.h [new file with mode: 0644]
lib/AST/ItaniumCXXABI.cpp [new file with mode: 0644]
lib/AST/MicrosoftCXXABI.cpp [new file with mode: 0644]
lib/CodeGen/CGCXX.cpp
lib/CodeGen/CGCXXABI.h
lib/CodeGen/CodeGenModule.h
lib/CodeGen/ItaniumCXXABI.cpp
lib/CodeGen/MicrosoftCXXABI.cpp

index 747c46e6f15da9a51068566b0c2a52f274cc05f4..fc928f3858805899cdf2b6fdb694e028313d0463 100644 (file)
@@ -50,6 +50,7 @@ namespace clang {
   class SelectorTable;
   class SourceManager;
   class TargetInfo;
+  class CXXABI;
   // Decls
   class DeclContext;
   class CXXMethodDecl;
@@ -283,6 +284,10 @@ class ASTContext {
 
   /// \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 adb75f0f61ef927739840ae965c7f817903c8854..1e437fdabeba96922e0983d83da043b6cc9cee4f 100644 (file)
@@ -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 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
   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 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
   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 @@ ASTContext::getTypeInfo(const Type *T) {
     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 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
 
   return true;
 }
+
+CXXABI::~CXXABI() {}
index 407ed95f3ee1b08be1880f6c04031167dd7840c9..b340c0464cc696fb202b4b4ae687356db6cb537e 100644 (file)
@@ -23,6 +23,8 @@ add_clang_library(clangAST
   ExprCXX.cpp
   FullExpr.cpp
   InheritViz.cpp
+  ItaniumCXXABI.cpp
+  MicrosoftCXXABI.cpp
   NestedNameSpecifier.cpp
   ParentMap.cpp
   RecordLayout.cpp
diff --git a/lib/AST/CXXABI.h b/lib/AST/CXXABI.h
new file mode 100644 (file)
index 0000000..8781bd7
--- /dev/null
@@ -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
diff --git a/lib/AST/ItaniumCXXABI.cpp b/lib/AST/ItaniumCXXABI.cpp
new file mode 100644 (file)
index 0000000..0ac80ec
--- /dev/null
@@ -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);
+}
+
diff --git a/lib/AST/MicrosoftCXXABI.cpp b/lib/AST/MicrosoftCXXABI.cpp
new file mode 100644 (file)
index 0000000..87b7767
--- /dev/null
@@ -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 7b7be9a260edafdb696eeeceeaee960caf29a28f..edfbe0e72ee71290d27ed8f10d66edefbaff4b8b 100644 (file)
@@ -356,4 +356,4 @@ CodeGenFunction::BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
   return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
 }
 
-CXXABI::~CXXABI() {}
+CGCXXABI::~CGCXXABI() {}
index e1bbb0a79cce7c5e7279c99c4f602c036caa54c7..0cebcb1c31bc6960415cc84e1cc728e7d0cc2b2e 100644 (file)
@@ -21,17 +21,17 @@ namespace CodeGen {
   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);
 }
 }
 
index c7578788a5728e593aba108b04144e54f84afa63..eca449c702e0b14bb69dd0e38dbe1b42c413b856 100644 (file)
@@ -116,7 +116,7 @@ class CodeGenModule : public BlockModule {
   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 @@ public:
 
   /// getCXXABI() - Return a reference to the configured
   /// C++ ABI.
-  CXXABI &getCXXABI() {
+  CGCXXABI &getCXXABI() {
     if (!ABI) createCXXABI();
     return *ABI;
   }
index 98db75ea2b4646c4238a2c0ab1a403255ade2a69..a6137692fbd79b83acb18184edc5a3dc09c48c58 100644 (file)
@@ -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 @@ public:
 };
 }
 
-CodeGen::CXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
+CodeGen::CGCXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
   return new ItaniumCXXABI(CGM);
 }
 
index da0fdb616d6c68766e32c383c5747ea6930928d9..cfc635a7a4c0abc08db5d7e292e5871c8aefc9d7 100644 (file)
@@ -110,7 +110,7 @@ public:
                              llvm::SmallVectorImpl<char> &);
 };
 
-class MicrosoftCXXABI : public CXXABI {
+class MicrosoftCXXABI : public CGCXXABI {
   MicrosoftMangleContext MangleCtx;
 public:
   MicrosoftCXXABI(CodeGenModule &CGM)
@@ -1185,7 +1185,7 @@ void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
   assert(false && "Can't yet mangle destructors!");
 }
 
-CXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
+CGCXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
   return new MicrosoftCXXABI(CGM);
 }