2017-06-08 12:15:29 +00:00
|
|
|
From: Jiri Slaby <jirislaby@gmail.com>
|
|
|
|
Date: Wed, 7 Jun 2017 14:58:29 +0200
|
|
|
|
Subject: llvm40: errorOr and similar
|
|
|
|
Patch-mainline: no
|
|
|
|
|
|
|
|
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
|
|
|
|
---
|
2017-08-17 12:28:29 +00:00
|
|
|
lib/Module/ModuleUtil.cpp | 50 ++++++++++++++++++++++++++++++++++++++---------
|
|
|
|
1 file changed, 41 insertions(+), 9 deletions(-)
|
2017-06-08 12:15:29 +00:00
|
|
|
|
|
|
|
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
|
2017-11-17 17:18:06 +00:00
|
|
|
index 8aa070743048..ad847de0b368 100644
|
2017-06-08 12:15:29 +00:00
|
|
|
--- a/lib/Module/ModuleUtil.cpp
|
|
|
|
+++ b/lib/Module/ModuleUtil.cpp
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -204,7 +204,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-06-08 12:15:29 +00:00
|
|
|
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading modules\n");
|
|
|
|
// Load all bitcode files in to memory so we can examine their symbols
|
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
|
|
|
|
- Error Err;
|
|
|
|
+ Error Err = Error::success();
|
|
|
|
for (object::Archive::child_iterator AI = archive->child_begin(Err),
|
|
|
|
AE = archive->child_end(); AI != AE; ++AI)
|
|
|
|
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
2017-08-17 12:28:29 +00:00
|
|
|
@@ -229,8 +229,14 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-06-08 12:15:29 +00:00
|
|
|
#else
|
|
|
|
object::Archive::child_iterator childErr = AI;
|
|
|
|
#endif
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
|
|
+ Expected<StringRef> memberNameErr = childErr->getName();
|
|
|
|
+ ec = memberNameErr ? std::error_code() :
|
|
|
|
+ errorToErrorCode(memberNameErr.takeError());
|
|
|
|
+#else
|
|
|
|
ErrorOr<StringRef> memberNameErr = childErr->getName();
|
|
|
|
ec = memberNameErr.getError();
|
|
|
|
+#endif
|
|
|
|
if (!ec) {
|
|
|
|
memberName = memberNameErr.get();
|
|
|
|
#else
|
2017-11-17 17:18:06 +00:00
|
|
|
@@ -267,7 +273,10 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-06-08 12:15:29 +00:00
|
|
|
#endif
|
|
|
|
if (ec) {
|
|
|
|
// If we can't open as a binary object file its hopefully a bitcode file
|
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
|
|
+ Expected<MemoryBufferRef> buff = childErr->getMemoryBufferRef();
|
|
|
|
+ ec = buff ? std::error_code() : errorToErrorCode(buff.takeError());
|
|
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
|
|
ErrorOr<MemoryBufferRef> buff = childErr->getMemoryBufferRef();
|
|
|
|
ec = buff.getError();
|
|
|
|
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
2017-11-17 17:18:06 +00:00
|
|
|
@@ -291,13 +300,20 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
2017-06-08 12:15:29 +00:00
|
|
|
Module *Result = 0;
|
|
|
|
// FIXME: Maybe load bitcode file lazily? Then if we need to link, materialise the module
|
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
|
|
+ Expected<std::unique_ptr<Module> > resultErr =
|
|
|
|
+ parseBitcodeFile(buff.get(), composite->getContext());
|
|
|
|
+ ec = resultErr ? std::error_code() :
|
|
|
|
+ errorToErrorCode(resultErr.takeError());
|
|
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
|
|
ErrorOr<std::unique_ptr<Module> > resultErr =
|
|
|
|
+ parseBitcodeFile(buff.get(), composite->getContext());
|
|
|
|
+ ec = resultErr.getError();
|
|
|
|
#else
|
|
|
|
ErrorOr<Module *> resultErr =
|
|
|
|
-#endif
|
|
|
|
parseBitcodeFile(buff.get(), composite->getContext());
|
|
|
|
ec = resultErr.getError();
|
|
|
|
+#endif
|
|
|
|
if (ec)
|
|
|
|
errorMessage = ec.message();
|
|
|
|
else
|
2017-11-17 17:18:06 +00:00
|
|
|
@@ -474,7 +490,12 @@ Module *klee::linkWithLibrary(Module *module,
|
2017-06-08 12:15:29 +00:00
|
|
|
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 8)
|
|
|
|
Module *Result = 0;
|
|
|
|
#endif
|
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
|
|
+ Expected<std::unique_ptr<Module> > ResultErr =
|
|
|
|
+ parseBitcodeFile(Buffer, Context);
|
|
|
|
+ if (!ResultErr) {
|
|
|
|
+ ErrorMessage = errorToErrorCode(ResultErr.takeError()).message();
|
|
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
|
|
|
|
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
|
|
|
|
ErrorOr<std::unique_ptr<Module> > ResultErr =
|
|
|
|
#else
|
2017-11-17 17:18:06 +00:00
|
|
|
@@ -680,14 +701,22 @@ Module *klee::loadModule(LLVMContext &ctx, const std::string &path, std::string
|
2017-08-17 12:28:29 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-06-08 12:15:29 +00:00
|
|
|
|
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
|
|
+ std::error_code ec;
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
2017-08-17 12:28:29 +00:00
|
|
|
+ Expected<std::unique_ptr<Module>> errorOrModule =
|
|
|
|
+ getOwningLazyBitcodeModule(std::move(buffer.get()), ctx);
|
|
|
|
+ ec = errorOrModule ? std::error_code() :
|
|
|
|
+ errorToErrorCode(errorOrModule.takeError());
|
2017-06-08 12:15:29 +00:00
|
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
2017-08-17 12:28:29 +00:00
|
|
|
auto errorOrModule = getLazyBitcodeModule(std::move(buffer.get()), ctx);
|
|
|
|
+ ec = errorOrModule.getError();
|
2017-06-08 12:15:29 +00:00
|
|
|
#else
|
2017-08-17 12:28:29 +00:00
|
|
|
auto errorOrModule = getLazyBitcodeModule(buffer->get(), ctx);
|
|
|
|
+ ec = errorOrModule.getError();
|
2017-06-08 12:15:29 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-17 12:28:29 +00:00
|
|
|
- if (!errorOrModule) {
|
|
|
|
- errorMsg = errorOrModule.getError().message().c_str();
|
2017-06-08 12:15:29 +00:00
|
|
|
+ if (ec) {
|
2017-08-17 12:28:29 +00:00
|
|
|
+ errorMsg = ec.message();
|
|
|
|
return nullptr;
|
2017-06-08 12:15:29 +00:00
|
|
|
}
|
2017-08-17 12:28:29 +00:00
|
|
|
// The module has taken ownership of the MemoryBuffer so release it
|
2017-11-17 17:18:06 +00:00
|
|
|
@@ -699,7 +728,10 @@ Module *klee::loadModule(LLVMContext &ctx, const std::string &path, std::string
|
2017-08-17 12:28:29 +00:00
|
|
|
auto module = *errorOrModule;
|
2017-06-08 12:15:29 +00:00
|
|
|
#endif
|
2017-08-17 12:28:29 +00:00
|
|
|
|
2017-06-08 12:15:29 +00:00
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
2017-08-17 12:28:29 +00:00
|
|
|
+ if (llvm::Error err = module->materializeAll()) {
|
2017-06-08 12:15:29 +00:00
|
|
|
+ std::error_code ec = errorToErrorCode(std::move(err));
|
|
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
2017-08-17 12:28:29 +00:00
|
|
|
if (auto ec = module->materializeAll()) {
|
2017-06-08 12:15:29 +00:00
|
|
|
#else
|
2017-08-17 12:28:29 +00:00
|
|
|
if (auto ec = module->materializeAllPermanently()) {
|
2017-06-08 12:15:29 +00:00
|
|
|
--
|
2017-11-17 17:18:06 +00:00
|
|
|
2.15.0
|
2017-06-08 12:15:29 +00:00
|
|
|
|