summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/COFFObjectFile.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-21 23:06:54 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-21 23:06:54 +0000
commit692410efcb1330fc69aa75a042bea98c4eab80ba (patch)
tree41e211e52e88df872eab5a337196fc37dfc8ae72 /llvm/lib/Object/COFFObjectFile.cpp
parent902efc61be719775ccb15cb95ce6c2e79566dd5e (diff)
downloadbcm5719-llvm-692410efcb1330fc69aa75a042bea98c4eab80ba.tar.gz
bcm5719-llvm-692410efcb1330fc69aa75a042bea98c4eab80ba.zip
Be a bit more consistent about using ErrorOr when constructing Binary objects.
The constructors of classes deriving from Binary normally take an error_code as an argument to the constructor. My original intent was to change them to have a trivial constructor and move the initial parsing logic to a static method returning an ErrorOr. I changed my mind because: * A constructor with an error_code out parameter is extremely convenient from the implementation side. We can incrementally construct the object and give up when we find an error. * It is very efficient when constructing on the stack or when there is no error. The only inefficient case is where heap allocating and an error is found (we have to free the memory). The result is that this is a much smaller patch. It just standardizes the create* helpers to return an ErrorOr. Almost no functionality change: The only difference is that this found that we were trying to read past the end of COFF import library but ignoring the error. llvm-svn: 199770
Diffstat (limited to 'llvm/lib/Object/COFFObjectFile.cpp')
-rw-r--r--llvm/lib/Object/COFFObjectFile.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index ec8989d5c67..a7b06885008 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -514,10 +514,12 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &EC)
CurPtr += COFFHeader->SizeOfOptionalHeader;
}
- if (!COFFHeader->isImportLibrary())
- if ((EC = getObject(SectionTable, Data, base() + CurPtr,
- COFFHeader->NumberOfSections * sizeof(coff_section))))
- return;
+ if (COFFHeader->isImportLibrary())
+ return;
+
+ if ((EC = getObject(SectionTable, Data, base() + CurPtr,
+ COFFHeader->NumberOfSections * sizeof(coff_section))))
+ return;
// Initialize the pointer to the symbol table.
if (COFFHeader->PointerToSymbolTable != 0)
@@ -1013,9 +1015,10 @@ error_code ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const {
return object_error::success;
}
-namespace llvm {
-ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
+ErrorOr<ObjectFile *> ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
error_code EC;
- return new COFFObjectFile(Object, EC);
-}
+ OwningPtr<COFFObjectFile> Ret(new COFFObjectFile(Object, EC));
+ if (EC)
+ return EC;
+ return Ret.take();
}
OpenPOWER on IntegriCloud