Skip to content

Commit e5df0a1

Browse files
committed
Add assertions
1 parent 2427d71 commit e5df0a1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

clang/lib/AST/Interp/Pointer.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ class Pointer {
199199
bool isField() const { return Base != 0 && Base != RootPtrMark; }
200200

201201
/// Accessor for information about the declaration site.
202-
const Descriptor *getDeclDesc() const { return Pointee->Desc; }
202+
const Descriptor *getDeclDesc() const {
203+
assert(Pointee);
204+
return Pointee->Desc;
205+
}
203206
SourceLocation getDeclLoc() const { return getDeclDesc()->getLocation(); }
204207

205208
/// Returns a pointer to the object of which this pointer is a field.
@@ -298,9 +301,15 @@ class Pointer {
298301
/// Checks if the storage is extern.
299302
bool isExtern() const { return Pointee && Pointee->isExtern(); }
300303
/// Checks if the storage is static.
301-
bool isStatic() const { return Pointee->isStatic(); }
304+
bool isStatic() const {
305+
assert(Pointee);
306+
return Pointee->isStatic();
307+
}
302308
/// Checks if the storage is temporary.
303-
bool isTemporary() const { return Pointee->isTemporary(); }
309+
bool isTemporary() const {
310+
assert(Pointee);
311+
return Pointee->isTemporary();
312+
}
304313
/// Checks if the storage is a static temporary.
305314
bool isStaticTemporary() const { return isStatic() && isTemporary(); }
306315

@@ -323,7 +332,10 @@ class Pointer {
323332
}
324333

325334
/// Returns the declaration ID.
326-
std::optional<unsigned> getDeclID() const { return Pointee->getDeclID(); }
335+
std::optional<unsigned> getDeclID() const {
336+
assert(Pointee);
337+
return Pointee->getDeclID();
338+
}
327339

328340
/// Returns the byte offset from the start.
329341
unsigned getByteOffset() const {
@@ -362,6 +374,7 @@ class Pointer {
362374
/// Dereferences the pointer, if it's live.
363375
template <typename T> T &deref() const {
364376
assert(isLive() && "Invalid pointer");
377+
assert(Pointee);
365378
if (isArrayRoot())
366379
return *reinterpret_cast<T *>(Pointee->rawData() + Base +
367380
sizeof(InitMapPtr));
@@ -372,6 +385,7 @@ class Pointer {
372385
/// Dereferences a primitive element.
373386
template <typename T> T &elem(unsigned I) const {
374387
assert(I < getNumElems());
388+
assert(Pointee);
375389
return reinterpret_cast<T *>(Pointee->data() + sizeof(InitMapPtr))[I];
376390
}
377391

@@ -433,12 +447,14 @@ class Pointer {
433447
/// Returns a descriptor at a given offset.
434448
InlineDescriptor *getDescriptor(unsigned Offset) const {
435449
assert(Offset != 0 && "Not a nested pointer");
450+
assert(Pointee);
436451
return reinterpret_cast<InlineDescriptor *>(Pointee->rawData() + Offset) -
437452
1;
438453
}
439454

440455
/// Returns a reference to the InitMapPtr which stores the initialization map.
441456
InitMapPtr &getInitMap() const {
457+
assert(Pointee);
442458
return *reinterpret_cast<InitMapPtr *>(Pointee->rawData() + Base);
443459
}
444460

0 commit comments

Comments
 (0)