[llvm] 2c046c4 - Add the gsl::Pointer/gsl::Owner combo to ArrayRef and SmallVector so it can diagnose this common combo.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 03:34:37 PDT 2020
Author: Benjamin Kramer
Date: 2020-04-27T12:31:07+02:00
New Revision: 2c046c422f8bc5a879c413eba1629e3753939ac5
URL: https://github.com/llvm/llvm-project/commit/2c046c422f8bc5a879c413eba1629e3753939ac5
DIFF: https://github.com/llvm/llvm-project/commit/2c046c422f8bc5a879c413eba1629e3753939ac5.diff
LOG: Add the gsl::Pointer/gsl::Owner combo to ArrayRef and SmallVector so it can diagnose this common combo.
Added:
Modified:
llvm/include/llvm/ADT/ArrayRef.h
llvm/include/llvm/ADT/SmallVector.h
llvm/include/llvm/Support/Compiler.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index d11f8b5b44e9..5ed4d0766c34 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -38,7 +38,7 @@ namespace llvm {
/// This is intended to be trivially copyable, so it should be passed by
/// value.
template<typename T>
- class LLVM_NODISCARD ArrayRef {
+ class LLVM_GSL_POINTER LLVM_NODISCARD ArrayRef {
public:
using iterator = const T *;
using const_iterator = const T *;
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 12a58761955b..5656a283681f 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -841,7 +841,8 @@ template <typename T> struct alignas(alignof(T)) SmallVectorStorage<T, 0> {};
/// Note that this does not attempt to be exception safe.
///
template <typename T, unsigned N>
-class SmallVector : public SmallVectorImpl<T>, SmallVectorStorage<T, N> {
+class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>,
+ SmallVectorStorage<T, N> {
public:
SmallVector() : SmallVectorImpl<T>(N) {}
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index cc64b54e31f8..79af6f5d3c68 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -289,6 +289,14 @@
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
#endif
+/// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable
+/// lifetime warnings.
+#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
+#define LLVM_GSL_OWNER [[gsl::Owner]]
+#else
+#define LLVM_GSL_OWNER
+#endif
+
/// LLVM_GSL_POINTER - Apply this to non-owning classes like
/// StringRef to enable lifetime warnings.
#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
More information about the llvm-commits
mailing list