File indexing completed on 2026-05-10 08:36:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CLANG_BASIC_THUNK_H
0016 #define LLVM_CLANG_BASIC_THUNK_H
0017
0018 #include <cstdint>
0019 #include <cstring>
0020
0021 namespace clang {
0022
0023 class CXXMethodDecl;
0024 class Type;
0025
0026
0027 struct ReturnAdjustment {
0028
0029
0030 int64_t NonVirtual = 0;
0031
0032
0033
0034 union VirtualAdjustment {
0035
0036 struct {
0037
0038
0039 int64_t VBaseOffsetOffset;
0040 } Itanium;
0041
0042
0043 struct {
0044
0045
0046 uint32_t VBPtrOffset;
0047
0048
0049 uint32_t VBIndex;
0050 } Microsoft;
0051
0052 VirtualAdjustment() { memset(this, 0, sizeof(*this)); }
0053
0054 bool Equals(const VirtualAdjustment &Other) const {
0055 return memcmp(this, &Other, sizeof(Other)) == 0;
0056 }
0057
0058 bool isEmpty() const {
0059 VirtualAdjustment Zero;
0060 return Equals(Zero);
0061 }
0062
0063 bool Less(const VirtualAdjustment &RHS) const {
0064 return memcmp(this, &RHS, sizeof(RHS)) < 0;
0065 }
0066 } Virtual;
0067
0068 ReturnAdjustment() = default;
0069
0070 bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
0071
0072 friend bool operator==(const ReturnAdjustment &LHS,
0073 const ReturnAdjustment &RHS) {
0074 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
0075 }
0076
0077 friend bool operator!=(const ReturnAdjustment &LHS,
0078 const ReturnAdjustment &RHS) {
0079 return !(LHS == RHS);
0080 }
0081
0082 friend bool operator<(const ReturnAdjustment &LHS,
0083 const ReturnAdjustment &RHS) {
0084 if (LHS.NonVirtual < RHS.NonVirtual)
0085 return true;
0086
0087 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
0088 }
0089 };
0090
0091
0092 struct ThisAdjustment {
0093
0094
0095 int64_t NonVirtual = 0;
0096
0097
0098
0099 union VirtualAdjustment {
0100
0101 struct {
0102
0103
0104 int64_t VCallOffsetOffset;
0105 } Itanium;
0106
0107 struct {
0108
0109 int32_t VtordispOffset;
0110
0111
0112
0113 int32_t VBPtrOffset;
0114
0115
0116 int32_t VBOffsetOffset;
0117 } Microsoft;
0118
0119 VirtualAdjustment() { memset(this, 0, sizeof(*this)); }
0120
0121 bool Equals(const VirtualAdjustment &Other) const {
0122 return memcmp(this, &Other, sizeof(Other)) == 0;
0123 }
0124
0125 bool isEmpty() const {
0126 VirtualAdjustment Zero;
0127 return Equals(Zero);
0128 }
0129
0130 bool Less(const VirtualAdjustment &RHS) const {
0131 return memcmp(this, &RHS, sizeof(RHS)) < 0;
0132 }
0133 } Virtual;
0134
0135 ThisAdjustment() = default;
0136
0137 bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
0138
0139 friend bool operator==(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
0140 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
0141 }
0142
0143 friend bool operator!=(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
0144 return !(LHS == RHS);
0145 }
0146
0147 friend bool operator<(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
0148 if (LHS.NonVirtual < RHS.NonVirtual)
0149 return true;
0150
0151 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
0152 }
0153 };
0154
0155
0156
0157 struct ThunkInfo {
0158
0159 ThisAdjustment This;
0160
0161
0162 ReturnAdjustment Return;
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 const CXXMethodDecl *Method;
0173 const Type *ThisType;
0174
0175 ThunkInfo() : Method(nullptr), ThisType(nullptr) {}
0176
0177 ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return,
0178 const Type *ThisT, const CXXMethodDecl *Method = nullptr)
0179 : This(This), Return(Return), Method(Method), ThisType(ThisT) {}
0180
0181 friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
0182 return LHS.This == RHS.This && LHS.Return == RHS.Return &&
0183 LHS.Method == RHS.Method && LHS.ThisType == RHS.ThisType;
0184 }
0185
0186 bool isEmpty() const {
0187 return This.isEmpty() && Return.isEmpty() && Method == nullptr;
0188 }
0189 };
0190
0191 }
0192
0193 #endif