LLVM 22.0.0git
VirtualOutputFile.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 \c OutputFile class methods.
11///
12//===----------------------------------------------------------------------===//
13
18
19using namespace llvm;
20using namespace llvm::vfs;
21
22char OutputFileImpl::ID = 0;
24
25void OutputFileImpl::anchor() {}
26void NullOutputFileImpl::anchor() {}
27
45
47 if (OpenProxy)
49
50 return std::make_unique<TrackedProxy>(OpenProxy, getOS());
51}
52
54 // Catch double-closing logic bugs.
55 if (LLVM_UNLIKELY(!Impl))
58
59 // Report a fatal error if there's an open proxy and the file is being kept.
60 // This is safer than relying on clients to remember to flush(). Also call
61 // OutputFile::discard() to give the backend a chance to clean up any
62 // side effects (such as temporaries).
63 if (LLVM_UNLIKELY(OpenProxy))
66 discard()));
67
68 Error E = Impl->keep();
69 Impl = nullptr;
70 DiscardOnDestroyHandler = nullptr;
71 return E;
72}
73
75 // Catch double-closing logic bugs.
76 if (LLVM_UNLIKELY(!Impl))
79
80 // Be lenient about open proxies since client teardown paths won't
81 // necessarily clean up in the right order. Reset the proxy to flush any
82 // current content; if there is another write, there should be quick crash on
83 // null dereference.
84 if (OpenProxy)
85 OpenProxy->resetProxy();
86
87 Error E = Impl->discard();
88 Impl = nullptr;
89 DiscardOnDestroyHandler = nullptr;
90 return E;
91}
92
93void OutputFile::destroy() {
94 if (!Impl)
95 return;
96
97 // Clean up the file. Move the discard handler into a local since discard
98 // will reset it.
99 auto DiscardHandler = std::move(DiscardOnDestroyHandler);
100 Error E = discard();
101 assert(!Impl && "Expected discard to destroy Impl");
102
103 // If there's no handler, report a fatal error.
104 if (LLVM_UNLIKELY(!DiscardHandler))
107 std::move(E)));
108 else if (E)
109 DiscardHandler(std::move(E));
110}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:336
This file contains the declarations of the OutputError class.
This file contains the declarations of the llvm::vfs::OutputFile class, which is a virtualized output...
TrackedProxy(TrackedProxy *&TrackingPointer, raw_pwrite_stream &OS)
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
raw_pwrite_stream_proxy(raw_pwrite_stream &OS)
raw_pwrite_stream(bool Unbuffered=false, OStreamKind K=OStreamKind::OK_OStream)
StringRef getPath() const
raw_pwrite_stream & getOS()
Expected< std::unique_ptr< raw_pwrite_stream > > createProxy()
Create a proxy stream for clients that need to pass an owned stream to a producer.
Error discard()
Discard an output, cleaning up any temporary state.
Error keep()
Keep an output.
This is an optimization pass for GlobalISel generic memory operations.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition Error.h:442
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340