LLVM 22.0.0git
VirtualOutputBackends.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements the VirtualOutputBackend types, including:
11/// * NullOutputBackend: Outputs to NullOutputBackend are discarded.
12/// * FilteringOutputBackend: Filter paths from output.
13/// * MirroringOutputBackend: Mirror the output into two different backend.
14/// * OnDiskOutputBackend: Write output files to disk.
15///
16//===----------------------------------------------------------------------===//
17
19#include "llvm/ADT/ScopeExit.h"
23#include "llvm/Support/Path.h"
28
29using namespace llvm;
30using namespace llvm::vfs;
31
32void ProxyOutputBackend::anchor() {}
33void OnDiskOutputBackend::anchor() {}
34
36 struct NullOutputBackend : public OutputBackend {
37 IntrusiveRefCntPtr<OutputBackend> cloneImpl() const override {
38 return const_cast<NullOutputBackend *>(this);
39 }
41 createFileImpl(StringRef Path, std::optional<OutputConfig>) override {
42 return std::make_unique<NullOutputFileImpl>();
43 }
44 };
45
47}
48
50 IntrusiveRefCntPtr<OutputBackend> UnderlyingBackend,
51 std::function<bool(StringRef, std::optional<OutputConfig>)> Filter) {
52 struct FilteringOutputBackend : public ProxyOutputBackend {
54 createFileImpl(StringRef Path,
55 std::optional<OutputConfig> Config) override {
56 if (Filter(Path, Config))
57 return ProxyOutputBackend::createFileImpl(Path, Config);
58 return std::make_unique<NullOutputFileImpl>();
59 }
60
61 IntrusiveRefCntPtr<OutputBackend> cloneImpl() const override {
63 getUnderlyingBackend().clone(), Filter);
64 }
65
66 FilteringOutputBackend(
67 IntrusiveRefCntPtr<OutputBackend> UnderlyingBackend,
68 std::function<bool(StringRef, std::optional<OutputConfig>)> Filter)
69 : ProxyOutputBackend(std::move(UnderlyingBackend)),
70 Filter(std::move(Filter)) {
71 assert(this->Filter && "Expected a non-null function");
72 }
73 std::function<bool(StringRef, std::optional<OutputConfig>)> Filter;
74 };
75
77 std::move(UnderlyingBackend), std::move(Filter));
78}
79
83 struct ProxyOutputBackend1 : public ProxyOutputBackend {
85 };
86 struct ProxyOutputBackend2 : public ProxyOutputBackend {
88 };
89 struct MirroringOutput final : public OutputFileImpl, raw_pwrite_stream {
90 Error keep() final {
91 flush();
92 return joinErrors(F1->keep(), F2->keep());
93 }
94 Error discard() final {
95 flush();
96 return joinErrors(F1->discard(), F2->discard());
97 }
98 raw_pwrite_stream &getOS() final { return *this; }
99
100 void write_impl(const char *Ptr, size_t Size) override {
101 F1->getOS().write(Ptr, Size);
102 F2->getOS().write(Ptr, Size);
103 }
104 void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) override {
105 this->flush();
106 F1->getOS().pwrite(Ptr, Size, Offset);
107 F2->getOS().pwrite(Ptr, Size, Offset);
108 }
109 uint64_t current_pos() const override { return F1->getOS().tell(); }
110 size_t preferred_buffer_size() const override {
111 return PreferredBufferSize;
112 }
113 void reserveExtraSpace(uint64_t ExtraSize) override {
114 F1->getOS().reserveExtraSpace(ExtraSize);
115 F2->getOS().reserveExtraSpace(ExtraSize);
116 }
117 bool is_displayed() const override {
118 return F1->getOS().is_displayed() && F2->getOS().is_displayed();
119 }
120 bool has_colors() const override {
121 return F1->getOS().has_colors() && F2->getOS().has_colors();
122 }
123 void enable_colors(bool enable) override {
125 F1->getOS().enable_colors(enable);
126 F2->getOS().enable_colors(enable);
127 }
128
129 MirroringOutput(std::unique_ptr<OutputFileImpl> F1,
130 std::unique_ptr<OutputFileImpl> F2)
131 : PreferredBufferSize(std::max(F1->getOS().GetBufferSize(),
132 F1->getOS().GetBufferSize())),
133 F1(std::move(F1)), F2(std::move(F2)) {
134 // Don't double buffer.
135 this->F1->getOS().SetUnbuffered();
136 this->F2->getOS().SetUnbuffered();
137 }
138 size_t PreferredBufferSize;
139 std::unique_ptr<OutputFileImpl> F1;
140 std::unique_ptr<OutputFileImpl> F2;
141 };
142 struct MirroringOutputBackend : public ProxyOutputBackend1,
143 public ProxyOutputBackend2 {
145 createFileImpl(StringRef Path,
146 std::optional<OutputConfig> Config) override {
147 std::unique_ptr<OutputFileImpl> File1;
148 std::unique_ptr<OutputFileImpl> File2;
149 if (Error E =
150 ProxyOutputBackend1::createFileImpl(Path, Config).moveInto(File1))
151 return std::move(E);
152 if (Error E =
153 ProxyOutputBackend2::createFileImpl(Path, Config).moveInto(File2))
154 return joinErrors(std::move(E), File1->discard());
155
156 // Skip the extra indirection if one of these is a null output.
157 if (isa<NullOutputFileImpl>(*File1)) {
158 consumeError(File1->discard());
159 return std::move(File2);
160 }
161 if (isa<NullOutputFileImpl>(*File2)) {
162 consumeError(File2->discard());
163 return std::move(File1);
164 }
165 return std::make_unique<MirroringOutput>(std::move(File1),
166 std::move(File2));
167 }
168
169 IntrusiveRefCntPtr<OutputBackend> cloneImpl() const override {
172 ProxyOutputBackend1::getUnderlyingBackend().clone(),
173 ProxyOutputBackend2::getUnderlyingBackend().clone()));
174 }
175 void Retain() const { ProxyOutputBackend1::Retain(); }
176 void Release() const { ProxyOutputBackend1::Release(); }
177
178 MirroringOutputBackend(IntrusiveRefCntPtr<OutputBackend> Backend1,
180 : ProxyOutputBackend1(std::move(Backend1)),
181 ProxyOutputBackend2(std::move(Backend2)) {}
182 };
183
184 assert(Backend1 && "Expected actual backend");
185 assert(Backend2 && "Expected actual backend");
188 std::move(Backend2)));
189}
190
191static OutputConfig
192applySettings(std::optional<OutputConfig> &&Config,
193 const OnDiskOutputBackend::OutputSettings &Settings) {
194 if (!Config)
195 Config = Settings.DefaultConfig;
196 if (!Settings.UseTemporaries)
197 Config->setNoAtomicWrite();
198 if (!Settings.RemoveOnSignal)
199 Config->setNoDiscardOnSignal();
200 return *Config;
201}
202
203namespace {
204class OnDiskOutputFile final : public OutputFileImpl {
205public:
206 Error keep() override;
207 Error discard() override;
208 raw_pwrite_stream &getOS() override {
209 assert(FileOS && "Expected valid file");
210 if (BufferOS)
211 return *BufferOS;
212 return *FileOS;
213 }
214
215 /// Attempt to open a temporary file for \p OutputPath.
216 ///
217 /// This tries to open a uniquely-named temporary file for \p OutputPath,
218 /// possibly also creating any missing directories if \a
219 /// OnDiskOutputConfig::UseTemporaryCreateMissingDirectories is set in \a
220 /// Config.
221 ///
222 /// \post FD and \a TempPath are initialized if this is successful.
223 Error tryToCreateTemporary(std::optional<int> &FD);
224
225 Error initializeFile(std::optional<int> &FD);
226 Error initializeStream();
227 Error reset();
228
229 OnDiskOutputFile(StringRef OutputPath, std::optional<OutputConfig> Config,
230 const OnDiskOutputBackend::OutputSettings &Settings)
231 : Config(applySettings(std::move(Config), Settings)),
232 OutputPath(OutputPath.str()) {}
233
234 OutputConfig Config;
235 const std::string OutputPath;
236 std::optional<std::string> TempPath;
237 std::optional<raw_fd_ostream> FileOS;
238 std::optional<buffer_ostream> BufferOS;
239};
240} // end namespace
241
243 OutputConfig Config,
244 llvm::function_ref<Error()> CreateFile) {
245 return handleErrors(CreateFile(), [&](std::unique_ptr<ECError> EC) {
246 if (EC->convertToErrorCode() != std::errc::no_such_file_or_directory ||
247 Config.getNoImplyCreateDirectories())
248 return Error(std::move(EC));
249
250 StringRef ParentPath = sys::path::parent_path(OutputPath);
251 if (std::error_code EC = sys::fs::create_directories(ParentPath))
252 return make_error<OutputError>(ParentPath, EC);
253 return CreateFile();
254 });
255}
256
257Error OnDiskOutputFile::tryToCreateTemporary(std::optional<int> &FD) {
258 // Create a temporary file.
259 // Insert -%%%%%%%% before the extension (if any), and because some tools
260 // (noticeable, clang's own GlobalModuleIndex.cpp) glob for build
261 // artifacts, also append .tmp.
262 StringRef OutputExtension = sys::path::extension(OutputPath);
263 SmallString<128> ModelPath =
264 StringRef(OutputPath).drop_back(OutputExtension.size());
265 ModelPath += "-%%%%%%%%";
266 ModelPath += OutputExtension;
267 ModelPath += ".tmp";
268
269 return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
270 int NewFD;
271 SmallString<128> UniquePath;
272 if (std::error_code EC =
273 sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath))
274 return make_error<TempFileOutputError>(ModelPath, OutputPath, EC);
275
276 if (Config.getDiscardOnSignal())
277 sys::RemoveFileOnSignal(UniquePath);
278
279 TempPath = UniquePath.str().str();
280 FD.emplace(NewFD);
281 return Error::success();
282 });
283}
284
285Error OnDiskOutputFile::initializeFile(std::optional<int> &FD) {
286 assert(OutputPath != "-" && "Unexpected request for FD of stdout");
287
288 // Disable temporary file for other non-regular files, and if we get a status
289 // object, also check if we can write and disable write-through buffers if
290 // appropriate.
291 if (Config.getAtomicWrite()) {
292 sys::fs::file_status Status;
293 sys::fs::status(OutputPath, Status);
294 if (sys::fs::exists(Status)) {
296 Config.setNoAtomicWrite();
297
298 // Fail now if we can't write to the final destination.
299 if (!sys::fs::can_write(OutputPath))
301 OutputPath,
302 std::make_error_code(std::errc::operation_not_permitted));
303 }
304 }
305
306 // If (still) using a temporary file, try to create it (and return success if
307 // that works).
308 if (Config.getAtomicWrite())
309 if (!errorToBool(tryToCreateTemporary(FD)))
310 return Error::success();
311
312 // Not using a temporary file. Open the final output file.
313 return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
314 int NewFD;
316 if (Config.getTextWithCRLF())
318 else if (Config.getText())
320 if (Config.getAppend())
322 if (std::error_code EC = sys::fs::openFileForWrite(
323 OutputPath, NewFD, sys::fs::CD_CreateAlways, OF))
324 return convertToOutputError(OutputPath, EC);
325 FD.emplace(NewFD);
326
327 if (Config.getDiscardOnSignal())
328 sys::RemoveFileOnSignal(OutputPath);
329 return Error::success();
330 });
331}
332
333Error OnDiskOutputFile::initializeStream() {
334 // Open the file stream.
335 if (OutputPath == "-") {
336 std::error_code EC;
337 FileOS.emplace(OutputPath, EC);
338 if (EC)
339 return make_error<OutputError>(OutputPath, EC);
340 } else {
341 std::optional<int> FD;
342 if (Error E = initializeFile(FD))
343 return E;
344 FileOS.emplace(*FD, /*shouldClose=*/true);
345 }
346
347 // Buffer the stream if necessary.
348 if (!FileOS->supportsSeeking() && !Config.getText())
349 BufferOS.emplace(*FileOS);
350
351 return Error::success();
352}
353
354namespace {
355class OpenFileRAII {
356 static const int InvalidFd = -1;
357
358public:
359 int Fd = InvalidFd;
360
361 ~OpenFileRAII() {
362 if (Fd != InvalidFd)
364 }
365};
366
367enum class FileDifference : uint8_t {
368 /// The source and destination paths refer to the exact same file.
369 IdenticalFile,
370 /// The source and destination paths refer to separate files with identical
371 /// contents.
372 SameContents,
373 /// The source and destination paths refer to separate files with different
374 /// contents.
375 DifferentContents
376};
377} // end anonymous namespace
378
379static Expected<FileDifference>
380areFilesDifferent(const llvm::Twine &Source, const llvm::Twine &Destination) {
381 if (sys::fs::equivalent(Source, Destination))
382 return FileDifference::IdenticalFile;
383
384 OpenFileRAII SourceFile;
385 sys::fs::file_status SourceStatus;
386 // If we can't open the source file, fail.
387 if (std::error_code EC = sys::fs::openFileForRead(Source, SourceFile.Fd))
388 return convertToOutputError(Source, EC);
389
390 // If we can't stat the source file, fail.
391 if (std::error_code EC = sys::fs::status(SourceFile.Fd, SourceStatus))
392 return convertToOutputError(Source, EC);
393
394 OpenFileRAII DestFile;
395 sys::fs::file_status DestStatus;
396 // If we can't open the destination file, report different.
397 if (std::error_code Error =
398 sys::fs::openFileForRead(Destination, DestFile.Fd))
399 return FileDifference::DifferentContents;
400
401 // If we can't open the destination file, report different.
402 if (std::error_code Error = sys::fs::status(DestFile.Fd, DestStatus))
403 return FileDifference::DifferentContents;
404
405 // If the files are different sizes, they must be different.
406 uint64_t Size = SourceStatus.getSize();
407 if (Size != DestStatus.getSize())
408 return FileDifference::DifferentContents;
409
410 // If both files are zero size, they must be the same.
411 if (Size == 0)
412 return FileDifference::SameContents;
413
414 // The two files match in size, so we have to compare the bytes to determine
415 // if they're the same.
416 std::error_code SourceRegionErr;
417 sys::fs::mapped_file_region SourceRegion(
418 sys::fs::convertFDToNativeFile(SourceFile.Fd),
419 sys::fs::mapped_file_region::readonly, Size, 0, SourceRegionErr);
420 if (SourceRegionErr)
421 return convertToOutputError(Source, SourceRegionErr);
422
423 std::error_code DestRegionErr;
427
428 if (DestRegionErr)
429 return FileDifference::DifferentContents;
430
431 if (memcmp(SourceRegion.const_data(), DestRegion.const_data(), Size) != 0)
432 return FileDifference::DifferentContents;
433
434 return FileDifference::SameContents;
435}
436
437Error OnDiskOutputFile::reset() {
438 // Destroy the streams to flush them.
439 BufferOS.reset();
440 if (!FileOS)
441 return Error::success();
442
443 // Remember the error in raw_fd_ostream to be reported later.
444 std::error_code EC = FileOS->error();
445 // Clear the error to avoid fatal error when reset.
446 FileOS->clear_error();
447 FileOS.reset();
448 return errorCodeToError(EC);
449}
450
451Error OnDiskOutputFile::keep() {
452 if (auto E = reset())
453 return E;
454
455 // Close the file descriptor and remove crash cleanup before exit.
456 auto RemoveDiscardOnSignal = make_scope_exit([&]() {
457 if (Config.getDiscardOnSignal())
458 sys::DontRemoveFileOnSignal(TempPath ? *TempPath : OutputPath);
459 });
460
461 if (!TempPath)
462 return Error::success();
463
464 // See if we should append instead of move.
465 if (Config.getAppend() && OutputPath != "-") {
466 // Read TempFile for the content to append.
467 auto Content = MemoryBuffer::getFile(*TempPath);
468 if (!Content)
469 return convertToTempFileOutputError(*TempPath, OutputPath,
470 Content.getError());
471 while (1) {
472 // Attempt to lock the output file.
473 // Only one process is allowed to append to this file at a time.
474 llvm::LockFileManager Lock(OutputPath);
475 bool Owned;
476 if (Error Err = Lock.tryLock().moveInto(Owned)) {
477 // If we error acquiring a lock, we cannot ensure appends
478 // to the trace file are atomic - cannot ensure output correctness.
479 Lock.unsafeMaybeUnlock();
481 OutputPath, std::make_error_code(std::errc::no_lock_available));
482 }
483 if (Owned) {
484 // Lock acquired, perform the write and release the lock.
485 std::error_code EC;
486 llvm::raw_fd_ostream Out(OutputPath, EC, llvm::sys::fs::OF_Append);
487 if (EC)
488 return convertToOutputError(OutputPath, EC);
489 Out << (*Content)->getBuffer();
490 Out.close();
491 Lock.unsafeMaybeUnlock();
492 if (Out.has_error())
493 return convertToOutputError(OutputPath, Out.error());
494 // Remove temp file and done.
495 (void)sys::fs::remove(*TempPath);
496 return Error::success();
497 }
498 // Someone else owns the lock on this file, wait.
499 switch (Lock.waitForUnlockFor(std::chrono::seconds(256))) {
503 continue; // try again to get the lock.
504 }
506 // We could error on timeout to avoid potentially hanging forever, but
507 // it may be more likely that an interrupted process failed to clear
508 // the lock, causing other waiting processes to time-out. Let's clear
509 // the lock and try again right away. If we do start seeing compiler
510 // hangs in this location, we will need to re-consider.
511 Lock.unsafeMaybeUnlock();
512 continue;
513 }
514 }
515 break;
516 }
517 }
518
519 if (Config.getOnlyIfDifferent()) {
520 auto Result = areFilesDifferent(*TempPath, OutputPath);
521 if (!Result)
522 return Result.takeError();
523 switch (*Result) {
524 case FileDifference::IdenticalFile:
525 // Do nothing for a self-move.
526 return Error::success();
527
528 case FileDifference::SameContents:
529 // Files are identical; remove the source file.
530 (void)sys::fs::remove(*TempPath);
531 return Error::success();
532
533 case FileDifference::DifferentContents:
534 break; // Rename the file.
535 }
536 }
537
538 // Move temporary to the final output path and remove it if that fails.
539 std::error_code RenameEC = sys::fs::rename(*TempPath, OutputPath);
540 if (!RenameEC)
541 return Error::success();
542
543 // FIXME: TempPath should be in the same directory as OutputPath but try to
544 // copy the output to see if makes any difference. If this path is used,
545 // investigate why we need to copy.
546 RenameEC = sys::fs::copy_file(*TempPath, OutputPath);
547 (void)sys::fs::remove(*TempPath);
548
549 if (!RenameEC)
550 return Error::success();
551
552 return make_error<TempFileOutputError>(*TempPath, OutputPath, RenameEC);
553}
554
555Error OnDiskOutputFile::discard() {
556 // Destroy the streams to flush them.
557 if (auto E = reset())
558 return E;
559
560 // Nothing on the filesystem to remove for stdout.
561 if (OutputPath == "-")
562 return Error::success();
563
564 auto discardPath = [&](StringRef Path) {
565 std::error_code EC = sys::fs::remove(Path);
567 return EC;
568 };
569
570 // Clean up the file that's in-progress.
571 if (!TempPath)
572 return convertToOutputError(OutputPath, discardPath(OutputPath));
573 return convertToTempFileOutputError(*TempPath, OutputPath,
574 discardPath(*TempPath));
575}
576
578 return convertToOutputError(StringRef(Path.data(), Path.size()),
580}
581
584 std::optional<OutputConfig> Config) {
585 SmallString<256> AbsPath;
586 if (Path != "-") {
587 AbsPath = Path;
588 if (Error E = makeAbsolute(AbsPath))
589 return std::move(E);
590 Path = AbsPath;
591 }
592
593 auto File = std::make_unique<OnDiskOutputFile>(Path, Config, Settings);
594 if (Error E = File->initializeStream())
595 return std::move(E);
596
597 return std::move(File);
598}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition Compiler.h:404
Merge contiguous icmps into a memcmp
Provides a library for accessing information about this process and other processes on the operating ...
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
static Error createDirectoriesOnDemand(StringRef OutputPath, OutputConfig Config, llvm::function_ref< Error()> CreateFile)
static Expected< FileDifference > areFilesDifferent(const llvm::Twine &Source, const llvm::Twine &Destination)
static OutputConfig applySettings(std::optional< OutputConfig > &&Config, const OnDiskOutputBackend::OutputSettings &Settings)
This file contains the declarations of the concrete VirtualOutputBackend classes, which are the imple...
This file contains the declarations of the OutputConfig class.
This file contains the declarations of the OutputError class.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:233
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:154
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An efficient, type-erasing, non-owning reference to a callable.
raw_ostream & write(unsigned char C)
virtual void enable_colors(bool enable)
An abstract base class for streams implementations that also support a pwrite operation.
static LLVM_ABI std::error_code SafelyCloseFileDescriptor(int FD)
Represents the result of a call to sys::fs::status().
Definition FileSystem.h:222
This class represents a memory mapped file.
@ readonly
May only access map via const_data as read only.
LLVM_ABI const char * const_data() const
Get a const view of the data.
Definition Path.cpp:1169
Represents an open file.
Expected< std::unique_ptr< OutputFileImpl > > createFileImpl(StringRef Path, std::optional< OutputConfig > Config) override
Create a file for Path.
OutputSettings Settings
Settings for this backend.
Error makeAbsolute(SmallVectorImpl< char > &Path) const
Resolve an absolute path.
Interface for virtualized outputs.
A helper class for proxying another backend, with the default implementation to forward to the underl...
ProxyOutputBackend(IntrusiveRefCntPtr< OutputBackend > UnderlyingBackend)
Expected< std::unique_ptr< OutputFileImpl > > createFileImpl(StringRef Path, std::optional< OutputConfig > Config) override
Create a file for Path.
The result of a status operation.
CallInst * Retain
LLVM_ABI bool is_regular_file(const basic_file_status &status)
Does status represent a regular file?
Definition Path.cpp:1104
LLVM_ABI void make_absolute(const Twine &current_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Definition Path.cpp:906
LLVM_ABI std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
bool can_write(const Twine &Path)
Can we write this file?
Definition FileSystem.h:476
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
Definition Path.cpp:1077
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
Definition FileSystem.h:762
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition FileSystem.h:771
@ OF_Append
The file should be opened in append mode.
Definition FileSystem.h:774
LLVM_ABI std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
Create a uniquely named file.
Definition Path.cpp:822
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
Definition FileSystem.h:734
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
Definition Path.cpp:967
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
Definition Path.cpp:1016
LLVM_ABI file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
Definition FileSystem.h:998
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
Definition Path.cpp:467
LLVM_ABI StringRef extension(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get extension.
Definition Path.cpp:590
LLVM_ABI void DontRemoveFileOnSignal(StringRef Filename)
This function removes a file from the list of files to be removed on signal delivery.
LLVM_ABI bool RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg=nullptr)
This function registers signal handlers to ensure that if a signal gets delivered that the named file...
Error convertToOutputError(const Twine &OutputPath, std::error_code EC)
Return Error::success() or use OutputPath to create an OutputError, depending on EC.
IntrusiveRefCntPtr< OutputBackend > makeNullOutputBackend()
Create a backend that ignores all output.
IntrusiveRefCntPtr< OutputBackend > makeFilteringOutputBackend(IntrusiveRefCntPtr< OutputBackend > UnderlyingBackend, std::function< bool(StringRef, std::optional< OutputConfig >)> Filter)
Make a backend where OutputBackend::createFile() forwards to UnderlyingBackend when Filter is true,...
IntrusiveRefCntPtr< OutputBackend > makeMirroringOutputBackend(IntrusiveRefCntPtr< OutputBackend > Backend1, IntrusiveRefCntPtr< OutputBackend > Backend2)
Create a backend that forwards OutputBackend::createFile() to both Backend1 and Backend2.
Error convertToTempFileOutputError(const Twine &TempPath, const Twine &OutputPath, std::error_code EC)
Return Error::success() or use TempPath and OutputPath to create a TempFileOutputError,...
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
Definition Error.h:1113
@ Offset
Definition DWP.cpp:477
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
Definition ScopeExit.h:59
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition Error.h:967
IntrusiveRefCntPtr< T > makeIntrusiveRefCnt(Args &&...A)
Factory function for creating intrusive ref counted pointers.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition Error.h:442
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
@ Success
The lock was released successfully.
@ OwnerDied
Owner died while holding the lock.
@ Timeout
Reached timeout while waiting for the owner to release the lock.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1869
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition Error.cpp:111
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1083
bool RemoveOnSignal
Register output files to be deleted if a signal is received.
Full configuration for an output for use by the OutputBackend.
constexpr bool getTextWithCRLF() const