diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -82,8 +82,8 @@ [this] { UpdateSymlinkMappings(); }); llvm::SmallString<128> path; - clang::driver::Driver::getDefaultModuleCachePath(path); - SetClangModulesCachePath(path); + if (clang::driver::Driver::getDefaultModuleCachePath(path)) + SetClangModulesCachePath(path); } bool ModuleListProperties::GetEnableExternalLookup() const { diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -800,8 +800,10 @@ /// @param Model Name to base unique path off of. /// @param ResultPath Set to the file's path. /// @param MakeAbsolute Whether to use the system temp directory. -void createUniquePath(const Twine &Model, SmallVectorImpl &ResultPath, - bool MakeAbsolute); +LLVM_ATTRIBUTE_DEPRECATED( + void createUniquePath(const Twine &Model, SmallVectorImpl &ResultPath, + bool MakeAbsolute), + "Use createUniqueFile() or createUniqueDirectory()"); /// Create a uniquely named file. /// diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h --- a/llvm/include/llvm/Support/Path.h +++ b/llvm/include/llvm/Support/Path.h @@ -363,7 +363,10 @@ /// (e.g., TEMP on Windows, TMPDIR on *nix) to specify a temporary directory. /// /// @param result Holds the resulting path name. -void system_temp_directory(bool erasedOnReboot, SmallVectorImpl &result); +LLVM_ATTRIBUTE_DEPRECATED( + void system_temp_directory(bool erasedOnReboot, + SmallVectorImpl &result), + "Only meant for debugging due to trivial security problems"); /// Get the user's home directory. /// diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -164,6 +164,41 @@ FS_Name }; +// Avoid a deprecation warning by moving the createUniquePath body here. +static void _createUniquePath(const Twine &Model, + SmallVectorImpl &ResultPath, + bool MakeAbsolute) { + SmallString<128> ModelStorage; + Model.toVector(ModelStorage); + + if (MakeAbsolute) { + // Make model absolute by prepending a temp directory if it's not already. + if (!sys::path::is_absolute(Twine(ModelStorage))) { + SmallString<128> TDir; +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif + sys::path::system_temp_directory(true, TDir); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + sys::path::append(TDir, Twine(ModelStorage)); + ModelStorage.swap(TDir); + } + } + + ResultPath = ModelStorage; + ResultPath.push_back(0); + ResultPath.pop_back(); + + // Replace '%' with random chars. + for (unsigned i = 0, e = ModelStorage.size(); i != e; ++i) { + if (ModelStorage[i] == '%') + ResultPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15]; + } +} + static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD, SmallVectorImpl &ResultPath, bool MakeAbsolute, @@ -176,7 +211,7 @@ // Checking which is racy, so we try a number of times, then give up. std::error_code EC; for (int Retries = 128; Retries > 0; --Retries) { - sys::fs::createUniquePath(Model, ResultPath, MakeAbsolute); + _createUniquePath(Model, ResultPath, MakeAbsolute); // Try to open + create the file. switch (Type) { case FS_File: { @@ -778,28 +813,7 @@ void createUniquePath(const Twine &Model, SmallVectorImpl &ResultPath, bool MakeAbsolute) { - SmallString<128> ModelStorage; - Model.toVector(ModelStorage); - - if (MakeAbsolute) { - // Make model absolute by prepending a temp directory if it's not already. - if (!sys::path::is_absolute(Twine(ModelStorage))) { - SmallString<128> TDir; - sys::path::system_temp_directory(true, TDir); - sys::path::append(TDir, Twine(ModelStorage)); - ModelStorage.swap(TDir); - } - } - - ResultPath = ModelStorage; - ResultPath.push_back(0); - ResultPath.pop_back(); - - // Replace '%' with random chars. - for (unsigned i = 0, e = ModelStorage.size(); i != e; ++i) { - if (ModelStorage[i] == '%') - ResultPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15]; - } + return _createUniquePath(Model, ResultPath, MakeAbsolute); } std::error_code createUniqueFile(const Twine &Model, int &ResultFd,