[llvm-branch-commits] [cfe-branch] r195167 - Merging r195158:

Bill Wendling isanbard at gmail.com
Tue Nov 19 15:16:16 PST 2013


Author: void
Date: Tue Nov 19 17:16:16 2013
New Revision: 195167

URL: http://llvm.org/viewvc/llvm-project?rev=195167&view=rev
Log:
Merging r195158:
------------------------------------------------------------------------
r195158 | whunt | 2013-11-19 14:11:09 -0800 (Tue, 19 Nov 2013) | 9 lines

Microsoft Record Layout: zero sized base after base with vbtbl fix

Microsoft adds an extra byte of padding before laying out zero sized 
non-virtual bases if the non-virtual base before it contains a vbptr.  
This patch adds the same behavior to clang.

Differential Revision: http://llvm-reviews.chandlerc.com/D2106


------------------------------------------------------------------------

Added:
    cfe/branches/release_34/test/Layout/ms-x86-empty-base-after-base-with-vbptr.cpp
      - copied unchanged from r195158, cfe/trunk/test/Layout/ms-x86-empty-base-after-base-with-vbptr.cpp
Modified:
    cfe/branches/release_34/   (props changed)
    cfe/branches/release_34/lib/AST/RecordLayoutBuilder.cpp

Propchange: cfe/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Nov 19 17:16:16 2013
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:195126,195128,195135-195136,195163
+/cfe/trunk:195126,195128,195135-195136,195158,195163
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_34/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/AST/RecordLayoutBuilder.cpp?rev=195167&r1=195166&r2=195167&view=diff
==============================================================================
--- cfe/branches/release_34/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/branches/release_34/lib/AST/RecordLayoutBuilder.cpp Tue Nov 19 17:16:16 2013
@@ -2017,6 +2017,8 @@ static bool isMsLayout(const RecordDecl*
 // * If the last field is a non-zero length bitfield and we have any virtual
 //   bases then some extra padding is added before the virtual bases for no
 //   obvious reason.
+// * When laying out empty non-virtual bases, an extra byte of padding is added
+//   if the non-virtual base before the empty non-virtual base has a vbptr.
 
 
 namespace {
@@ -2141,6 +2143,8 @@ public:
   bool LastBaseWasEmpty;
   /// \brief Lets us know if we're in 64-bit mode
   bool Is64BitMode;
+  /// \brief True if the last non-virtual base has a vbptr.
+  bool LastNonVirtualBaseHasVBPtr;
 };
 } // namespace
 
@@ -2304,6 +2308,7 @@ void
 MicrosoftRecordLayoutBuilder::layoutNonVirtualBases(const CXXRecordDecl *RD) {
   LazyEmptyBase = 0;
   LastBaseWasEmpty = false;
+  LastNonVirtualBaseHasVBPtr = false;
 
   // Lay out the primary base first.
   if (PrimaryBase)
@@ -2331,6 +2336,10 @@ MicrosoftRecordLayoutBuilder::layoutNonV
     const ASTRecordLayout &LazyLayout =
         Context.getASTRecordLayout(LazyEmptyBase);
     Size = Size.RoundUpToAlignment(LazyLayout.getAlignment());
+    // If the last non-virtual base has a vbptr we add a byte of padding for no
+    // obvious reason.
+    if (LastNonVirtualBaseHasVBPtr)
+      Size++;
     Bases.insert(std::make_pair(LazyEmptyBase, Size));
     // Empty bases only consume space when followed by another empty base.
     if (RD && Layout->getNonVirtualSize().isZero()) {
@@ -2338,6 +2347,7 @@ MicrosoftRecordLayoutBuilder::layoutNonV
       Size++;
     }
     LazyEmptyBase = 0;
+    LastNonVirtualBaseHasVBPtr = false;
   }
 
   // RD is null when flushing the final lazy base.
@@ -2356,6 +2366,7 @@ MicrosoftRecordLayoutBuilder::layoutNonV
   // Note: we don't update alignment here because it was accounted
   // for during initalization.
   LastBaseWasEmpty = false;
+  LastNonVirtualBaseHasVBPtr = Layout->hasVBPtr();
 }
 
 void MicrosoftRecordLayoutBuilder::layoutVBPtr(const CXXRecordDecl *RD) {





More information about the llvm-branch-commits mailing list