Author: Timm Baeder
Date: 2026-08-24T16:17:29+02:00
New Revision: e4c6b065368023c956c5ddd5bb21c6abc297f398

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

LOG: [clang][bytecode] Optimize `PtrView::isOnePastEnd()` (#218375)

We call this a lot. Optimize this by inlining and then simplifying the
callers, i.e. don't call getFieldDesc() as much.

Also remove some code duplication from the similar
`Pointer::isOnePastEnd()`.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Pointer.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Pointer.h 
b/clang/lib/AST/ByteCode/Pointer.h
index 78768929f3487..1e6ee372276bf 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -189,9 +189,21 @@ struct PtrView {
     if (!Pointee)
       return false;
 
-    if (isUnknownSizeArray())
+    const Descriptor *Desc = getFieldDesc();
+    if (Desc->isUnknownSizeArray())
       return false;
-    return isPastEnd() || (getSize() == getOffset());
+
+    if (isPastEnd())
+      return true;
+
+    if (Offset != Base) {
+      unsigned Adjust =
+          Desc->ElemDesc ? sizeof(InlineDescriptor) : sizeof(InitMapPtr);
+      unsigned Off = Offset - Base - Adjust;
+      return Desc->getSize() == Off;
+    }
+
+    return Desc->getSize() == 0;
   }
 
   PtrView atIndex(unsigned Idx) const {
@@ -834,10 +846,7 @@ class Pointer {
     if (!BS.Pointee)
       return false;
 
-    if (isUnknownSizeArray())
-      return false;
-
-    return isPastEnd() || (getSize() == getOffset());
+    return view().isOnePastEnd();
   }
 
   /// Checks if the pointer points past the end of the object.


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to