Revert "Revert "[LifetimeAnalysis] Add [[gsl::Pointer]] to llvm::StringRef""
authorMatthias Gehre <gehre.matthias@gmail.com>
Thu, 16 Apr 2020 12:10:06 +0000 (14:10 +0200)
committerMatthias Gehre <gehre.matthias@gmail.com>
Thu, 16 Apr 2020 12:10:22 +0000 (14:10 +0200)
This reverts commit bac85ab3b55d02f0a1e824712f185af42cd1ea04.

llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/Support/Compiler.h

index ad31517..add5d37 100644 (file)
@@ -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);
 
index 34d8ed8..a8356cc 100644 (file)
 #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__