From 50de3522e699b23dee10bb8d1ef962c27b56f026 Mon Sep 17 00:00:00 2001 From: Warren Hunt Date: Thu, 26 Dec 2013 22:09:12 +0000 Subject: [ms-abi] Fixes improperly sized vfptrs with pragma pack With pragma pack, the layout engine would produce vfptrs that were packed width rather than pointer width. This patch addresses the issue and adds a test case. llvm-svn: 198059 --- clang/lib/AST/RecordLayoutBuilder.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'clang/lib/AST/RecordLayoutBuilder.cpp') diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index 74010ce7aa0..832bfef90c9 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -2316,15 +2316,14 @@ void MicrosoftRecordLayoutBuilder::layoutVFPtr(const CXXRecordDecl *RD) { if (!HasExtendableVFPtr) return; + updateAlignment(PointerAlignment); + Size = Size.RoundUpToAlignment(PointerAlignment) + PointerSize; // MSVC 32 (but not 64) potentially over-aligns the vf-table pointer by giving // it the max alignment of all the non-virtual data in the class. The // resulting layout is essentially { vftbl, { nvdata } }. This is completely // unnecessary, but we're not here to pass judgment. - updateAlignment(PointerAlignment); - if (Is64BitMode) - Size = Size.RoundUpToAlignment(PointerAlignment) + PointerSize; - else - Size = Size.RoundUpToAlignment(PointerAlignment) + Alignment; + if (!Is64BitMode && Alignment > PointerSize) + Size += Alignment - PointerSize; } void -- cgit v1.2.3