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

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 22 22:16:04 PDT 2024


Author: Franklin
Date: 2024-10-22T22:16:00-07:00
New Revision: deb22fa6613a075fe2c707b2d19001ab9ef28804

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

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

Current implementation of `slice(N)` is buggy, since
`slice(N, size() - N)` will never fail the assertion
`assert(N+M <= size() && "Invalid specifier")` above, even
`N > size()`.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/ArrayRef.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index ac40ec4a6b2404..d9897320ce091a 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -198,7 +198,7 @@ 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 { return drop_front(N); }
 
     /// Drop the first \p N elements of the array.
     ArrayRef<T> drop_front(size_t N = 1) const {


        


More information about the llvm-commits mailing list