diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -22,6 +22,8 @@ #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/ArrayRef.h" + +#include #include #include @@ -138,6 +140,9 @@ /// Options controlling preprocessed output. PreprocessorOutputOptions PreprocessorOutputOpts; + /// Container holding strings allocated during round-trip. + mutable std::forward_list AllocatedStrings; + public: CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {} @@ -188,6 +193,13 @@ std::string getModuleHash() const; using StringAllocator = llvm::function_ref; + + /// Allocates a string whose lifetime is tied to the lifetime of this object. + const char *AllocateString(const llvm::Twine &Value) const { + AllocatedStrings.push_front(Value.str()); + return AllocatedStrings.front().c_str(); + } + /// Generate a cc1-compatible command line arguments from this instance. /// /// \param [out] Args - The generated arguments. Note that the caller is