clang  8.0.0svn
RecordLayout.cpp
Go to the documentation of this file.
1 //===- RecordLayout.cpp - Layout information for a struct/union -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the RecordLayout interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/RecordLayout.h"
15 #include "clang/AST/ASTContext.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include <cassert>
19 
20 using namespace clang;
21 
22 void ASTRecordLayout::Destroy(ASTContext &Ctx) {
23  if (CXXInfo) {
24  CXXInfo->~CXXRecordLayoutInfo();
25  Ctx.Deallocate(CXXInfo);
26  }
27  this->~ASTRecordLayout();
28  Ctx.Deallocate(this);
29 }
30 
31 ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
32  CharUnits alignment,
33  CharUnits unadjustedAlignment,
34  CharUnits requiredAlignment,
35  CharUnits datasize,
36  ArrayRef<uint64_t> fieldoffsets)
37  : Size(size), DataSize(datasize), Alignment(alignment),
38  UnadjustedAlignment(unadjustedAlignment),
39  RequiredAlignment(requiredAlignment) {
40  FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
41 }
42 
43 // Constructor for C++ records.
44 ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx,
45  CharUnits size, CharUnits alignment,
46  CharUnits unadjustedAlignment,
47  CharUnits requiredAlignment,
48  bool hasOwnVFPtr, bool hasExtendableVFPtr,
49  CharUnits vbptroffset,
50  CharUnits datasize,
51  ArrayRef<uint64_t> fieldoffsets,
52  CharUnits nonvirtualsize,
53  CharUnits nonvirtualalignment,
54  CharUnits SizeOfLargestEmptySubobject,
55  const CXXRecordDecl *PrimaryBase,
56  bool IsPrimaryBaseVirtual,
57  const CXXRecordDecl *BaseSharingVBPtr,
58  bool EndsWithZeroSizedObject,
59  bool LeadsWithZeroSizedBase,
60  const BaseOffsetsMapTy& BaseOffsets,
61  const VBaseOffsetsMapTy& VBaseOffsets)
62  : Size(size), DataSize(datasize), Alignment(alignment),
63  UnadjustedAlignment(unadjustedAlignment),
64  RequiredAlignment(requiredAlignment), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
65 {
66  FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
67 
68  CXXInfo->PrimaryBase.setPointer(PrimaryBase);
69  CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
70  CXXInfo->NonVirtualSize = nonvirtualsize;
71  CXXInfo->NonVirtualAlignment = nonvirtualalignment;
72  CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
73  CXXInfo->BaseOffsets = BaseOffsets;
74  CXXInfo->VBaseOffsets = VBaseOffsets;
75  CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
76  CXXInfo->VBPtrOffset = vbptroffset;
77  CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;
78  CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr;
79  CXXInfo->EndsWithZeroSizedObject = EndsWithZeroSizedObject;
80  CXXInfo->LeadsWithZeroSizedBase = LeadsWithZeroSizedBase;
81 
82 #ifndef NDEBUG
83  if (const CXXRecordDecl *PrimaryBase = getPrimaryBase()) {
84  if (isPrimaryBaseVirtual()) {
86  assert(getVBaseClassOffset(PrimaryBase).isZero() &&
87  "Primary virtual base must be at offset 0!");
88  }
89  } else {
90  assert(getBaseClassOffset(PrimaryBase).isZero() &&
91  "Primary base must be at offset 0!");
92  }
93  }
94 #endif
95 }
Defines the clang::ASTContext interface.
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:699
bool isZero(ProgramStateRef State, const NonLoc &Val)
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1018
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:39
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we&#39;re targeting...
bool hasPrimaryVBases() const
Does this ABI allow virtual bases to be primary base classes?
Definition: TargetCXXABI.h:220
Dataflow Directional Tag Classes.
void Deallocate(void *Ptr) const
Definition: ASTContext.h:684
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
Defines the clang::TargetInfo interface.