summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-29 00:02:26 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-29 00:02:26 +0000
commitc3ceeb6fa751e82de1aff19ff0cf812fc94237cb (patch)
treeae2c82fe314eda2be055d940c1a5dca99182b9ab /llvm
parent1e632af0d4989357836a52ff8a0e237e69ca81d3 (diff)
downloadbcm5719-llvm-c3ceeb6fa751e82de1aff19ff0cf812fc94237cb.tar.gz
bcm5719-llvm-c3ceeb6fa751e82de1aff19ff0cf812fc94237cb.zip
Make createObjectFile's signature a bit less error prone.
This will be better with c++11, but right now file_magic converts to bool, which makes the api really easy to misuse. llvm-svn: 200357
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Object/ObjectFile.h10
-rw-r--r--llvm/lib/Object/Binary.cpp2
-rw-r--r--llvm/tools/llvm-ar/llvm-ar.cpp3
3 files changed, 10 insertions, 5 deletions
diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h
index 806de34e76a..7533d625b12 100644
--- a/llvm/include/llvm/Object/ObjectFile.h
+++ b/llvm/include/llvm/Object/ObjectFile.h
@@ -378,9 +378,13 @@ public:
/// return true.
/// @brief Create ObjectFile from path.
static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
- static ErrorOr<ObjectFile *>
- createObjectFile(MemoryBuffer *Object, bool BufferOwned = true,
- sys::fs::file_magic Type = sys::fs::file_magic::unknown);
+ static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object,
+ bool BufferOwned,
+ sys::fs::file_magic Type);
+ static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object) {
+ return createObjectFile(Object, true, sys::fs::file_magic::unknown);
+ }
+
static inline bool classof(const Binary *v) {
return v->isObject();
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp
index a2f4ec9a0b8..63898d277f3 100644
--- a/llvm/lib/Object/Binary.cpp
+++ b/llvm/lib/Object/Binary.cpp
@@ -67,7 +67,7 @@ ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source,
case sys::fs::file_magic::coff_object:
case sys::fs::file_magic::coff_import_library:
case sys::fs::file_magic::pecoff_executable:
- return ObjectFile::createObjectFile(scopedSource.take(), Type);
+ return ObjectFile::createObjectFile(scopedSource.take(), true, Type);
case sys::fs::file_magic::macho_universal_binary:
return MachOUniversalBinary::create(scopedSource.take());
case sys::fs::file_magic::unknown:
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 944cce408fa..8917cd3801f 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -703,7 +703,8 @@ static void writeSymbolTable(
I != E; ++I, ++MemberNum) {
MemoryBuffer *MemberBuffer = Buffers[MemberNum];
ErrorOr<object::ObjectFile *> ObjOrErr =
- object::ObjectFile::createObjectFile(MemberBuffer, false);
+ object::ObjectFile::createObjectFile(MemberBuffer, false,
+ sys::fs::file_magic::unknown);
if (!ObjOrErr)
continue; // FIXME: check only for "not an object file" errors.
object::ObjectFile *Obj = ObjOrErr.get();
OpenPOWER on IntegriCloud