leonardchan updated this revision to Diff 259602.
leonardchan added a comment.

Updated to reflect the changes in D72959 <https://reviews.llvm.org/D72959> 
which make the vtable 4-byte aligned under the `Relative` layout.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77592/new/

https://reviews.llvm.org/D77592

Files:
  clang/include/clang/AST/VTableBuilder.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/VTableBuilder.cpp


Index: clang/lib/AST/VTableBuilder.cpp
===================================================================
--- clang/lib/AST/VTableBuilder.cpp
+++ clang/lib/AST/VTableBuilder.cpp
@@ -2221,8 +2221,9 @@
 
 VTableLayout::~VTableLayout() { }
 
-ItaniumVTableContext::ItaniumVTableContext(ASTContext &Context)
-    : VTableContextBase(/*MS=*/false) {}
+ItaniumVTableContext::ItaniumVTableContext(
+    ASTContext &Context, VTableComponentLayout ComponentLayout)
+    : VTableContextBase(/*MS=*/false), ComponentLayout(ComponentLayout) {}
 
 ItaniumVTableContext::~ItaniumVTableContext() {}
 
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10463,6 +10463,8 @@
     if (Target->getCXXABI().isMicrosoft())
       VTContext.reset(new MicrosoftVTableContext(*this));
     else
+      // TODO: Specify that we want to use the Relative VTableComponentLayout
+      // here once we add the option for selecting it for Fuchsia.
       VTContext.reset(new ItaniumVTableContext(*this));
   }
   return VTContext.get();
Index: clang/include/clang/AST/VTableBuilder.h
===================================================================
--- clang/include/clang/AST/VTableBuilder.h
+++ clang/include/clang/AST/VTableBuilder.h
@@ -371,7 +371,20 @@
   void computeVTableRelatedInformation(const CXXRecordDecl *RD) override;
 
 public:
-  ItaniumVTableContext(ASTContext &Context);
+  enum VTableComponentLayout {
+    /// Components in the vtable are pointers to other structs/functions.
+    /// Offsets are of size ptrdiff_t, making the entire vtable pointer 
aligned.
+    /// This is the default layout.
+    Pointer,
+
+    /// Components in the vtable are relative 32-bit offsets between the vtable
+    /// and other structs/functions. Offsets will be 32-bits, making the entire
+    /// vtable 4-byte aligned.
+    Relative,
+  };
+
+  ItaniumVTableContext(ASTContext &Context,
+                       VTableComponentLayout ComponentLayout = Pointer);
   ~ItaniumVTableContext() override;
 
   const VTableLayout &getVTableLayout(const CXXRecordDecl *RD) {
@@ -402,6 +415,16 @@
   static bool classof(const VTableContextBase *VT) {
     return !VT->isMicrosoft();
   }
+
+  VTableComponentLayout getVTableComponentLayout() const {
+    return ComponentLayout;
+  }
+
+  bool isPointerLayout() const { return ComponentLayout == Pointer; }
+  bool isRelativeLayout() const { return ComponentLayout == Relative; }
+
+private:
+  VTableComponentLayout ComponentLayout;
 };
 
 /// Holds information about the inheritance path to a virtual base or function


Index: clang/lib/AST/VTableBuilder.cpp
===================================================================
--- clang/lib/AST/VTableBuilder.cpp
+++ clang/lib/AST/VTableBuilder.cpp
@@ -2221,8 +2221,9 @@
 
 VTableLayout::~VTableLayout() { }
 
-ItaniumVTableContext::ItaniumVTableContext(ASTContext &Context)
-    : VTableContextBase(/*MS=*/false) {}
+ItaniumVTableContext::ItaniumVTableContext(
+    ASTContext &Context, VTableComponentLayout ComponentLayout)
+    : VTableContextBase(/*MS=*/false), ComponentLayout(ComponentLayout) {}
 
 ItaniumVTableContext::~ItaniumVTableContext() {}
 
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10463,6 +10463,8 @@
     if (Target->getCXXABI().isMicrosoft())
       VTContext.reset(new MicrosoftVTableContext(*this));
     else
+      // TODO: Specify that we want to use the Relative VTableComponentLayout
+      // here once we add the option for selecting it for Fuchsia.
       VTContext.reset(new ItaniumVTableContext(*this));
   }
   return VTContext.get();
Index: clang/include/clang/AST/VTableBuilder.h
===================================================================
--- clang/include/clang/AST/VTableBuilder.h
+++ clang/include/clang/AST/VTableBuilder.h
@@ -371,7 +371,20 @@
   void computeVTableRelatedInformation(const CXXRecordDecl *RD) override;
 
 public:
-  ItaniumVTableContext(ASTContext &Context);
+  enum VTableComponentLayout {
+    /// Components in the vtable are pointers to other structs/functions.
+    /// Offsets are of size ptrdiff_t, making the entire vtable pointer aligned.
+    /// This is the default layout.
+    Pointer,
+
+    /// Components in the vtable are relative 32-bit offsets between the vtable
+    /// and other structs/functions. Offsets will be 32-bits, making the entire
+    /// vtable 4-byte aligned.
+    Relative,
+  };
+
+  ItaniumVTableContext(ASTContext &Context,
+                       VTableComponentLayout ComponentLayout = Pointer);
   ~ItaniumVTableContext() override;
 
   const VTableLayout &getVTableLayout(const CXXRecordDecl *RD) {
@@ -402,6 +415,16 @@
   static bool classof(const VTableContextBase *VT) {
     return !VT->isMicrosoft();
   }
+
+  VTableComponentLayout getVTableComponentLayout() const {
+    return ComponentLayout;
+  }
+
+  bool isPointerLayout() const { return ComponentLayout == Pointer; }
+  bool isRelativeLayout() const { return ComponentLayout == Relative; }
+
+private:
+  VTableComponentLayout ComponentLayout;
 };
 
 /// Holds information about the inheritance path to a virtual base or function
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to