Skip to content

Commit 4d29e93

Browse files
tbaederryuxuanchen1997
authored andcommitted
[clang][Interp][NFC] Add Pointer::isDereferencable()
We currently have a few places where we check whether a pointer can be read from at all. Add a function to do that.
1 parent 64f31c1 commit 4d29e93

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

clang/lib/AST/Interp/Pointer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ class Pointer {
584584
assert(isLive() && "Invalid pointer");
585585
assert(isBlockPointer());
586586
assert(asBlockPointer().Pointee);
587+
assert(isDereferencable());
587588
assert(Offset + sizeof(T) <=
588589
asBlockPointer().Pointee->getDescriptor()->getAllocSize());
589590

@@ -603,6 +604,17 @@ class Pointer {
603604
sizeof(InitMapPtr))[I];
604605
}
605606

607+
/// Whether this block can be read from at all. This is only true for
608+
/// block pointers that point to a valid location inside that block.
609+
bool isDereferencable() const {
610+
if (!isBlockPointer())
611+
return false;
612+
if (isPastEnd())
613+
return false;
614+
615+
return true;
616+
}
617+
606618
/// Initializes a field.
607619
void initialize() const;
608620
/// Activats a field.

0 commit comments

Comments
 (0)