//===------- MicrosoftCXXABI.cpp - AST support for the Microsoft C++ ABI --===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This provides C++ AST support targeting the Microsoft Visual C++ // ABI. // //===----------------------------------------------------------------------===// #include "CXXABI.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "clang/AST/CXXInheritance.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/Mangle.h" #include "clang/AST/MangleNumberingContext.h" #include "clang/AST/RecordLayout.h" #include "clang/AST/Type.h" #include "clang/Basic/TargetInfo.h" usingnamespaceclang; namespace { /// Numbers things which need to correspond across multiple TUs. /// Typically these are things like static locals, lambdas, or blocks. class MicrosoftNumberingContext : public MangleNumberingContext { … }; class MSHIPNumberingContext : public MicrosoftNumberingContext { … }; class MSSYCLNumberingContext : public MicrosoftNumberingContext { … }; class MicrosoftCXXABI : public CXXABI { … }; } // getNumBases() seems to only give us the number of direct bases, and not the // total. This function tells us if we inherit from anybody that uses MI, or if // we have a non-primary base class, which uses the multiple inheritance model. static bool usesMultipleInheritanceModel(const CXXRecordDecl *RD) { … } MSInheritanceModel CXXRecordDecl::calculateInheritanceModel() const { … } MSInheritanceModel CXXRecordDecl::getMSInheritanceModel() const { … } bool CXXRecordDecl::nullFieldOffsetIsZero() const { … } MSVtorDispMode CXXRecordDecl::getMSVtorDispMode() const { … } // Returns the number of pointer and integer slots used to represent a member // pointer in the MS C++ ABI. // // Member function pointers have the following general form; however, fields // are dropped as permitted (under the MSVC interpretation) by the inheritance // model of the actual class. // // struct { // // A pointer to the member function to call. If the member function is // // virtual, this will be a thunk that forwards to the appropriate vftable // // slot. // void *FunctionPointerOrVirtualThunk; // // // An offset to add to the address of the vbtable pointer after // // (possibly) selecting the virtual base but before resolving and calling // // the function. // // Only needed if the class has any virtual bases or bases at a non-zero // // offset. // int NonVirtualBaseAdjustment; // // // The offset of the vb-table pointer within the object. Only needed for // // incomplete types. // int VBPtrOffset; // // // An offset within the vb-table that selects the virtual base containing // // the member. Loading from this offset produces a new offset that is // // added to the address of the vb-table pointer to produce the base. // int VirtualBaseAdjustmentOffset; // }; static std::pair<unsigned, unsigned> getMSMemberPointerSlots(const MemberPointerType *MPT) { … } CXXABI::MemberPointerInfo MicrosoftCXXABI::getMemberPointerInfo( const MemberPointerType *MPT) const { … } CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) { … }