[clang] ff96ad8 - [clang][Interp][NFC] Add Pointer::isDereferencable()
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 15 22:24:26 PDT 2024
Author: Timm Bäder
Date: 2024-07-16T07:24:08+02:00
New Revision: ff96ad84f52022af295d11749f106480e7292a89
URL: https://github.com/llvm/llvm-project/commit/ff96ad84f52022af295d11749f106480e7292a89
DIFF: https://github.com/llvm/llvm-project/commit/ff96ad84f52022af295d11749f106480e7292a89.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/Interp/Pointer.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 6e9e8675306ef..28bc42985adb2 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.
More information about the cfe-commits
mailing list