diff options
author | Timm Baeder <tbaeder@redhat.com> | 2024-08-03 07:11:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-03 07:11:27 +0200 |
commit | d631ebb7562d48d9e3d0f9ac0543364587d470b6 (patch) | |
tree | e0217992d93cf85507161c984d7b8b99fadfa9ff | |
parent | 14837aff058f9a2d32b8277debe619d8eb1995a1 (diff) | |
download | llvm-d631ebb7562d48d9e3d0f9ac0543364587d470b6.zip llvm-d631ebb7562d48d9e3d0f9ac0543364587d470b6.tar.gz llvm-d631ebb7562d48d9e3d0f9ac0543364587d470b6.tar.bz2 |
[clang][Interp] Enhance CodePtr (#101787)
Add more relational operators.
-rw-r--r-- | clang/lib/AST/Interp/Source.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h index c28b488..88b5ec7 100644 --- a/clang/lib/AST/Interp/Source.h +++ b/clang/lib/AST/Interp/Source.h @@ -29,7 +29,7 @@ class Function; /// Pointer into the code segment. class CodePtr final { public: - CodePtr() : Ptr(nullptr) {} + CodePtr() = default; CodePtr &operator+=(int32_t Offset) { Ptr += Offset; @@ -45,11 +45,16 @@ public: assert(Ptr != nullptr && "Invalid code pointer"); return CodePtr(Ptr - RHS); } + CodePtr operator+(ssize_t RHS) const { + assert(Ptr != nullptr && "Invalid code pointer"); + return CodePtr(Ptr + RHS); + } bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; } const std::byte *operator*() const { return Ptr; } - - operator bool() const { return Ptr; } + explicit operator bool() const { return Ptr; } + bool operator<=(const CodePtr &RHS) const { return Ptr <= RHS.Ptr; } + bool operator>=(const CodePtr &RHS) const { return Ptr >= RHS.Ptr; } /// Reads data and advances the pointer. template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() { @@ -65,7 +70,7 @@ private: /// Constructor used by Function to generate pointers. CodePtr(const std::byte *Ptr) : Ptr(Ptr) {} /// Pointer into the code owned by a function. - const std::byte *Ptr; + const std::byte *Ptr = nullptr; }; /// Describes the statement/declaration an opcode was generated from. |