[llvm] 6d2f73f - Revert "Revert "[LifetimeAnalysis] Add [[gsl::Pointer]] to llvm::StringRef""
Matthias Gehre via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 05:11:18 PDT 2020
Author: Matthias Gehre
Date: 2020-04-16T14:10:22+02:00
New Revision: 6d2f73f821ed5ea584869924b150ac2e6e65c12e
URL: https://github.com/llvm/llvm-project/commit/6d2f73f821ed5ea584869924b150ac2e6e65c12e
DIFF: https://github.com/llvm/llvm-project/commit/6d2f73f821ed5ea584869924b150ac2e6e65c12e.diff
LOG: Revert "Revert "[LifetimeAnalysis] Add [[gsl::Pointer]] to llvm::StringRef""
This reverts commit bac85ab3b55d02f0a1e824712f185af42cd1ea04.
Added:
Modified:
llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/Support/Compiler.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index ad31517a1ea7..add5d37f89f7 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -54,7 +54,7 @@ namespace llvm {
/// situations where the character data resides in some other buffer, whose
/// lifetime extends past that of the StringRef. For this reason, it is not in
/// general safe to store a StringRef.
- class StringRef {
+ class LLVM_GSL_POINTER StringRef {
public:
static const size_t npos = ~size_t(0);
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 34d8ed8baf2d..a8356ccf812d 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_POINTER - Apply this to non-owning classes like
+/// StringRef to enable lifetime warnings.
+#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
+#define LLVM_GSL_POINTER [[gsl::Pointer]]
+#else
+#define LLVM_GSL_POINTER
+#endif
+
/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
/// pedantic diagnostics.
#ifdef __GNUC__
More information about the llvm-commits
mailing list