[llvm] [ADT] Fix ArrayRef<T>::slice (PR #113048)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 09:15:26 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Franklin (FLZ101)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/113048.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/ArrayRef.h (+4-1) 


``````````diff
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index ac40ec4a6b2404..69a08fd079043a 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -198,7 +198,10 @@ namespace llvm {
     }
 
     /// slice(n) - Chop off the first N elements of the array.
-    ArrayRef<T> slice(size_t N) const { return slice(N, size() - N); }
+    ArrayRef<T> slice(size_t N) const {
+      assert(N <= size() && "Invalid specifier");
+      return slice(N, size() - N);
+    }
 
     /// Drop the first \p N elements of the array.
     ArrayRef<T> drop_front(size_t N = 1) const {

``````````

</details>


https://github.com/llvm/llvm-project/pull/113048


More information about the llvm-commits mailing list