From 6d2f73f821ed5ea584869924b150ac2e6e65c12e Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Thu, 16 Apr 2020 14:10:06 +0200 Subject: [PATCH] Revert "Revert "[LifetimeAnalysis] Add [[gsl::Pointer]] to llvm::StringRef"" This reverts commit bac85ab3b55d02f0a1e824712f185af42cd1ea04. --- llvm/include/llvm/ADT/StringRef.h | 2 +- llvm/include/llvm/Support/Compiler.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h index ad31517..add5d37 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 34d8ed8..a8356cc 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__ -- 2.7.4