2017-11-10 00:59:22 +00:00
|
|
|
//===- RecordLayout.cpp - Layout information for a struct/union -----------===//
|
2010-03-08 20:56:29 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// 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
|
2010-03-08 20:56:29 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the RecordLayout interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/RecordLayout.h"
|
2017-11-10 00:59:22 +00:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/Basic/TargetCXXABI.h"
|
2011-09-27 19:12:27 +00:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2017-11-10 00:59:22 +00:00
|
|
|
#include <cassert>
|
2010-03-08 20:56:29 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
void ASTRecordLayout::Destroy(ASTContext &Ctx) {
|
2010-08-25 00:32:19 +00:00
|
|
|
if (CXXInfo) {
|
|
|
|
CXXInfo->~CXXRecordLayoutInfo();
|
2014-05-24 07:19:25 +00:00
|
|
|
Ctx.Deallocate(CXXInfo);
|
2010-08-25 00:32:19 +00:00
|
|
|
}
|
2010-03-08 20:56:29 +00:00
|
|
|
this->~ASTRecordLayout();
|
|
|
|
Ctx.Deallocate(this);
|
|
|
|
}
|
|
|
|
|
2011-02-09 01:59:34 +00:00
|
|
|
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
|
2016-05-24 18:10:50 +00:00
|
|
|
CharUnits alignment,
|
2018-07-30 17:48:23 +00:00
|
|
|
CharUnits unadjustedAlignment,
|
2013-12-06 00:01:17 +00:00
|
|
|
CharUnits requiredAlignment,
|
|
|
|
CharUnits datasize,
|
2016-05-24 18:10:50 +00:00
|
|
|
ArrayRef<uint64_t> fieldoffsets)
|
|
|
|
: Size(size), DataSize(datasize), Alignment(alignment),
|
2018-07-30 17:48:23 +00:00
|
|
|
UnadjustedAlignment(unadjustedAlignment),
|
2017-11-10 00:59:22 +00:00
|
|
|
RequiredAlignment(requiredAlignment) {
|
2016-05-24 18:10:50 +00:00
|
|
|
FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
|
2010-03-08 20:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for C++ records.
|
2011-01-12 09:06:06 +00:00
|
|
|
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx,
|
2011-02-15 02:32:40 +00:00
|
|
|
CharUnits size, CharUnits alignment,
|
2018-07-30 17:48:23 +00:00
|
|
|
CharUnits unadjustedAlignment,
|
2013-12-06 00:01:17 +00:00
|
|
|
CharUnits requiredAlignment,
|
2013-11-13 22:16:13 +00:00
|
|
|
bool hasOwnVFPtr, bool hasExtendableVFPtr,
|
2013-10-11 20:19:00 +00:00
|
|
|
CharUnits vbptroffset,
|
2011-10-21 22:49:56 +00:00
|
|
|
CharUnits datasize,
|
2016-05-24 18:10:50 +00:00
|
|
|
ArrayRef<uint64_t> fieldoffsets,
|
2011-02-01 01:52:10 +00:00
|
|
|
CharUnits nonvirtualsize,
|
2014-01-09 00:30:56 +00:00
|
|
|
CharUnits nonvirtualalignment,
|
2010-10-31 22:13:23 +00:00
|
|
|
CharUnits SizeOfLargestEmptySubobject,
|
2010-05-26 05:20:58 +00:00
|
|
|
const CXXRecordDecl *PrimaryBase,
|
2010-11-24 23:20:19 +00:00
|
|
|
bool IsPrimaryBaseVirtual,
|
2013-11-08 11:45:35 +00:00
|
|
|
const CXXRecordDecl *BaseSharingVBPtr,
|
2016-05-23 17:16:12 +00:00
|
|
|
bool EndsWithZeroSizedObject,
|
2013-12-06 19:54:25 +00:00
|
|
|
bool LeadsWithZeroSizedBase,
|
2010-03-11 04:10:39 +00:00
|
|
|
const BaseOffsetsMapTy& BaseOffsets,
|
2012-05-01 08:55:32 +00:00
|
|
|
const VBaseOffsetsMapTy& VBaseOffsets)
|
2013-12-06 00:01:17 +00:00
|
|
|
: Size(size), DataSize(datasize), Alignment(alignment),
|
2018-07-30 17:48:23 +00:00
|
|
|
UnadjustedAlignment(unadjustedAlignment),
|
2016-05-24 18:10:50 +00:00
|
|
|
RequiredAlignment(requiredAlignment), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
|
2010-03-08 20:56:29 +00:00
|
|
|
{
|
2016-05-24 18:10:50 +00:00
|
|
|
FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
|
2010-03-08 20:56:29 +00:00
|
|
|
|
2010-11-24 23:20:19 +00:00
|
|
|
CXXInfo->PrimaryBase.setPointer(PrimaryBase);
|
|
|
|
CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
|
2010-03-08 20:56:29 +00:00
|
|
|
CXXInfo->NonVirtualSize = nonvirtualsize;
|
2014-01-09 00:30:56 +00:00
|
|
|
CXXInfo->NonVirtualAlignment = nonvirtualalignment;
|
2010-05-08 22:35:05 +00:00
|
|
|
CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
|
2010-03-11 04:10:39 +00:00
|
|
|
CXXInfo->BaseOffsets = BaseOffsets;
|
|
|
|
CXXInfo->VBaseOffsets = VBaseOffsets;
|
2012-05-01 08:55:32 +00:00
|
|
|
CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
|
2011-09-27 19:12:27 +00:00
|
|
|
CXXInfo->VBPtrOffset = vbptroffset;
|
2013-11-13 22:16:13 +00:00
|
|
|
CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;
|
2013-11-08 11:45:35 +00:00
|
|
|
CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr;
|
2016-05-23 17:16:12 +00:00
|
|
|
CXXInfo->EndsWithZeroSizedObject = EndsWithZeroSizedObject;
|
2013-12-06 19:54:25 +00:00
|
|
|
CXXInfo->LeadsWithZeroSizedBase = LeadsWithZeroSizedBase;
|
2013-10-11 20:19:00 +00:00
|
|
|
|
2010-03-11 01:49:18 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (const CXXRecordDecl *PrimaryBase = getPrimaryBase()) {
|
2011-09-27 19:12:27 +00:00
|
|
|
if (isPrimaryBaseVirtual()) {
|
2013-01-25 22:30:49 +00:00
|
|
|
if (Ctx.getTargetInfo().getCXXABI().hasPrimaryVBases()) {
|
|
|
|
assert(getVBaseClassOffset(PrimaryBase).isZero() &&
|
|
|
|
"Primary virtual base must be at offset 0!");
|
2011-09-27 19:12:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-04 18:45:14 +00:00
|
|
|
assert(getBaseClassOffset(PrimaryBase).isZero() &&
|
2010-03-11 01:49:18 +00:00
|
|
|
"Primary base must be at offset 0!");
|
2011-09-27 19:12:27 +00:00
|
|
|
}
|
2010-03-11 01:49:18 +00:00
|
|
|
}
|
2018-07-30 19:24:48 +00:00
|
|
|
#endif
|
2010-03-08 20:56:29 +00:00
|
|
|
}
|