clang 24.0.0git
RecordLayout.cpp
Go to the documentation of this file.
1//===- RecordLayout.cpp - Layout information for a struct/union -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the RecordLayout interface.
10//
11//===----------------------------------------------------------------------===//
12
17#include <cassert>
18#include <utility>
19
20using namespace clang;
21
22void ASTRecordLayout::Destroy(ASTContext &Ctx) {
23 if (CXXInfo) {
24 CXXInfo->~CXXRecordLayoutInfo();
25 Ctx.Deallocate(CXXInfo);
26 }
27 this->~ASTRecordLayout();
28 Ctx.Deallocate(this);
29}
30
31ASTRecordLayout::ASTRecordLayout(
32 const ASTContext &Ctx, CharUnits size, CharUnits alignment,
33 CharUnits preferredAlignment, CharUnits unadjustedAlignment,
34 CharUnits requiredAlignment, CharUnits pragmaPackResistantAlignment,
35 CharUnits datasize, ArrayRef<uint64_t> fieldoffsets)
36 : Size(size), DataSize(datasize), Alignment(alignment),
37 PreferredAlignment(preferredAlignment),
38 UnadjustedAlignment(unadjustedAlignment),
39 RequiredAlignment(requiredAlignment),
40 PragmaPackResistantAlignment(pragmaPackResistantAlignment) {
41 FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
42}
43
44// Constructor for C++ records.
45ASTRecordLayout::ASTRecordLayout(
46 const ASTContext &Ctx, CharUnits size, CharUnits alignment,
47 CharUnits preferredAlignment, CharUnits unadjustedAlignment,
48 CharUnits requiredAlignment, CharUnits pragmaPackResistantAlignment,
49 bool hasOwnVFPtr, bool hasExtendableVFPtr, CharUnits vbptroffset,
50 CharUnits datasize, ArrayRef<uint64_t> fieldoffsets,
51 CharUnits nonvirtualsize, CharUnits nonvirtualalignment,
52 CharUnits preferrednvalignment, CharUnits nonrequirednvalignment,
53 CharUnits SizeOfLargestEmptySubobject, const CXXRecordDecl *PrimaryBase,
54 bool IsPrimaryBaseVirtual, const CXXRecordDecl *BaseSharingVBPtr,
55 bool EndsWithZeroSizedObject, bool LeadsWithZeroSizedBase,
56 BaseOffsetsMapTy &&BaseOffsets, VBaseOffsetsMapTy &&VBaseOffsets)
57 : Size(size), DataSize(datasize), Alignment(alignment),
58 PreferredAlignment(preferredAlignment),
59 UnadjustedAlignment(unadjustedAlignment),
60 RequiredAlignment(requiredAlignment),
61 PragmaPackResistantAlignment(pragmaPackResistantAlignment),
62 CXXInfo(new (Ctx) CXXRecordLayoutInfo) {
63 FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
64
65 CXXInfo->PrimaryBase.setPointer(PrimaryBase);
66 CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
67 CXXInfo->NonVirtualSize = nonvirtualsize;
68 CXXInfo->NonVirtualAlignment = nonvirtualalignment;
69 CXXInfo->PreferredNVAlignment = preferrednvalignment;
70 CXXInfo->NonRequiredNVAlignment = nonrequirednvalignment;
71 CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
72 CXXInfo->BaseOffsets = std::move(BaseOffsets);
73 CXXInfo->VBaseOffsets = std::move(VBaseOffsets);
74 CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
75 CXXInfo->VBPtrOffset = vbptroffset;
76 CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;
77 CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr;
78 CXXInfo->EndsWithZeroSizedObject = EndsWithZeroSizedObject;
79 CXXInfo->LeadsWithZeroSizedBase = LeadsWithZeroSizedBase;
80
81#ifndef NDEBUG
82 if (const CXXRecordDecl *PrimaryBase = getPrimaryBase()) {
83 if (isPrimaryBaseVirtual()) {
85 assert(getVBaseClassOffset(PrimaryBase).isZero() &&
86 "Primary virtual base must be at offset 0!");
87 }
88 } else {
89 assert(getBaseClassOffset(PrimaryBase).isZero() &&
90 "Primary base must be at offset 0!");
91 }
92 }
93#endif
94}
Defines the clang::ASTContext interface.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:246
void Deallocate(void *Ptr) const
Definition ASTContext.h:942
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:981
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
bool hasPrimaryVBases() const
Does this ABI allow virtual bases to be primary base classes?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))