diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h index 6e9e8675306ef1..28bc42985adb2a 100644 --- a/clang/lib/AST/Interp/Pointer.h +++ b/clang/lib/AST/Interp/Pointer.h @@ -584,6 +584,7 @@ class Pointer { assert(isLive() && "Invalid pointer"); assert(isBlockPointer()); assert(asBlockPointer().Pointee); + assert(isDereferencable()); assert(Offset + sizeof(T) <= asBlockPointer().Pointee->getDescriptor()->getAllocSize()); @@ -603,6 +604,17 @@ class Pointer { sizeof(InitMapPtr))[I]; } + /// Whether this block can be read from at all. This is only true for + /// block pointers that point to a valid location inside that block. + bool isDereferencable() const { + if (!isBlockPointer()) + return false; + if (isPastEnd()) + return false; + + return true; + } + /// Initializes a field. void initialize() const; /// Activats a field.