[llvm] 27f0bf7 - ADT: ArrayRef: Assert that begin <= end

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 20:04:49 PDT 2023


Author: David Blaikie
Date: 2023-07-25T03:04:42Z
New Revision: 27f0bf75df78d7439ad698c70e75bf138525db3e

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

LOG: ADT: ArrayRef: Assert that begin <= end

This came up in the context of #63169 - if this assert were in place it
would've been much easier to reduce the test case.

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 a25cf1cf817ef0..713f463f65edf1 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -79,7 +79,9 @@ namespace llvm {
 
     /// Construct an ArrayRef from a range.
     constexpr ArrayRef(const T *begin, const T *end)
-        : Data(begin), Length(end - begin) {}
+        : Data(begin), Length(end - begin) {
+      assert(begin <= end);
+    }
 
     /// Construct an ArrayRef from a SmallVector. This is templated in order to
     /// avoid instantiating SmallVectorTemplateCommon<T> whenever we


        


More information about the llvm-commits mailing list