Skip to content

Commit 02ba0cd

Browse files
committed
[clang][Interp] Enhance CodePtr
Add more relational operators.
1 parent 53e8790 commit 02ba0cd

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clang/lib/AST/Interp/Source.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Function;
2929
/// Pointer into the code segment.
3030
class CodePtr final {
3131
public:
32-
CodePtr() : Ptr(nullptr) {}
32+
CodePtr() = default;
3333

3434
CodePtr &operator+=(int32_t Offset) {
3535
Ptr += Offset;
@@ -45,11 +45,16 @@ class CodePtr final {
4545
assert(Ptr != nullptr && "Invalid code pointer");
4646
return CodePtr(Ptr - RHS);
4747
}
48+
CodePtr operator+(ssize_t RHS) const {
49+
assert(Ptr != nullptr && "Invalid code pointer");
50+
return CodePtr(Ptr + RHS);
51+
}
4852

4953
bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
5054
const std::byte *operator*() const { return Ptr; }
51-
52-
operator bool() const { return Ptr; }
55+
explicit operator bool() const { return Ptr; }
56+
bool operator<=(const CodePtr &RHS) const { return Ptr <= RHS.Ptr; }
57+
bool operator>=(const CodePtr &RHS) const { return Ptr >= RHS.Ptr; }
5358

5459
/// Reads data and advances the pointer.
5560
template <typename T> std::enable_if_t<!std::is_pointer<T>::value, T> read() {
@@ -65,7 +70,7 @@ class CodePtr final {
6570
/// Constructor used by Function to generate pointers.
6671
CodePtr(const std::byte *Ptr) : Ptr(Ptr) {}
6772
/// Pointer into the code owned by a function.
68-
const std::byte *Ptr;
73+
const std::byte *Ptr = nullptr;
6974
};
7075

7176
/// Describes the statement/declaration an opcode was generated from.

0 commit comments

Comments
 (0)