summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h2
-rw-r--r--llvm/include/llvm/Object/Archive.h2
-rw-r--r--llvm/include/llvm/Support/Error.h20
-rw-r--r--llvm/lib/Object/Archive.cpp7
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp2
-rw-r--r--llvm/lib/Object/MachOUniversal.cpp2
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp2
7 files changed, 22 insertions, 15 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
index 5c867e7e7fd..12705aff9e1 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
@@ -688,7 +688,7 @@ public:
private:
OrcRemoteTargetClient(ChannelT &Channel, Error &Err) : Channel(Channel) {
- ErrorAsOutParameter EAO(Err);
+ ErrorAsOutParameter EAO(&Err);
if (auto RIOrErr = callST<GetRemoteInfo>(Channel)) {
std::tie(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
RemoteTrampolineSize, RemoteIndirectStubSize) = *RIOrErr;
diff --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h
index c71f138c67e..b252c82f281 100644
--- a/llvm/include/llvm/Object/Archive.h
+++ b/llvm/include/llvm/Object/Archive.h
@@ -131,10 +131,10 @@ public:
// iteration. And if there is an error break out of the loop.
child_iterator &operator++() { // Preincrement
assert(E && "Can't increment iterator with no Error attached");
+ ErrorAsOutParameter ErrAsOutParam(E);
if (auto ChildOrErr = C.getNext())
C = *ChildOrErr;
else {
- ErrorAsOutParameter ErrAsOutParam(*E);
C = C.getParent()->child_end().C;
*E = ChildOrErr.takeError();
E = nullptr;
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 5f515a88a02..0064e097056 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -571,24 +571,32 @@ inline void consumeError(Error Err) {
/// RAII:
///
/// Result foo(Error &Err) {
-/// ErrorAsOutParameter ErrAsOutParam(Err); // 'Checked' flag set
+/// ErrorAsOutParameter ErrAsOutParam(&Err); // 'Checked' flag set
/// // <body of foo>
/// // <- 'Checked' flag auto-cleared when ErrAsOutParam is destructed.
/// }
+///
+/// ErrorAsOutParameter takes an Error* rather than Error& so that it can be
+/// used with optional Errors (Error pointers that are allowed to be null). If
+/// ErrorAsOutParameter took an Error reference, an instance would have to be
+/// created inside every condition that verified that Error was non-null. By
+/// taking an Error pointer we can just create one instance at the top of the
+/// function.
class ErrorAsOutParameter {
public:
- ErrorAsOutParameter(Error &Err) : Err(Err) {
+ ErrorAsOutParameter(Error *Err) : Err(Err) {
// Raise the checked bit if Err is success.
- (void)!!Err;
+ if (Err)
+ (void)!!*Err;
}
~ErrorAsOutParameter() {
// Clear the checked bit.
- if (!Err)
- Err = Error::success();
+ if (Err && !*Err)
+ *Err = Error::success();
}
private:
- Error &Err;
+ Error *Err;
};
/// Tagged union holding either a T or a Error.
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index 6d0330d52ec..84ef358344d 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -108,16 +108,15 @@ Archive::Child::Child(const Archive *Parent, const char *Start, Error *Err)
: Parent(Parent) {
if (!Start)
return;
+ ErrorAsOutParameter ErrAsOutParam(Err);
uint64_t Size = sizeof(ArchiveMemberHeader);
Data = StringRef(Start, Size);
if (!isThinMember()) {
Expected<uint64_t> MemberSize = getRawSize();
if (!MemberSize) {
- if (Err) {
- ErrorAsOutParameter ErrAsOutParam(*Err);
+ if (Err)
*Err = MemberSize.takeError();
- }
return;
}
Size += MemberSize.get();
@@ -299,7 +298,7 @@ void Archive::setFirstRegular(const Child &C) {
Archive::Archive(MemoryBufferRef Source, Error &Err)
: Binary(Binary::ID_Archive, Source) {
- ErrorAsOutParameter ErrAsOutParam(Err);
+ ErrorAsOutParameter ErrAsOutParam(&Err);
StringRef Buffer = Data.getBuffer();
// Check for sufficient magic.
if (Buffer.startswith(ThinMagic)) {
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 563236f95a5..262dbe12ed4 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -267,7 +267,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
DataInCodeLoadCmd(nullptr), LinkOptHintsLoadCmd(nullptr),
DyldInfoLoadCmd(nullptr), UuidLoadCmd(nullptr),
HasPageZeroSegment(false) {
- ErrorAsOutParameter ErrAsOutParam(Err);
+ ErrorAsOutParameter ErrAsOutParam(&Err);
uint64_t BigSize;
if (is64Bit()) {
parseHeader(this, Header64, Err);
diff --git a/llvm/lib/Object/MachOUniversal.cpp b/llvm/lib/Object/MachOUniversal.cpp
index 66c9151eb69..f36e84d93b9 100644
--- a/llvm/lib/Object/MachOUniversal.cpp
+++ b/llvm/lib/Object/MachOUniversal.cpp
@@ -114,7 +114,7 @@ MachOUniversalBinary::create(MemoryBufferRef Source) {
MachOUniversalBinary::MachOUniversalBinary(MemoryBufferRef Source, Error &Err)
: Binary(Binary::ID_MachOUniversalBinary, Source), Magic(0),
NumberOfObjects(0) {
- ErrorAsOutParameter ErrAsOutParam(Err);
+ ErrorAsOutParameter ErrAsOutParam(&Err);
if (Data.getBufferSize() < sizeof(MachO::fat_header)) {
Err = make_error<GenericBinaryError>("File too small to be a Mach-O "
"universal file",
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 20509268374..3d2f2089cf7 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -109,7 +109,7 @@ TEST(Error, UncheckedSuccess) {
// ErrorAsOutParameter tester.
void errAsOutParamHelper(Error &Err) {
- ErrorAsOutParameter ErrAsOutParam(Err);
+ ErrorAsOutParameter ErrAsOutParam(&Err);
// Verify that checked flag is raised - assignment should not crash.
Err = Error::success();
// Raise the checked bit manually - caller should still have to test the
OpenPOWER on IntegriCloud