OBS-URL: https://build.opensuse.org/package/show/devel:tools:statica/klee?expand=0&rev=24
135 lines
5.4 KiB
Diff
135 lines
5.4 KiB
Diff
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>
|
|
---
|
|
lib/Module/ModuleUtil.cpp | 31 ++++++++++++++++++++++++++-----
|
|
tools/klee/main.cpp | 19 +++++++++++++++----
|
|
2 files changed, 41 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
|
|
index 6bdea479ee06..a807ff79e95e 100644
|
|
--- a/lib/Module/ModuleUtil.cpp
|
|
+++ b/lib/Module/ModuleUtil.cpp
|
|
@@ -219,7 +219,7 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
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)
|
|
@@ -244,8 +244,14 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
#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
|
|
@@ -279,7 +285,10 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
#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)
|
|
@@ -303,13 +312,20 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
|
|
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
|
|
@@ -488,7 +504,12 @@ Module *klee::linkWithLibrary(Module *module,
|
|
#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
|
|
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
|
|
index eccc79776bb5..098f9308d130 100644
|
|
--- a/tools/klee/main.cpp
|
|
+++ b/tools/klee/main.cpp
|
|
@@ -1278,15 +1278,23 @@ int main(int argc, char **argv, char **envp) {
|
|
klee_error("error loading program '%s': %s", InputFile.c_str(),
|
|
Buffer.getError().message().c_str());
|
|
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
+ std::error_code ec;
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ Expected<std::unique_ptr<Module>> mainModuleOrError =
|
|
+ getOwningLazyBitcodeModule(std::move(Buffer.get()), ctx);
|
|
+ ec = mainModuleOrError ? std::error_code() :
|
|
+ errorToErrorCode(mainModuleOrError.takeError());
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
|
|
auto mainModuleOrError = getLazyBitcodeModule(std::move(Buffer.get()), ctx);
|
|
+ ec = mainModuleOrError.getError();
|
|
#else
|
|
auto mainModuleOrError = getLazyBitcodeModule(Buffer->get(), ctx);
|
|
+ ec = mainModuleOrError.getError();
|
|
#endif
|
|
|
|
- if (!mainModuleOrError) {
|
|
+ if (ec) {
|
|
klee_error("error loading program '%s': %s", InputFile.c_str(),
|
|
- mainModuleOrError.getError().message().c_str());
|
|
+ ec.message().c_str());
|
|
}
|
|
else {
|
|
// The module has taken ownership of the MemoryBuffer so release it
|
|
@@ -1298,7 +1306,10 @@ int main(int argc, char **argv, char **envp) {
|
|
#else
|
|
mainModule = *mainModuleOrError;
|
|
#endif
|
|
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ if (llvm::Error err = mainModule->materializeAll()) {
|
|
+ std::error_code ec = errorToErrorCode(std::move(err));
|
|
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
|
|
if (auto ec = mainModule->materializeAll()) {
|
|
#else
|
|
if (auto ec = mainModule->materializeAllPermanently()) {
|
|
--
|
|
2.13.1
|
|
|