[clang] d631ebb - [clang][Interp] Enhance CodePtr (#101787)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 2 22:11:31 PDT 2024


Author: Timm Baeder
Date: 2024-08-03T07:11:27+02:00
New Revision: d631ebb7562d48d9e3d0f9ac0543364587d470b6

URL: https://github.com/llvm/llvm-project/commit/d631ebb7562d48d9e3d0f9ac0543364587d470b6
DIFF: https://github.com/llvm/llvm-project/commit/d631ebb7562d48d9e3d0f9ac0543364587d470b6.diff

LOG: [clang][Interp] Enhance CodePtr (#101787)

Add more relational operators.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Source.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h
index c28b488ff554d..88b5ec7740df5 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 @@ class CodePtr final {
     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 @@ class CodePtr final {
   /// 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.


        


More information about the cfe-commits mailing list