Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/RecordLayout.cpp
Line
Count
Source
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
13
#include "clang/AST/RecordLayout.h"
14
#include "clang/AST/ASTContext.h"
15
#include "clang/Basic/TargetCXXABI.h"
16
#include "clang/Basic/TargetInfo.h"
17
#include <cassert>
18
19
using namespace clang;
20
21
170k
void ASTRecordLayout::Destroy(ASTContext &Ctx) {
22
170k
  if (CXXInfo) {
23
118k
    CXXInfo->~CXXRecordLayoutInfo();
24
118k
    Ctx.Deallocate(CXXInfo);
25
118k
  }
26
170k
  this->~ASTRecordLayout();
27
170k
  Ctx.Deallocate(this);
28
170k
}
29
30
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
31
                                 CharUnits alignment,
32
                                 CharUnits preferredAlignment,
33
                                 CharUnits unadjustedAlignment,
34
                                 CharUnits requiredAlignment,
35
                                 CharUnits datasize,
36
                                 ArrayRef<uint64_t> fieldoffsets)
37
    : Size(size), DataSize(datasize), Alignment(alignment),
38
      PreferredAlignment(preferredAlignment),
39
      UnadjustedAlignment(unadjustedAlignment),
40
124k
      RequiredAlignment(requiredAlignment) {
41
124k
  FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
42
124k
}
43
44
// Constructor for C++ records.
45
ASTRecordLayout::ASTRecordLayout(
46
    const ASTContext &Ctx, CharUnits size, CharUnits alignment,
47
    CharUnits preferredAlignment, CharUnits unadjustedAlignment,
48
    CharUnits requiredAlignment, bool hasOwnVFPtr, bool hasExtendableVFPtr,
49
    CharUnits vbptroffset, CharUnits datasize, ArrayRef<uint64_t> fieldoffsets,
50
    CharUnits nonvirtualsize, CharUnits nonvirtualalignment,
51
    CharUnits preferrednvalignment, CharUnits SizeOfLargestEmptySubobject,
52
    const CXXRecordDecl *PrimaryBase, bool IsPrimaryBaseVirtual,
53
    const CXXRecordDecl *BaseSharingVBPtr, bool EndsWithZeroSizedObject,
54
    bool LeadsWithZeroSizedBase, const BaseOffsetsMapTy &BaseOffsets,
55
    const VBaseOffsetsMapTy &VBaseOffsets)
56
    : Size(size), DataSize(datasize), Alignment(alignment),
57
      PreferredAlignment(preferredAlignment),
58
      UnadjustedAlignment(unadjustedAlignment),
59
      RequiredAlignment(requiredAlignment),
60
191k
      CXXInfo(new (Ctx) CXXRecordLayoutInfo) {
61
191k
  FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
62
191k
63
191k
  CXXInfo->PrimaryBase.setPointer(PrimaryBase);
64
191k
  CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);
65
191k
  CXXInfo->NonVirtualSize = nonvirtualsize;
66
191k
  CXXInfo->NonVirtualAlignment = nonvirtualalignment;
67
191k
  CXXInfo->PreferredNVAlignment = preferrednvalignment;
68
191k
  CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
69
191k
  CXXInfo->BaseOffsets = BaseOffsets;
70
191k
  CXXInfo->VBaseOffsets = VBaseOffsets;
71
191k
  CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
72
191k
  CXXInfo->VBPtrOffset = vbptroffset;
73
191k
  CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr;
74
191k
  CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr;
75
191k
  CXXInfo->EndsWithZeroSizedObject = EndsWithZeroSizedObject;
76
191k
  CXXInfo->LeadsWithZeroSizedBase = LeadsWithZeroSizedBase;
77
191k
78
191k
#ifndef NDEBUG
79
191k
    if (const CXXRecordDecl *PrimaryBase = getPrimaryBase()) {
80
8.37k
      if (isPrimaryBaseVirtual()) {
81
196
        if (Ctx.getTargetInfo().getCXXABI().hasPrimaryVBases()) {
82
196
          assert(getVBaseClassOffset(PrimaryBase).isZero() &&
83
196
                 "Primary virtual base must be at offset 0!");
84
196
        }
85
8.18k
      } else {
86
8.18k
        assert(getBaseClassOffset(PrimaryBase).isZero() &&
87
8.18k
               "Primary base must be at offset 0!");
88
8.18k
      }
89
8.37k
    }
90
191k
#endif
91
191k
}