From: David Majnemer Date: Fri, 24 Apr 2015 01:24:59 +0000 (+0000) Subject: Cleanup some MS-ABI specific code X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f3cb3aa2d9b4afce0c8b818ecb5b8fc590c74dd7;p=clang Cleanup some MS-ABI specific code No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235680 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/MicrosoftCXXABI.cpp b/lib/AST/MicrosoftCXXABI.cpp index fb3beff4be..4eb960a60d 100644 --- a/lib/AST/MicrosoftCXXABI.cpp +++ b/lib/AST/MicrosoftCXXABI.cpp @@ -213,29 +213,28 @@ getMSMemberPointerSlots(const MemberPointerType *MPT) { std::pair MicrosoftCXXABI::getMemberPointerWidthAndAlign( const MemberPointerType *MPT) const { - const TargetInfo &Target = Context.getTargetInfo(); - assert(Target.getTriple().getArch() == llvm::Triple::x86 || - Target.getTriple().getArch() == llvm::Triple::x86_64); - unsigned Ptrs, Ints; - std::tie(Ptrs, Ints) = getMSMemberPointerSlots(MPT); // The nominal struct is laid out with pointers followed by ints and aligned // to a pointer width if any are present and an int width otherwise. + const TargetInfo &Target = Context.getTargetInfo(); unsigned PtrSize = Target.getPointerWidth(0); unsigned IntSize = Target.getIntWidth(); + + unsigned Ptrs, Ints; + std::tie(Ptrs, Ints) = getMSMemberPointerSlots(MPT); uint64_t Width = Ptrs * PtrSize + Ints * IntSize; unsigned Align; // When MSVC does x86_32 record layout, it aligns aggregate member pointers to // 8 bytes. However, __alignof usually returns 4 for data memptrs and 8 for // function memptrs. - if (Ptrs + Ints > 1 && Target.getTriple().getArch() == llvm::Triple::x86) - Align = 8 * 8; + if (Ptrs + Ints > 1 && Target.getTriple().isArch32Bit()) + Align = 64; else if (Ptrs) Align = Target.getPointerAlign(0); else Align = Target.getIntAlign(); - if (Target.getTriple().getArch() == llvm::Triple::x86_64) + if (Target.getTriple().isArch64Bit()) Width = llvm::RoundUpToAlignment(Width, Align); return std::make_pair(Width, Align); } diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index ba92587679..8c9f57deb2 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -2379,8 +2379,9 @@ void MicrosoftRecordLayoutBuilder::initializeLayout(const RecordDecl *RD) { // In 64-bit mode we always perform an alignment step after laying out vbases. // In 32-bit mode we do not. The check to see if we need to perform alignment // checks the RequiredAlignment field and performs alignment if it isn't 0. - RequiredAlignment = Context.getTargetInfo().getPointerWidth(0) == 64 ? - CharUnits::One() : CharUnits::Zero(); + RequiredAlignment = Context.getTargetInfo().getTriple().isArch64Bit() + ? CharUnits::One() + : CharUnits::Zero(); // Compute the maximum field alignment. MaxFieldAlignment = CharUnits::Zero(); // Honor the default struct packing maximum alignment flag. @@ -2417,7 +2418,8 @@ MicrosoftRecordLayoutBuilder::initializeCXXLayout(const CXXRecordDecl *RD) { // injection. PointerInfo.Size = Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); - PointerInfo.Alignment = PointerInfo.Size; + PointerInfo.Alignment = + Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerAlign(0)); // Respect pragma pack. if (!MaxFieldAlignment.isZero()) PointerInfo.Alignment = std::min(PointerInfo.Alignment, MaxFieldAlignment);