File tree Expand file tree Collapse file tree 2 files changed +36
-26
lines changed Expand file tree Collapse file tree 2 files changed +36
-26
lines changed Original file line number Diff line number Diff line change @@ -110,19 +110,21 @@ Pointer &Pointer::operator=(const Pointer &P) {
110
110
StorageKind = P.StorageKind ;
111
111
Offset = P.Offset ;
112
112
113
- if (P.isBlockPointer ()) {
113
+ switch (StorageKind) {
114
+ case Storage::Int:
115
+ Int = P.Int ;
116
+ break ;
117
+ case Storage::Block:
114
118
BS = P.BS ;
115
119
116
120
if (BS.Pointee )
117
121
BS.Pointee ->addPointer (this );
118
- } else if (P.isIntegralPointer ()) {
119
- Int = P.Int ;
120
- } else if (P.isFunctionPointer ()) {
122
+ break ;
123
+ case Storage::Fn:
121
124
Fn = P.Fn ;
122
- } else if (P.isTypeidPointer ()) {
125
+ break ;
126
+ case Storage::Typeid:
123
127
Typeid = P.Typeid ;
124
- } else {
125
- assert (false && " Unhandled storage kind" );
126
128
}
127
129
return *this ;
128
130
}
@@ -147,19 +149,21 @@ Pointer &Pointer::operator=(Pointer &&P) {
147
149
StorageKind = P.StorageKind ;
148
150
Offset = P.Offset ;
149
151
150
- if (P.isBlockPointer ()) {
152
+ switch (StorageKind) {
153
+ case Storage::Int:
154
+ Int = P.Int ;
155
+ break ;
156
+ case Storage::Block:
151
157
BS = P.BS ;
152
158
153
159
if (BS.Pointee )
154
160
BS.Pointee ->addPointer (this );
155
- } else if (P.isIntegralPointer ()) {
156
- Int = P.Int ;
157
- } else if (P.isFunctionPointer ()) {
161
+ break ;
162
+ case Storage::Fn:
158
163
Fn = P.Fn ;
159
- } else if (P.isTypeidPointer ()) {
164
+ break ;
165
+ case Storage::Typeid:
160
166
Typeid = P.Typeid ;
161
- } else {
162
- assert (false && " Unhandled storage kind" );
163
167
}
164
168
return *this ;
165
169
}
@@ -358,13 +362,17 @@ void Pointer::print(llvm::raw_ostream &OS) const {
358
362
}
359
363
360
364
size_t Pointer::computeOffsetForComparison () const {
361
- if (isIntegralPointer ())
362
- return asIntPointer ().Value + Offset;
363
- if (isTypeidPointer ())
365
+ switch (StorageKind) {
366
+ case Storage::Int:
367
+ return Int.Value + Offset;
368
+ case Storage::Block:
369
+ // See below.
370
+ break ;
371
+ case Storage::Fn:
372
+ return Fn.getIntegerRepresentation () + Offset;
373
+ case Storage::Typeid:
364
374
return reinterpret_cast <uintptr_t >(asTypeidPointer ().TypePtr ) + Offset;
365
-
366
- if (!isBlockPointer ())
367
- return Offset;
375
+ }
368
376
369
377
size_t Result = 0 ;
370
378
Pointer P = *this ;
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ struct TypeidPointer {
56
56
const Type *TypeInfoType;
57
57
};
58
58
59
- enum class Storage { Block, Int , Fn, Typeid };
59
+ enum class Storage { Int, Block , Fn, Typeid };
60
60
61
61
// / A pointer to a memory block, live or dead.
62
62
// /
@@ -252,14 +252,16 @@ class Pointer {
252
252
253
253
// / Checks if the pointer is null.
254
254
bool isZero () const {
255
- if (isBlockPointer ())
255
+ switch (StorageKind) {
256
+ case Storage::Int:
257
+ return Int.Value == 0 && Offset == 0 ;
258
+ case Storage::Block:
256
259
return BS.Pointee == nullptr ;
257
- if ( isFunctionPointer ())
260
+ case Storage::Fn:
258
261
return Fn.isZero ();
259
- if ( isTypeidPointer ())
262
+ case Storage::Typeid:
260
263
return false ;
261
- assert (isIntegralPointer ());
262
- return Int.Value == 0 && Offset == 0 ;
264
+ }
263
265
}
264
266
// / Checks if the pointer is live.
265
267
bool isLive () const {
You can’t perform that action at this time.
0 commit comments