Skip to content

Commit

Permalink
[clang][Interp][NFC] Add Pointer::isDereferencable()
Browse files Browse the repository at this point in the history
Summary:
We currently have a few places where we check whether a pointer can
be read from at all. Add a function to do that.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D59822397
  • Loading branch information
tbaederr authored and sayhaan committed Jul 16, 2024
1 parent 067e819 commit 02f9b85
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/lib/AST/Interp/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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.
Expand Down

0 comments on commit 02f9b85

Please sign in to comment.