|
| 1 | +diff --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp |
| 2 | +index 28cb0efd7d59..a8127efc1df0 100644 |
| 3 | +--- a/lldb/source/Core/DataFileCache.cpp |
| 4 | ++++ b/lldb/source/Core/DataFileCache.cpp |
| 5 | +@@ -132,11 +132,6 @@ bool DataFileCache::SetCachedData(llvm::StringRef key, |
| 6 | + if (file_or_err) { |
| 7 | + llvm::CachedFileStream *cfs = file_or_err->get(); |
| 8 | + cfs->OS->write((const char *)data.data(), data.size()); |
| 9 | +- if (llvm::Error err = cfs->commit()) { |
| 10 | +- Log *log = GetLog(LLDBLog::Modules); |
| 11 | +- LLDB_LOG_ERROR(log, std::move(err), |
| 12 | +- "failed to commit to the cache for key: {0}"); |
| 13 | +- } |
| 14 | + return true; |
| 15 | + } else { |
| 16 | + Log *log = GetLog(LLDBLog::Modules); |
| 17 | +diff --git a/llvm/include/llvm/Support/Caching.h b/llvm/include/llvm/Support/Caching.h |
| 18 | +index 48a72b09c961..4fa57cc92e51 100644 |
| 19 | +--- a/llvm/include/llvm/Support/Caching.h |
| 20 | ++++ b/llvm/include/llvm/Support/Caching.h |
| 21 | +@@ -30,7 +30,6 @@ public: |
| 22 | + CachedFileStream(std::unique_ptr<raw_pwrite_stream> OS, |
| 23 | + std::string OSPath = "") |
| 24 | + : OS(std::move(OS)), ObjectPathName(OSPath) {} |
| 25 | +- virtual Error commit() { return Error::success(); } |
| 26 | + std::unique_ptr<raw_pwrite_stream> OS; |
| 27 | + std::string ObjectPathName; |
| 28 | + virtual ~CachedFileStream() = default; |
| 29 | +diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp |
| 30 | +index 6ff889d3a8ca..4c785117ae8e 100644 |
| 31 | +--- a/llvm/lib/Debuginfod/Debuginfod.cpp |
| 32 | ++++ b/llvm/lib/Debuginfod/Debuginfod.cpp |
| 33 | +@@ -188,7 +188,6 @@ class StreamedHTTPResponseHandler : public HTTPResponseHandler { |
| 34 | + public: |
| 35 | + StreamedHTTPResponseHandler(CreateStreamFn CreateStream, HTTPClient &Client) |
| 36 | + : CreateStream(CreateStream), Client(Client) {} |
| 37 | +- Error commit(); |
| 38 | + virtual ~StreamedHTTPResponseHandler() = default; |
| 39 | + |
| 40 | + Error handleBodyChunk(StringRef BodyChunk) override; |
| 41 | +@@ -211,12 +210,6 @@ Error StreamedHTTPResponseHandler::handleBodyChunk(StringRef BodyChunk) { |
| 42 | + return Error::success(); |
| 43 | + } |
| 44 | + |
| 45 | +-Error StreamedHTTPResponseHandler::commit() { |
| 46 | +- if (FileStream) |
| 47 | +- return FileStream->commit(); |
| 48 | +- return Error::success(); |
| 49 | +-} |
| 50 | +- |
| 51 | + // An over-accepting simplification of the HTTP RFC 7230 spec. |
| 52 | + static bool isHeader(StringRef S) { |
| 53 | + StringRef Name; |
| 54 | +@@ -305,8 +298,6 @@ Expected<std::string> getCachedOrDownloadArtifact( |
| 55 | + Error Err = Client.perform(Request, Handler); |
| 56 | + if (Err) |
| 57 | + return std::move(Err); |
| 58 | +- if (Err = Handler.commit()) |
| 59 | +- return std::move(Err); |
| 60 | + |
| 61 | + unsigned Code = Client.responseCode(); |
| 62 | + if (Code && Code != 200) |
| 63 | +diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp |
| 64 | +index ad0857a8746a..d5d642f0d25e 100644 |
| 65 | +--- a/llvm/lib/LTO/LTOBackend.cpp |
| 66 | ++++ b/llvm/lib/LTO/LTOBackend.cpp |
| 67 | +@@ -421,9 +421,6 @@ static void codegen(const Config &Conf, TargetMachine *TM, |
| 68 | + |
| 69 | + if (DwoOut) |
| 70 | + DwoOut->keep(); |
| 71 | +- |
| 72 | +- if (Error Err = Stream->commit()) |
| 73 | +- report_fatal_error(std::move(Err)); |
| 74 | + } |
| 75 | + |
| 76 | + static void splitCodeGen(const Config &C, TargetMachine *TM, |
| 77 | +diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp |
| 78 | +index d891184a65c9..1ef51db218e8 100644 |
| 79 | +--- a/llvm/lib/Support/Caching.cpp |
| 80 | ++++ b/llvm/lib/Support/Caching.cpp |
| 81 | +@@ -80,7 +80,6 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, |
| 82 | + sys::fs::TempFile TempFile; |
| 83 | + std::string ModuleName; |
| 84 | + unsigned Task; |
| 85 | +- bool Committed = false; |
| 86 | + |
| 87 | + CacheStream(std::unique_ptr<raw_pwrite_stream> OS, AddBufferFn AddBuffer, |
| 88 | + sys::fs::TempFile TempFile, std::string EntryPath, |
| 89 | +@@ -89,10 +88,9 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, |
| 90 | + AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)), |
| 91 | + ModuleName(ModuleName), Task(Task) {} |
| 92 | + |
| 93 | +- Error commit() override { |
| 94 | +- if (Committed) |
| 95 | +- return Error::success(); |
| 96 | +- Committed = true; |
| 97 | ++ ~CacheStream() { |
| 98 | ++ // TODO: Manually commit rather than using non-trivial destructor, |
| 99 | ++ // allowing to replace report_fatal_errors with a return Error. |
| 100 | + |
| 101 | + // Make sure the stream is closed before committing it. |
| 102 | + OS.reset(); |
| 103 | +@@ -102,12 +100,10 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, |
| 104 | + MemoryBuffer::getOpenFile( |
| 105 | + sys::fs::convertFDToNativeFile(TempFile.FD), ObjectPathName, |
| 106 | + /*FileSize=*/-1, /*RequiresNullTerminator=*/false); |
| 107 | +- if (!MBOrErr) { |
| 108 | +- std::error_code EC = MBOrErr.getError(); |
| 109 | +- return createStringError(EC, Twine("Failed to open new cache file ") + |
| 110 | +- TempFile.TmpName + ": " + |
| 111 | +- EC.message() + "\n"); |
| 112 | +- } |
| 113 | ++ if (!MBOrErr) |
| 114 | ++ report_fatal_error(Twine("Failed to open new cache file ") + |
| 115 | ++ TempFile.TmpName + ": " + |
| 116 | ++ MBOrErr.getError().message() + "\n"); |
| 117 | + |
| 118 | + // On POSIX systems, this will atomically replace the destination if |
| 119 | + // it already exists. We try to emulate this on Windows, but this may |
| 120 | +@@ -122,10 +118,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, |
| 121 | + E = handleErrors(std::move(E), [&](const ECError &E) -> Error { |
| 122 | + std::error_code EC = E.convertToErrorCode(); |
| 123 | + if (EC != errc::permission_denied) |
| 124 | +- return createStringError( |
| 125 | +- EC, Twine("Failed to rename temporary file ") + |
| 126 | +- TempFile.TmpName + " to " + ObjectPathName + ": " + |
| 127 | +- EC.message() + "\n"); |
| 128 | ++ return errorCodeToError(EC); |
| 129 | + |
| 130 | + auto MBCopy = MemoryBuffer::getMemBufferCopy((*MBOrErr)->getBuffer(), |
| 131 | + ObjectPathName); |
| 132 | +@@ -138,22 +131,11 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, |
| 133 | + }); |
| 134 | + |
| 135 | + if (E) |
| 136 | +- return E; |
| 137 | ++ report_fatal_error(Twine("Failed to rename temporary file ") + |
| 138 | ++ TempFile.TmpName + " to " + ObjectPathName + ": " + |
| 139 | ++ toString(std::move(E)) + "\n"); |
| 140 | + |
| 141 | + AddBuffer(Task, ModuleName, std::move(*MBOrErr)); |
| 142 | +- return Error::success(); |
| 143 | +- } |
| 144 | +- |
| 145 | +- ~CacheStream() { |
| 146 | +- // In Debug builds, try to track down places where commit() was not |
| 147 | +- // called before destruction. |
| 148 | +- assert(Committed); |
| 149 | +- // In Release builds, fall back to the previous behaviour of committing |
| 150 | +- // during destruction and reporting errors with report_fatal_error. |
| 151 | +- if (Committed) |
| 152 | +- return; |
| 153 | +- if (Error Err = commit()) |
| 154 | +- report_fatal_error(Twine(toString(std::move(Err)))); |
| 155 | + } |
| 156 | + }; |
| 157 | + |
| 158 | +diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp |
| 159 | +index 0d4ca5299689..0b175a3852e4 100644 |
| 160 | +--- a/llvm/tools/gold/gold-plugin.cpp |
| 161 | ++++ b/llvm/tools/gold/gold-plugin.cpp |
| 162 | +@@ -1101,9 +1101,7 @@ static std::vector<std::pair<SmallString<128>, bool>> runLTO() { |
| 163 | + |
| 164 | + auto AddBuffer = [&](size_t Task, const Twine &moduleName, |
| 165 | + std::unique_ptr<MemoryBuffer> MB) { |
| 166 | +- auto Stream = *AddStream(Task, ModuleName); |
| 167 | +- Stream->OS << MB->getBuffer(); |
| 168 | +- check(Stream->commit(), "Failed to commit cache"); |
| 169 | ++ *AddStream(Task, moduleName)->OS << MB->getBuffer(); |
| 170 | + }; |
| 171 | + |
| 172 | + FileCache Cache; |
| 173 | +diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp |
| 174 | +index 63a2d0545496..5dd961a603c9 100644 |
| 175 | +--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp |
| 176 | ++++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp |
| 177 | +@@ -447,9 +447,7 @@ static int run(int argc, char **argv) { |
| 178 | + |
| 179 | + auto AddBuffer = [&](size_t Task, const Twine &ModuleName, |
| 180 | + std::unique_ptr<MemoryBuffer> MB) { |
| 181 | +- auto Stream = AddStream(Task, ModuleName); |
| 182 | +- *Stream->OS << MB->getBuffer(); |
| 183 | +- check(Stream->commit(), "Failed to commit cache"); |
| 184 | ++ *AddStream(Task, ModuleName)->OS << MB->getBuffer(); |
| 185 | + }; |
| 186 | + |
| 187 | + FileCache Cache; |
0 commit comments