Coverage Report

Created: 2019-03-22 08:08

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/ABI.h
Line
Count
Source (jump to first uncovered line)
1
//===----- ABI.h - ABI related declarations ---------------------*- C++ -*-===//
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
/// \file
10
/// Enums/classes describing ABI related information about constructors,
11
/// destructors and thunks.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_BASIC_ABI_H
16
#define LLVM_CLANG_BASIC_ABI_H
17
18
#include "llvm/Support/DataTypes.h"
19
#include <cstring>
20
21
namespace clang {
22
23
/// C++ constructor types.
24
enum CXXCtorType {
25
  Ctor_Complete,       ///< Complete object ctor
26
  Ctor_Base,           ///< Base object ctor
27
  Ctor_Comdat,         ///< The COMDAT used for ctors
28
  Ctor_CopyingClosure, ///< Copying closure variant of a ctor
29
  Ctor_DefaultClosure, ///< Default closure variant of a ctor
30
};
31
32
/// C++ destructor types.
33
enum CXXDtorType {
34
    Dtor_Deleting, ///< Deleting dtor
35
    Dtor_Complete, ///< Complete object dtor
36
    Dtor_Base,     ///< Base object dtor
37
    Dtor_Comdat    ///< The COMDAT used for dtors
38
};
39
40
/// A return adjustment.
41
struct ReturnAdjustment {
42
  /// The non-virtual adjustment from the derived object to its
43
  /// nearest virtual base.
44
  int64_t NonVirtual;
45
46
  /// Holds the ABI-specific information about the virtual return
47
  /// adjustment, if needed.
48
  union VirtualAdjustment {
49
    // Itanium ABI
50
    struct {
51
      /// The offset (in bytes), relative to the address point
52
      /// of the virtual base class offset.
53
      int64_t VBaseOffsetOffset;
54
    } Itanium;
55
56
    // Microsoft ABI
57
    struct {
58
      /// The offset (in bytes) of the vbptr, relative to the beginning
59
      /// of the derived class.
60
      uint32_t VBPtrOffset;
61
62
      /// Index of the virtual base in the vbtable.
63
      uint32_t VBIndex;
64
    } Microsoft;
65
66
153k
    VirtualAdjustment() {
67
153k
      memset(this, 0, sizeof(*this));
68
153k
    }
69
70
76.7k
    bool Equals(const VirtualAdjustment &Other) const {
71
76.7k
      return memcmp(this, &Other, sizeof(Other)) == 0;
72
76.7k
    }
73
74
74.6k
    bool isEmpty() const {
75
74.6k
      VirtualAdjustment Zero;
76
74.6k
      return Equals(Zero);
77
74.6k
    }
78
79
14
    bool Less(const VirtualAdjustment &RHS) const {
80
14
      return memcmp(this, &RHS, sizeof(RHS)) < 0;
81
14
    }
82
  } Virtual;
83
84
79.2k
  ReturnAdjustment() : NonVirtual(0) {}
85
86
74.8k
  bool isEmpty() const { return !NonVirtual && 
Virtual.isEmpty()74.6k
; }
87
88
  friend bool operator==(const ReturnAdjustment &LHS,
89
2.18k
                         const ReturnAdjustment &RHS) {
90
2.18k
    return LHS.NonVirtual == RHS.NonVirtual && 
LHS.Virtual.Equals(RHS.Virtual)2.17k
;
91
2.18k
  }
92
93
0
  friend bool operator!=(const ReturnAdjustment &LHS, const ReturnAdjustment &RHS) {
94
0
    return !(LHS == RHS);
95
0
  }
96
97
  friend bool operator<(const ReturnAdjustment &LHS,
98
27
                        const ReturnAdjustment &RHS) {
99
27
    if (LHS.NonVirtual < RHS.NonVirtual)
100
13
      return true;
101
14
102
14
    return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
103
14
  }
104
};
105
106
/// A \c this pointer adjustment.
107
struct ThisAdjustment {
108
  /// The non-virtual adjustment from the derived object to its
109
  /// nearest virtual base.
110
  int64_t NonVirtual;
111
112
  /// Holds the ABI-specific information about the virtual this
113
  /// adjustment, if needed.
114
  union VirtualAdjustment {
115
    // Itanium ABI
116
    struct {
117
      /// The offset (in bytes), relative to the address point,
118
      /// of the virtual call offset.
119
      int64_t VCallOffsetOffset;
120
    } Itanium;
121
122
    struct {
123
      /// The offset of the vtordisp (in bytes), relative to the ECX.
124
      int32_t VtordispOffset;
125
126
      /// The offset of the vbptr of the derived class (in bytes),
127
      /// relative to the ECX after vtordisp adjustment.
128
      int32_t VBPtrOffset;
129
130
      /// The offset (in bytes) of the vbase offset in the vbtable.
131
      int32_t VBOffsetOffset;
132
    } Microsoft;
133
134
69.2k
    VirtualAdjustment() {
135
69.2k
      memset(this, 0, sizeof(*this));
136
69.2k
    }
137
138
6.56k
    bool Equals(const VirtualAdjustment &Other) const {
139
6.56k
      return memcmp(this, &Other, sizeof(Other)) == 0;
140
6.56k
    }
141
142
4.37k
    bool isEmpty() const {
143
4.37k
      VirtualAdjustment Zero;
144
4.37k
      return Equals(Zero);
145
4.37k
    }
146
147
48
    bool Less(const VirtualAdjustment &RHS) const {
148
48
      return memcmp(this, &RHS, sizeof(RHS)) < 0;
149
48
    }
150
  } Virtual;
151
152
64.8k
  ThisAdjustment() : NonVirtual(0) { }
153
154
5.72k
  bool isEmpty() const { return !NonVirtual && 
Virtual.isEmpty()3.49k
; }
155
156
  friend bool operator==(const ThisAdjustment &LHS,
157
6.05k
                         const ThisAdjustment &RHS) {
158
6.05k
    return LHS.NonVirtual == RHS.NonVirtual && 
LHS.Virtual.Equals(RHS.Virtual)2.19k
;
159
6.05k
  }
160
161
0
  friend bool operator!=(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
162
0
    return !(LHS == RHS);
163
0
  }
164
165
  friend bool operator<(const ThisAdjustment &LHS,
166
62
                        const ThisAdjustment &RHS) {
167
62
    if (LHS.NonVirtual < RHS.NonVirtual)
168
9
      return true;
169
53
170
53
    return LHS.NonVirtual == RHS.NonVirtual && 
LHS.Virtual.Less(RHS.Virtual)48
;
171
53
  }
172
};
173
174
class CXXMethodDecl;
175
176
/// The \c this pointer adjustment as well as an optional return
177
/// adjustment for a thunk.
178
struct ThunkInfo {
179
  /// The \c this pointer adjustment.
180
  ThisAdjustment This;
181
182
  /// The return adjustment.
183
  ReturnAdjustment Return;
184
185
  /// Holds a pointer to the overridden method this thunk is for,
186
  /// if needed by the ABI to distinguish different thunks with equal
187
  /// adjustments. Otherwise, null.
188
  /// CAUTION: In the unlikely event you need to sort ThunkInfos, consider using
189
  /// an ABI-specific comparator.
190
  const CXXMethodDecl *Method;
191
192
41.2k
  ThunkInfo() : Method(nullptr) { }
193
194
  ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return,
195
            const CXXMethodDecl *Method = nullptr)
196
1.94k
      : This(This), Return(Return), Method(Method) {}
197
198
6.05k
  friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
199
6.05k
    return LHS.This == RHS.This && 
LHS.Return == RHS.Return2.18k
&&
200
6.05k
           
LHS.Method == RHS.Method2.15k
;
201
6.05k
  }
202
203
2.84k
  bool isEmpty() const {
204
2.84k
    return This.isEmpty() && 
Return.isEmpty()2.35k
&&
Method == nullptr2.27k
;
205
2.84k
  }
206
};
207
208
} // end namespace clang
209
210
#endif