Coverage Report

Created: 2018-12-11 17:59

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