Accepting request 502372 from devel:tools:statica

- Build against LLVM 4
- Update to version 1.3.0+20170607:
  * Fix test failure on systems with libstdc++ corresponding to gcc7.
  * llvm: rename ExitOnError to OptExitOnError
  * Prevent test failure when realloc fails in test/Feature/Realloc.c
- added patches:
    0001-llvm-don-t-use-clEnumValEnd-for-LLVM-4.0.patch
    0002-llvm-get-rid-of-static_casts-from-iterators.patch
    0003-Core-TimingSolver-use-WallTimer.patch
    0004-llvm-make-KLEE-compile-against-LLVM-3.7.patch
    0005-llvm-make-KLEE-compile-against-LLVM-3.8.patch
    0006-llvm-make-KLEE-compile-against-LLVM-3.9.patch
    0007-test-add-versions-of-some-tests-for-LLVM-3.8.patch
    0008-travis-CI-add-LLVM-3.8-build-tests.patch
    0009-llvm40-handle-different-header-names.patch
    0010-llvm-APFloat-members-are-functions-in-LLVM-4.0.patch
    0011-llvm40-errorOr-and-similar.patch
    0012-llvm-use-chrono-helpers-from-LLVM-4.0.patch
    0013-llvm-PointerType-is-not-SequentialType-in-LLVM-4.patch
- removed patches (renamed to the above):
    0001-test-add-versions-of-some-tests-for-LLVM-3.8.patch
    0002-Make-KLEE-compile-against-LLVM-3.7.patch
    0003-Make-KLEE-compile-against-LLVM-3.8.patch

- Update to version 1.3.0+20170602:
  * use METASMT_REQUIRE_RTTI flag to decide whether we need RTTI
  * [travis] add environment variable METASMT_BOOST_VERSION to control the boost version used by metaSMT and test it with the combination LLVM-2.9 + metaSMT
  * [CMake] change WARNING to FATAL_ERROR when building with a non-RTTI LLVM version and a metaSMT version that requires RTTI
  * [TravisCI] Try to unbreak the build against upstream STP.
  * Remove redundant KLEE prefix while logging

OBS-URL: https://build.opensuse.org/request/show/502372
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/klee?expand=0&rev=3
This commit is contained in:
Dominique Leuenberger 2017-06-12 13:32:07 +00:00 committed by Git OBS Bridge
commit 14b43f5ef3
22 changed files with 3184 additions and 751 deletions

View File

@ -1,638 +0,0 @@
From: =?UTF-8?q?Richard=20Trembeck=C3=BD?= <richardt@centrum.sk>
Date: Sun, 1 May 2016 16:38:21 +0200
Subject: llvm: make KLEE compile against LLVM 3.5 and 3.6
Patch-mainline: no
Based on work by @ccadeptic23 and @delcypher.
Formatting fixed by @snf.
Fix compiler warning by @martijnthe.
Further fixes by @mchalupa.
Refactored, so that changes can be reviewed -- no massive changes in
whitespace and in the surrounding code.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Core/Executor.cpp | 25 +++++++-
lib/Core/ExternalDispatcher.cpp | 18 ++++++
lib/Core/ExternalDispatcher.h | 6 ++
lib/Core/StatsTracker.cpp | 11 ++--
lib/Module/KModule.cpp | 13 ++++-
lib/Module/ModuleUtil.cpp | 117 +++++++++++++++++++++++++++++++++-----
lib/Module/Optimize.cpp | 14 +++--
lib/Module/RaiseAsm.cpp | 13 ++++-
lib/Solver/QueryLoggingSolver.cpp | 8 ++-
lib/Support/CompressionStream.cpp | 10 +++-
test/lit.cfg | 2 +-
tools/klee/Makefile | 10 +++-
tools/klee/main.cpp | 16 +++++-
13 files changed, 227 insertions(+), 36 deletions(-)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 95812dd72587..4148ca22caf3 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -81,6 +81,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
@@ -383,7 +384,13 @@ Executor::Executor(LLVMContext &ctx, const InterpreterOptions &opts,
if (!DebugCompressInstructions) {
#endif
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ std::error_code ec;
+ debugInstFile = new llvm::raw_fd_ostream(debug_file_name.c_str(), ec,
+ llvm::sys::fs::OpenFlags::F_Text);
+ if (ec)
+ ErrorInfo = ec.message();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
debugInstFile = new llvm::raw_fd_ostream(debug_file_name.c_str(), ErrorInfo,
llvm::sys::fs::OpenFlags::F_Text);
#else
@@ -1479,9 +1486,13 @@ Function* Executor::getTargetFunction(Value *calledVal, ExecutionState &state) {
while (true) {
if (GlobalValue *gv = dyn_cast<GlobalValue>(c)) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ if (!Visited.insert(gv).second)
+ return 0;
+#else
if (!Visited.insert(gv))
return 0;
-
+#endif
std::string alias = state.getFnAlias(gv->getName());
if (alias != "") {
llvm::Module* currModule = kmodule->module;
@@ -3080,8 +3091,16 @@ void Executor::callExternalFunction(ExecutionState &state,
else
klee_warning_once(function, "%s", os.str().c_str());
}
-
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ // MCJIT needs unique module, so we create quick external dispatcher for call.
+ // reference:
+ // http://blog.llvm.org/2013/07/using-mcjit-with-kaleidoscope-tutorial.html
+ ExternalDispatcher *e = new ExternalDispatcher(function->getContext());
+ bool success = e->executeCall(function, target->inst, args);
+ delete e;
+#else
bool success = externalDispatcher->executeCall(function, target->inst, args);
+#endif
if (!success) {
terminateStateOnError(state, "failed external call: " + function->getName(),
External);
diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp
index 984e3ab2e4a4..9701d35add85 100644
--- a/lib/Core/ExternalDispatcher.cpp
+++ b/lib/Core/ExternalDispatcher.cpp
@@ -23,7 +23,12 @@
#include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
#endif
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+#include "llvm/ExecutionEngine/MCJIT.h"
+#else
#include "llvm/ExecutionEngine/JIT.h"
+#endif
+
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
@@ -89,7 +94,12 @@ ExternalDispatcher::ExternalDispatcher(LLVMContext &ctx) {
dispatchModule = new Module("ExternalDispatcher", ctx);
std::string error;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ dispatchModule_uniptr.reset(dispatchModule);
+ executionEngine = EngineBuilder(std::move(dispatchModule_uniptr)).create();
+#else
executionEngine = ExecutionEngine::createJIT(dispatchModule, &error);
+#endif
if (!executionEngine) {
llvm::errs() << "unable to make jit: " << error << "\n";
abort();
@@ -98,6 +108,10 @@ ExternalDispatcher::ExternalDispatcher(LLVMContext &ctx) {
// If we have a native target, initialize it to ensure it is linked in and
// usable by the JIT.
llvm::InitializeNativeTarget();
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ llvm::InitializeNativeTargetAsmParser();
+ llvm::InitializeNativeTargetAsmPrinter();
+#endif
// from ExecutionEngine::create
if (executionEngine) {
@@ -146,7 +160,11 @@ bool ExternalDispatcher::executeCall(Function *f, Instruction *i, uint64_t *args
// ensures that any errors or assertions in the compilation process will
// trigger crashes instead of being caught as aborts in the external
// function.
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ executionEngine->finalizeObject();
+#else
executionEngine->recompileAndRelinkFunction(dispatcher);
+#endif
}
} else {
dispatcher = it->second;
diff --git a/lib/Core/ExternalDispatcher.h b/lib/Core/ExternalDispatcher.h
index 94363bab5ffc..d869eb6fe0ca 100644
--- a/lib/Core/ExternalDispatcher.h
+++ b/lib/Core/ExternalDispatcher.h
@@ -10,7 +10,10 @@
#ifndef KLEE_EXTERNALDISPATCHER_H
#define KLEE_EXTERNALDISPATCHER_H
+#include "klee/Config/Version.h"
+
#include <map>
+#include <memory>
#include <string>
#include <stdint.h>
@@ -28,6 +31,9 @@ namespace klee {
private:
typedef std::map<const llvm::Instruction*,llvm::Function*> dispatchers_ty;
dispatchers_ty dispatchers;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ std::unique_ptr<llvm::Module> dispatchModule_uniptr;
+#endif
llvm::Module *dispatchModule;
llvm::ExecutionEngine *executionEngine;
std::map<std::string, void*> preboundFunctions;
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index e8192a8ed754..b93796ecdff7 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -206,13 +206,16 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename,
if (!sys::path::is_absolute(objectFilename)) {
SmallString<128> current(objectFilename);
if(sys::fs::make_absolute(current)) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ Twine current_twine(current.str()); // requires a twine for this
+ if (!sys::fs::exists(current_twine)) {
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ bool exists = false;
+ if (!sys::fs::exists(current.str(), exists)) {
+#else
bool exists = false;
-
-#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
error_code ec = sys::fs::exists(current.str(), exists);
if (ec == errc::success && exists) {
-#else
- if (!sys::fs::exists(current.str(), exists)) {
#endif
objectFilename = current.c_str();
}
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 08ec28efc1f6..45dc34bfec46 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -158,8 +158,14 @@ static Function *getStubFunctionForCtorList(Module *m,
if (arr) {
for (unsigned i=0; i<arr->getNumOperands(); i++) {
ConstantStruct *cs = cast<ConstantStruct>(arr->getOperand(i));
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ // There is a third *optional* element in global_ctor elements (``i8
+ // @data``).
+ assert((cs->getNumOperands() == 2 || cs->getNumOperands() == 3) &&
+ "unexpected element in ctor initializer list");
+#else
assert(cs->getNumOperands()==2 && "unexpected element in ctor initializer list");
-
+#endif
Constant *fp = cs->getOperand(1);
if (!fp->isNullValue()) {
if (llvm::ConstantExpr *ce = dyn_cast<llvm::ConstantExpr>(fp))
@@ -513,8 +519,13 @@ static int getOperandNum(Value *v,
return registerMap[inst];
} else if (Argument *a = dyn_cast<Argument>(v)) {
return a->getArgNo();
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ // Metadata is no longer a Value
+ } else if (isa<BasicBlock>(v) || isa<InlineAsm>(v)) {
+#else
} else if (isa<BasicBlock>(v) || isa<InlineAsm>(v) ||
isa<MDNode>(v)) {
+#endif
return -1;
} else {
assert(isa<Constant>(v));
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index 83dc5045e711..c7f1c6d9d4a7 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -212,15 +212,27 @@ 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, 5)
+ for (object::Archive::child_iterator AI = archive->child_begin(),
+ AE = archive->child_end(); AI != AE; ++AI)
+#else
for (object::Archive::child_iterator AI = archive->begin_children(),
AE = archive->end_children(); AI != AE; ++AI)
+#endif
{
StringRef memberName;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ ErrorOr<StringRef> memberNameErr = AI->getName();
+ std::error_code ec = memberNameErr.getError();
+ if (!ec) {
+ memberName = memberNameErr.get();
+#else
error_code ec = AI->getName(memberName);
if ( ec == errc::success )
{
+#endif
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loading archive member " << memberName << "\n");
}
else
@@ -229,17 +241,29 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
return false;
}
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ ErrorOr<std::unique_ptr<llvm::object::Binary> > child = AI->getAsBinary();
+ ec = child.getError();
+#else
OwningPtr<object::Binary> child;
ec = AI->getAsBinary(child);
- if (ec != object::object_error::success)
- {
+#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)
+ ErrorOr<MemoryBufferRef> buff = AI->getMemoryBufferRef();
+ ec = buff.getError();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ ErrorOr<std::unique_ptr<MemoryBuffer> > buffErr = AI->getMemoryBuffer();
+ std::unique_ptr<MemoryBuffer> buff = nullptr;
+ ec = buffErr.getError();
+ if (!ec)
+ buff = std::move(buffErr.get());
+#else
OwningPtr<MemoryBuffer> buff; // Once this is destroyed will Module still be valid??
- Module *Result = 0;
-
- if (error_code ec = AI->getMemoryBuffer(buff))
- {
+ ec = AI->getMemoryBuffer(buff);
+#endif
+ if (ec) {
SS << "Failed to get MemoryBuffer: " <<ec.message();
SS.flush();
return false;
@@ -247,10 +271,20 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
if (buff)
{
+ 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)
+ ErrorOr<Module *> resultErr = parseBitcodeFile(buff.get(),
+ composite->getContext());
+ ec = resultErr.getError();
+ if (ec)
+ errorMessage = ec.message();
+ else
+ Result = resultErr.get();
+#else
Result = ParseBitcodeFile(buff.get(), composite->getContext(),
&errorMessage);
-
+#endif
if(!Result)
{
SS << "Loading module failed : " << errorMessage << "\n";
@@ -317,8 +351,11 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Found " << GV->getName() <<
" in " << M->getModuleIdentifier() << "\n");
-
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ if (Linker::LinkModules(composite, M))
+#else
if (Linker::LinkModules(composite, M, Linker::DestroySource, &errorMessage))
+#endif
{
// Linking failed
SS << "Linking archive module with composite failed:" << errorMessage;
@@ -371,36 +408,86 @@ Module *klee::linkWithLibrary(Module *module,
libraryName.c_str());
}
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ ErrorOr<std::unique_ptr<MemoryBuffer> > bufferErr =
+ MemoryBuffer::getFile(libraryName);
+ std::error_code ec = bufferErr.getError();
+#else
OwningPtr<MemoryBuffer> Buffer;
- if (error_code ec = MemoryBuffer::getFile(libraryName,Buffer)) {
+ error_code ec = MemoryBuffer::getFile(libraryName,Buffer);
+#endif
+ if (ec) {
klee_error("Link with library %s failed: %s", libraryName.c_str(),
ec.message().c_str());
}
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ MemoryBufferRef Buffer = bufferErr.get()->getMemBufferRef();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ MemoryBuffer *Buffer = bufferErr->get();
+#endif
+
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ sys::fs::file_magic magic = sys::fs::identify_magic(Buffer.getBuffer());
+#else
sys::fs::file_magic magic = sys::fs::identify_magic(Buffer->getBuffer());
+#endif
LLVMContext &Context = module->getContext();
std::string ErrorMessage;
if (magic == sys::fs::file_magic::bitcode) {
Module *Result = 0;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ ErrorOr<Module *> ResultErr = parseBitcodeFile(Buffer, Context);
+ if ((ec = ResultErr.getError())) {
+ ErrorMessage = ec.message();
+#else
Result = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage);
+ if (!Result) {
+#endif
+ klee_error("Link with library %s failed: %s", libraryName.c_str(),
+ ErrorMessage.c_str());
+ }
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ Result = ResultErr.get();
+#endif
- if (!Result || Linker::LinkModules(module, Result, Linker::DestroySource,
- &ErrorMessage))
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ if (Linker::LinkModules(module, Result)) {
+ ErrorMessage = "linking error";
+#else
+ if (Linker::LinkModules(module, Result, Linker::DestroySource, &ErrorMessage)) {
+#endif
klee_error("Link with library %s failed: %s", libraryName.c_str(),
ErrorMessage.c_str());
+ }
delete Result;
} else if (magic == sys::fs::file_magic::archive) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ ErrorOr<std::unique_ptr<object::Binary> > arch =
+ object::createBinary(Buffer, &Context);
+ ec = arch.getError();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ ErrorOr<object::Binary *> arch =
+ object::createBinary(std::move(bufferErr.get()), &Context);
+ ec = arch.getError();
+#else
OwningPtr<object::Binary> arch;
- if (error_code ec = object::createBinary(Buffer.take(), arch))
+ ec = object::createBinary(Buffer.take(), arch);
+#endif
+ if (ec)
klee_error("Link with library %s failed: %s", libraryName.c_str(),
ec.message().c_str());
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ if (object::Archive *a = dyn_cast<object::Archive>(arch->get())) {
+#else
if (object::Archive *a = dyn_cast<object::Archive>(arch.get())) {
+#endif
// Handle in helper
if (!linkBCA(a, module, ErrorMessage))
klee_error("Link with library %s failed: %s", libraryName.c_str(),
@@ -411,7 +498,11 @@ Module *klee::linkWithLibrary(Module *module,
}
} else if (magic.is_object()) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ std::unique_ptr<object::Binary> obj;
+#else
OwningPtr<object::Binary> obj;
+#endif
if (obj.get()->isObject()) {
klee_warning("Link with library: Object file %s in archive %s found. "
"Currently not supported.",
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index 3d9c8cc17bf3..c0f3f34ca8e8 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -172,15 +172,17 @@ void Optimize(Module *M, const std::string &EntryPoint) {
if (VerifyEach)
Passes.add(createVerifierPass());
-#if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1)
- // Add an appropriate TargetData instance for this module...
- addPass(Passes, new TargetData(M));
-#elif LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
// Add an appropriate DataLayout instance for this module...
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ DataLayoutPass *dlpass = new DataLayoutPass();
+ dlpass->doInitialization(*M);
+ addPass(Passes, dlpass);
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ addPass(Passes, new DataLayoutPass(M));
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2)
addPass(Passes, new DataLayout(M));
#else
- // Add an appropriate DataLayout instance for this module...
- addPass(Passes, new DataLayoutPass(M));
+ addPass(Passes, new TargetData(M));
#endif
// DWD - Run the opt standard pass list as well.
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index af92b74b41b0..5fc54ef17743 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -24,6 +24,10 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Host.h"
#include "llvm/Target/TargetLowering.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
+#endif
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0)
#include "llvm/Target/TargetRegistry.h"
#else
@@ -99,15 +103,20 @@ bool RaiseAsmPass::runOnModule(Module &M) {
klee_warning("Warning: unable to select native target: %s", Err.c_str());
TLI = 0;
} else {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions());
+ TLI = TM->getSubtargetImpl()->getTargetLowering();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
TM = NativeTarget->createTargetMachine(HostTriple, "", "",
TargetOptions());
+ TLI = TM->getTargetLowering();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 0)
TM = NativeTarget->createTargetMachine(HostTriple, "", "");
+ TLI = TM->getTargetLowering();
#else
TM = NativeTarget->createTargetMachine(HostTriple, "");
-#endif
TLI = TM->getTargetLowering();
+#endif
triple = llvm::Triple(HostTriple);
}
diff --git a/lib/Solver/QueryLoggingSolver.cpp b/lib/Solver/QueryLoggingSolver.cpp
index a858a7d7ed87..cf4966cd4861 100644
--- a/lib/Solver/QueryLoggingSolver.cpp
+++ b/lib/Solver/QueryLoggingSolver.cpp
@@ -42,7 +42,13 @@ QueryLoggingSolver::QueryLoggingSolver(Solver *_solver, std::string path,
#ifdef HAVE_ZLIB_H
if (!CreateCompressedQueryLog) {
#endif
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ std::error_code ec;
+ os = new llvm::raw_fd_ostream(path.c_str(), ec,
+ llvm::sys::fs::OpenFlags::F_Text);
+ if (ec)
+ ErrorInfo = ec.message();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
os = new llvm::raw_fd_ostream(path.c_str(), ErrorInfo,
llvm::sys::fs::OpenFlags::F_Text);
#else
diff --git a/lib/Support/CompressionStream.cpp b/lib/Support/CompressionStream.cpp
index eb208edfa395..363038786f6b 100644
--- a/lib/Support/CompressionStream.cpp
+++ b/lib/Support/CompressionStream.cpp
@@ -10,9 +10,11 @@
#include "klee/Config/Version.h"
#ifdef HAVE_ZLIB_H
#include "klee/Internal/Support/CompressionStream.h"
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
+#if (LLVM_VERSION_CODE >= LLVM_VERSION(3, 3) \
+ && LLVM_VERSION_CODE <= LLVM_VERSION(3, 4))
#include "llvm/Support/system_error.h"
#else
+#include "llvm/Support/FileSystem.h"
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
@@ -27,9 +29,13 @@ compressed_fd_ostream::compressed_fd_ostream(const char *Filename,
ErrorInfo = "";
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
// Open file in binary mode
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+ std::error_code EC =
+ llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_None);
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
llvm::error_code EC =
llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_Binary);
-
+#endif
if (EC) {
ErrorInfo = EC.message();
FD = -1;
diff --git a/test/lit.cfg b/test/lit.cfg
index 31552882c55e..6ce6dc955847 100644
--- a/test/lit.cfg
+++ b/test/lit.cfg
@@ -130,7 +130,7 @@ if int(config.llvm_version_major) == 2:
# Add feature for the LLVM version in use, so it can be tested in REQUIRES and
# XFAIL checks. We also add "not-XXX" variants, for the same reason.
-known_llvm_versions = set(["2.9", "3.4", "3.5"])
+known_llvm_versions = set(["2.9", "3.4", "3.5", "3.6"])
current_llvm_version = "%s.%s" % (config.llvm_version_major,
config.llvm_version_minor)
config.available_features.add("llvm-" + current_llvm_version)
diff --git a/tools/klee/Makefile b/tools/klee/Makefile
index 8d50403fc1da..2930427c7bde 100644
--- a/tools/klee/Makefile
+++ b/tools/klee/Makefile
@@ -13,7 +13,13 @@ TOOLNAME = klee
include $(LEVEL)/Makefile.config
USEDLIBS = kleeCore.a kleeBasic.a kleeModule.a kleaverSolver.a kleaverExpr.a kleeSupport.a
-LINK_COMPONENTS = jit bitreader bitwriter ipo linker engine
+LINK_COMPONENTS = bitreader bitwriter ipo linker engine
+
+ifeq ($(shell python -c "print($(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR) >= 3.6)"), True)
+LINK_COMPONENTS += mcjit
+else
+LINK_COMPONENTS += jit
+endif
ifeq ($(shell python -c "print($(LLVM_VERSION_MAJOR).$(LLVM_VERSION_MINOR) >= 3.3)"), True)
LINK_COMPONENTS += irreader
@@ -36,4 +42,4 @@ endif
ifeq ($(HAVE_ZLIB),1)
LIBS += -lz
-endif
\ No newline at end of file
+endif
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index c65953d1399e..90d54e064dd3 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -385,7 +385,12 @@ llvm::raw_fd_ostream *KleeHandler::openOutputFile(const std::string &filename) {
llvm::raw_fd_ostream *f;
std::string Error;
std::string path = getOutputFilename(filename);
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3,5)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ std::error_code ec;
+ f = new llvm::raw_fd_ostream(path.c_str(), ec, llvm::sys::fs::F_None);
+ if (ec)
+ Error = ec.message();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
f = new llvm::raw_fd_ostream(path.c_str(), Error, llvm::sys::fs::F_None);
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3,4)
f = new llvm::raw_fd_ostream(path.c_str(), Error, llvm::sys::fs::F_Binary);
@@ -1038,9 +1043,14 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir)
SmallString<128> uclibcBCA(libDir);
llvm::sys::path::append(uclibcBCA, KLEE_UCLIBC_BCA_NAME);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+ Twine uclibcBCA_twine(uclibcBCA.c_str());
+ if (!llvm::sys::fs::exists(uclibcBCA_twine))
+#else
bool uclibcExists=false;
llvm::sys::fs::exists(uclibcBCA.c_str(), uclibcExists);
if (!uclibcExists)
+#endif
klee_error("Cannot find klee-uclibc : %s", uclibcBCA.c_str());
Function *f;
@@ -1265,7 +1275,11 @@ 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)
+ auto mainModuleOrError = getLazyBitcodeModule(std::move(Buffer.get()), ctx);
+#else
auto mainModuleOrError = getLazyBitcodeModule(Buffer->get(), ctx);
+#endif
if (!mainModuleOrError) {
klee_error("error loading program '%s': %s", InputFile.c_str(),
--
2.12.0

View File

@ -24,13 +24,10 @@ Define __errno_location as a weak symbol to return the actual int errno.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
runtime/POSIX/errno_location.c | 9 +++++++++
runtime/POSIX/errno_location.c | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 runtime/POSIX/errno_location.c
diff --git a/runtime/POSIX/errno_location.c b/runtime/POSIX/errno_location.c
new file mode 100644
index 000000000000..58a5dab631ae
--- /dev/null
+++ b/runtime/POSIX/errno_location.c
@@ -0,0 +1,9 @@
@ -43,6 +40,3 @@ index 000000000000..58a5dab631ae
+{
+ return &errno;
+}
--
2.12.0

View File

@ -0,0 +1,219 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 7 Jun 2017 13:32:53 +0200
Subject: llvm: don't use clEnumValEnd for LLVM 4.0
Patch-mainline: no
It became unnecessary when defining options and mainly undefined.
So introduce KLEE_LLVM_CL_VAL_END as suggested by @delcypher.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
include/klee/Config/Version.h | 6 ++++++
lib/Basic/CmdLineOptions.cpp | 18 +++++++++---------
lib/Core/Executor.cpp | 8 ++++----
lib/Core/UserSearcher.cpp | 4 ++--
lib/Expr/ExprSMTLIBPrinter.cpp | 8 ++++----
lib/Module/KModule.cpp | 4 ++--
tools/kleaver/main.cpp | 8 ++++----
tools/klee/main.cpp | 4 ++--
8 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/include/klee/Config/Version.h b/include/klee/Config/Version.h
index ea2af9615f98..c1fdbb97d53d 100644
--- a/include/klee/Config/Version.h
+++ b/include/klee/Config/Version.h
@@ -21,4 +21,10 @@
# define LLVM_TYPE_Q const
#endif
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+# define KLEE_LLVM_CL_VAL_END
+#else
+# define KLEE_LLVM_CL_VAL_END , clEnumValEnd
+#endif
+
#endif
diff --git a/lib/Basic/CmdLineOptions.cpp b/lib/Basic/CmdLineOptions.cpp
index 82cb01b20f73..54087c216438 100644
--- a/lib/Basic/CmdLineOptions.cpp
+++ b/lib/Basic/CmdLineOptions.cpp
@@ -13,6 +13,7 @@
*/
#include "klee/CommandLine.h"
+#include "klee/Config/Version.h"
namespace klee {
@@ -76,9 +77,8 @@ llvm::cl::list<QueryLoggingSolverType> queryLoggingOptions(
clEnumValN(ALL_KQUERY,"all:kquery","All queries in .kquery (KQuery) format"),
clEnumValN(ALL_SMTLIB,"all:smt2","All queries in .smt2 (SMT-LIBv2) format"),
clEnumValN(SOLVER_KQUERY,"solver:kquery","All queries reaching the solver in .kquery (KQuery) format"),
- clEnumValN(SOLVER_SMTLIB,"solver:smt2","All queries reaching the solver in .smt2 (SMT-LIBv2) format"),
- clEnumValEnd
- ),
+ clEnumValN(SOLVER_SMTLIB,"solver:smt2","All queries reaching the solver in .smt2 (SMT-LIBv2) format")
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::CommaSeparated
);
@@ -106,8 +106,8 @@ llvm::cl::opt<klee::MetaSMTBackendType> MetaSMTBackend(
clEnumValN(METASMT_BACKEND_STP, "stp", "Use metaSMT with STP"),
clEnumValN(METASMT_BACKEND_Z3, "z3", "Use metaSMT with Z3"),
clEnumValN(METASMT_BACKEND_BOOLECTOR, "btor",
- "Use metaSMT with Boolector"),
- clEnumValEnd),
+ "Use metaSMT with Boolector")
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::init(METASMT_DEFAULT_BACKEND));
#undef METASMT_DEFAULT_BACKEND
@@ -140,8 +140,8 @@ llvm::cl::opt<CoreSolverType> CoreSolverToUse(
llvm::cl::values(clEnumValN(STP_SOLVER, "stp", "stp" STP_IS_DEFAULT_STR),
clEnumValN(METASMT_SOLVER, "metasmt", "metaSMT" METASMT_IS_DEFAULT_STR),
clEnumValN(DUMMY_SOLVER, "dummy", "Dummy solver"),
- clEnumValN(Z3_SOLVER, "z3", "Z3" Z3_IS_DEFAULT_STR),
- clEnumValEnd),
+ clEnumValN(Z3_SOLVER, "z3", "Z3" Z3_IS_DEFAULT_STR)
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::init(DEFAULT_CORE_SOLVER));
llvm::cl::opt<CoreSolverType> DebugCrossCheckCoreSolverWith(
@@ -153,8 +153,8 @@ llvm::cl::opt<CoreSolverType> DebugCrossCheckCoreSolverWith(
clEnumValN(DUMMY_SOLVER, "dummy", "Dummy solver"),
clEnumValN(Z3_SOLVER, "z3", "Z3"),
clEnumValN(NO_SOLVER, "none",
- "Do not cross check (default)"),
- clEnumValEnd),
+ "Do not cross check (default)")
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::init(NO_SOLVER));
}
#undef STP_IS_DEFAULT_STR
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index d71d767d7e04..49e326f7e64c 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -156,8 +156,8 @@ namespace {
"inst_id]"),
clEnumValN(FILE_COMPACT, "compact:file",
"Log all instructions to file instructions.txt in format "
- "[inst_id]"),
- clEnumValEnd),
+ "[inst_id]")
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::CommaSeparated);
#ifdef HAVE_ZLIB_H
cl::opt<bool> DebugCompressInstructions(
@@ -288,8 +288,8 @@ namespace {
clEnumValN(Executor::ReadOnly, "ReadOnly", "Write to read-only memory"),
clEnumValN(Executor::ReportError, "ReportError", "klee_report_error called"),
clEnumValN(Executor::User, "User", "Wrong klee_* functions invocation"),
- clEnumValN(Executor::Unhandled, "Unhandled", "Unhandled instruction hit"),
- clEnumValEnd),
+ clEnumValN(Executor::Unhandled, "Unhandled", "Unhandled instruction hit")
+ KLEE_LLVM_CL_VAL_END),
cl::ZeroOrMore);
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0)
diff --git a/lib/Core/UserSearcher.cpp b/lib/Core/UserSearcher.cpp
index 725836e8bb75..2bbbe74785a3 100644
--- a/lib/Core/UserSearcher.cpp
+++ b/lib/Core/UserSearcher.cpp
@@ -30,8 +30,8 @@ namespace {
clEnumValN(Searcher::NURS_Depth, "nurs:depth", "use NURS with 2^depth"),
clEnumValN(Searcher::NURS_ICnt, "nurs:icnt", "use NURS with Instr-Count"),
clEnumValN(Searcher::NURS_CPICnt, "nurs:cpicnt", "use NURS with CallPath-Instr-Count"),
- clEnumValN(Searcher::NURS_QC, "nurs:qc", "use NURS with Query-Cost"),
- clEnumValEnd));
+ clEnumValN(Searcher::NURS_QC, "nurs:qc", "use NURS with Query-Cost")
+ KLEE_LLVM_CL_VAL_END));
cl::opt<bool>
UseIterativeDeepeningTimeSearch("use-iterative-deepening-time-search",
diff --git a/lib/Expr/ExprSMTLIBPrinter.cpp b/lib/Expr/ExprSMTLIBPrinter.cpp
index e8e9a253181c..192e3461caf9 100644
--- a/lib/Expr/ExprSMTLIBPrinter.cpp
+++ b/lib/Expr/ExprSMTLIBPrinter.cpp
@@ -25,8 +25,8 @@ argConstantDisplayMode(
clEnumValN(klee::ExprSMTLIBPrinter::HEX, "hex",
"Use Hexadecimal form (e.g. #x2D)"),
clEnumValN(klee::ExprSMTLIBPrinter::DECIMAL, "dec",
- "Use decimal form (e.g. (_ bv45 8) )"),
- clEnumValEnd),
+ "Use decimal form (e.g. (_ bv45 8) )")
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::init(klee::ExprSMTLIBPrinter::DECIMAL));
llvm::cl::opt<bool> humanReadableSMTLIB(
@@ -44,8 +44,8 @@ llvm::cl::opt<klee::ExprSMTLIBPrinter::AbbreviationMode> abbreviationMode(
clEnumValN(klee::ExprSMTLIBPrinter::ABBR_LET, "let",
"Abbreviate with let"),
clEnumValN(klee::ExprSMTLIBPrinter::ABBR_NAMED, "named",
- "Abbreviate with :named annotations"),
- clEnumValEnd),
+ "Abbreviate with :named annotations")
+ KLEE_LLVM_CL_VAL_END),
llvm::cl::init(klee::ExprSMTLIBPrinter::ABBR_LET));
}
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 45dc34bfec46..6438707ab346 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -92,8 +92,8 @@ namespace {
clEnumValN(eSwitchTypeLLVM, "llvm",
"lower using LLVM"),
clEnumValN(eSwitchTypeInternal, "internal",
- "execute switch internally"),
- clEnumValEnd),
+ "execute switch internally")
+ KLEE_LLVM_CL_VAL_END),
cl::init(eSwitchTypeInternal));
cl::opt<bool>
diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp
index 3fde0abf16bf..b8b32e31264a 100644
--- a/tools/kleaver/main.cpp
+++ b/tools/kleaver/main.cpp
@@ -68,8 +68,8 @@ namespace {
clEnumValN(PrintAST, "print-ast",
"Print parsed AST nodes from the input file."),
clEnumValN(Evaluate, "evaluate",
- "Print parsed AST nodes from the input file."),
- clEnumValEnd));
+ "Print parsed AST nodes from the input file.")
+ KLEE_LLVM_CL_VAL_END));
enum BuilderKinds {
@@ -88,8 +88,8 @@ namespace {
clEnumValN(ConstantFoldingBuilder, "constant-folding",
"Fold constant expressions."),
clEnumValN(SimplifyingBuilder, "simplify",
- "Fold constants and simplify expressions."),
- clEnumValEnd));
+ "Fold constants and simplify expressions.")
+ KLEE_LLVM_CL_VAL_END));
llvm::cl::opt<std::string> directoryToWriteQueryLogs("query-log-dir",llvm::cl::desc("The folder to write query logs to. Defaults is current working directory."),
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index b74789fa1bea..94798dad3181 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -145,8 +145,8 @@ namespace {
cl::desc("Choose libc version (none by default)."),
cl::values(clEnumValN(NoLibc, "none", "Don't link in a libc"),
clEnumValN(KleeLibc, "klee", "Link in klee libc"),
- clEnumValN(UcLibc, "uclibc", "Link in uclibc (adapted for klee)"),
- clEnumValEnd),
+ clEnumValN(UcLibc, "uclibc", "Link in uclibc (adapted for klee)")
+ KLEE_LLVM_CL_VAL_END),
cl::init(NoLibc));
--
2.13.1

View File

@ -0,0 +1,330 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 7 Jun 2017 14:30:54 +0200
Subject: llvm: get rid of static_casts from iterators
Patch-mainline: no
In commit b7a6aec4eeb4 (convert iterators using static_cast), I switched
all implicit casts to static_cast. It turned out that llvm 4.0 banned
casting via static_cast. See e.g. 1e2bc42eb988 in the llvm repo what
they do.
So similarly to the above commit, change all the casts of iterators to
"&*" which is what they do in LLVM.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Core/Executor.cpp | 11 +++++------
lib/Core/StatsTracker.cpp | 21 ++++++++++-----------
lib/Module/Checks.cpp | 4 ++--
lib/Module/InstructionInfoTable.cpp | 4 ++--
lib/Module/KModule.cpp | 12 ++++++------
lib/Module/LowerSwitch.cpp | 2 +-
lib/Module/RaiseAsm.cpp | 2 +-
tools/klee/main.cpp | 12 ++++++------
8 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 49e326f7e64c..2c0fc0d1290c 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -546,7 +546,7 @@ void Executor::initializeGlobals(ExecutionState &state) {
// ensures that we won't conflict. we don't need to allocate a memory object
// since reading/writing via a function pointer is unsupported anyway.
for (Module::iterator i = m->begin(), ie = m->end(); i != ie; ++i) {
- Function *f = static_cast<Function *>(i);
+ Function *f = &*i;
ref<ConstantExpr> addr(0);
// If the symbol has external weak linkage then it is implicitly
@@ -600,7 +600,7 @@ void Executor::initializeGlobals(ExecutionState &state) {
for (Module::const_global_iterator i = m->global_begin(),
e = m->global_end();
i != e; ++i) {
- const GlobalVariable *v = static_cast<const GlobalVariable *>(i);
+ const GlobalVariable *v = &*i;
size_t globalObjectAlignment = getAllocationAlignment(v);
if (i->isDeclaration()) {
// FIXME: We have no general way of handling unknown external
@@ -678,8 +678,7 @@ void Executor::initializeGlobals(ExecutionState &state) {
i != ie; ++i) {
// Map the alias to its aliasee's address. This works because we have
// addresses for everything, even undefined functions.
- globalAddresses.insert(std::make_pair(static_cast<GlobalAlias *>(i),
- evalConstant(i->getAliasee())));
+ globalAddresses.insert(std::make_pair(&*i, evalConstant(i->getAliasee())));
}
// once all objects are allocated, do the actual initialization
@@ -687,7 +686,7 @@ void Executor::initializeGlobals(ExecutionState &state) {
e = m->global_end();
i != e; ++i) {
if (i->hasInitializer()) {
- const GlobalVariable *v = static_cast<const GlobalVariable *>(i);
+ const GlobalVariable *v = &*i;
MemoryObject *mo = globalObjects.find(v)->second;
const ObjectState *os = state.addressSpace.findObject(mo);
assert(os);
@@ -3554,7 +3553,7 @@ void Executor::runFunctionAsMain(Function *f,
if (ai!=ae) {
arguments.push_back(ConstantExpr::alloc(argc, Expr::Int32));
if (++ai!=ae) {
- Instruction *first = static_cast<Instruction *>(f->begin()->begin());
+ Instruction *first = &*f->begin()->begin();
argvMO =
memory->allocate((argc + 1 + envc + 1 + 1) * NumPtrBytes,
/*isLocal=*/false, /*isGlobal=*/true,
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index b93796ecdff7..86de9586bd3f 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -165,7 +165,7 @@ static bool instructionIsCoverable(Instruction *i) {
if (it==bb->begin()) {
return true;
} else {
- Instruction *prev = static_cast<Instruction *>(--it);
+ Instruction *prev = &*(--it);
if (isa<CallInst>(prev) || isa<InvokeInst>(prev)) {
Function *target =
getDirectCallTarget(CallSite(prev), /*moduleIsFullyLinked=*/true);
@@ -542,7 +542,7 @@ void StatsTracker::writeIStats() {
// Always try to write the filename before the function name, as otherwise
// KCachegrind can create two entries for the function, one with an
// unnamed file and one without.
- Function *fn = static_cast<Function *>(fnIt);
+ Function *fn = &*fnIt;
const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fn);
if (ii.file != sourceFile) {
of << "fl=" << ii.file << "\n";
@@ -639,9 +639,9 @@ static std::vector<Instruction*> getSuccs(Instruction *i) {
if (i==bb->getTerminator()) {
for (succ_iterator it = succ_begin(bb), ie = succ_end(bb); it != ie; ++it)
- res.push_back(static_cast<Instruction *>(it->begin()));
+ res.push_back(&*it->begin());
} else {
- res.push_back(static_cast<Instruction *>(++BasicBlock::iterator(i)));
+ res.push_back(&*(++BasicBlock::iterator(i)));
}
return res;
@@ -688,7 +688,7 @@ void StatsTracker::computeReachableUncovered() {
bbIt != bb_ie; ++bbIt) {
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
- Instruction *inst = static_cast<Instruction *>(it);
+ Instruction *inst = &*it;
if (isa<CallInst>(inst) || isa<InvokeInst>(inst)) {
CallSite cs(inst);
if (isa<InlineAsm>(cs.getCalledValue())) {
@@ -721,7 +721,7 @@ void StatsTracker::computeReachableUncovered() {
std::vector<Instruction *> instructions;
for (Module::iterator fnIt = m->begin(), fn_ie = m->end();
fnIt != fn_ie; ++fnIt) {
- Function *fn = static_cast<Function *>(fnIt);
+ Function *fn = &*fnIt;
if (fnIt->isDeclaration()) {
if (fnIt->doesNotReturn()) {
functionShortestPath[fn] = 0;
@@ -737,7 +737,7 @@ void StatsTracker::computeReachableUncovered() {
bbIt != bb_ie; ++bbIt) {
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
- Instruction *inst = static_cast<Instruction *>(it);
+ Instruction *inst = &*it;
instructions.push_back(inst);
unsigned id = infos.getInfo(inst).id;
sm.setIndexedValue(stats::minDistToReturn,
@@ -796,14 +796,13 @@ void StatsTracker::computeReachableUncovered() {
// functionShortestPath, or it will remain 0 (erroneously indicating
// that no return instructions are reachable)
Function *f = inst->getParent()->getParent();
- if (best != cur
- || (inst == static_cast<Instruction *>(f->begin()->begin())
+ if (best != cur || (inst == &*f->begin()->begin()
&& functionShortestPath[f] != best)) {
sm.setIndexedValue(stats::minDistToReturn, id, best);
changed = true;
// Update shortest path if this is the entry point.
- if (inst == static_cast<Instruction *>(f->begin()->begin()))
+ if (inst == &*f->begin()->begin())
functionShortestPath[f] = best;
}
}
@@ -820,7 +819,7 @@ void StatsTracker::computeReachableUncovered() {
bbIt != bb_ie; ++bbIt) {
for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
- Instruction *inst = static_cast<Instruction *>(it);
+ Instruction *inst = &*it;
unsigned id = infos.getInfo(inst).id;
instructions.push_back(inst);
sm.setIndexedValue(stats::minDistToUncovered,
diff --git a/lib/Module/Checks.cpp b/lib/Module/Checks.cpp
index 48a4eb940f8b..eb0f189b1fd1 100644
--- a/lib/Module/Checks.cpp
+++ b/lib/Module/Checks.cpp
@@ -71,7 +71,7 @@ bool DivCheckPass::runOnModule(Module &M) {
Type::getInt64Ty(ctx),
false, /* sign doesn't matter */
"int_cast_to_i64",
- static_cast<Instruction *>(i));
+ &*i);
// Lazily bind the function to avoid always importing it.
if (!divZeroCheckFunction) {
@@ -129,7 +129,7 @@ bool OvershiftCheckPass::runOnModule(Module &M) {
Type::getInt64Ty(ctx),
false, /* sign doesn't matter */
"int_cast_to_i64",
- static_cast<Instruction *>(i));
+ &*i);
args.push_back(shift);
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index adf054423f13..8e58c19b0bb2 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -120,7 +120,7 @@ InstructionInfoTable::InstructionInfoTable(Module *m)
for (Module::iterator fnIt = m->begin(), fn_ie = m->end();
fnIt != fn_ie; ++fnIt) {
- Function *fn = static_cast<Function *>(fnIt);
+ Function *fn = &*fnIt;
// We want to ensure that as all instructions have source information, if
// available. Clang sometimes will not write out debug information on the
@@ -193,6 +193,6 @@ InstructionInfoTable::getFunctionInfo(const Function *f) const {
// and construct a test case for it if it does, though.
return dummyInfo;
} else {
- return getInfo(static_cast<const Instruction *>(f->begin()->begin()));
+ return getInfo(&*f->begin()->begin());
}
}
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 6438707ab346..bb74a71579c0 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -196,7 +196,7 @@ static void injectStaticConstructorsAndDestructors(Module *m) {
if (ctors)
CallInst::Create(getStubFunctionForCtorList(m, ctors, "klee.ctor_stub"),
- "", static_cast<Instruction *>(mainFn->begin()->begin()));
+ "", &*mainFn->begin()->begin());
if (dtors) {
Function *dtorStub = getStubFunctionForCtorList(m, dtors, "klee.dtor_stub");
for (Function::iterator it = mainFn->begin(), ie = mainFn->end();
@@ -286,7 +286,7 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
llvm::errs() << "KLEE: adding klee_merge at exit of: " << name << "\n";
for (llvm::Function::iterator bbit = f->begin(), bbie = f->end();
bbit != bbie; ++bbit) {
- BasicBlock *bb = static_cast<BasicBlock *>(bbit);
+ BasicBlock *bb = &*bbit;
if (bb != exit) {
Instruction *i = bbit->getTerminator();
if (i->getOpcode()==Instruction::Ret) {
@@ -451,7 +451,7 @@ void KModule::prepare(const Interpreter::ModuleOptions &opts,
if (it->isDeclaration())
continue;
- Function *fn = static_cast<Function *>(it);
+ Function *fn = &*it;
KFunction *kf = new KFunction(fn, this);
for (unsigned i=0; i<kf->numInstructions; ++i) {
@@ -542,7 +542,7 @@ KFunction::KFunction(llvm::Function *_function,
trackCoverage(true) {
for (llvm::Function::iterator bbit = function->begin(),
bbie = function->end(); bbit != bbie; ++bbit) {
- BasicBlock *bb = static_cast<BasicBlock *>(bbit);
+ BasicBlock *bb = &*bbit;
basicBlockEntry[bb] = numInstructions;
numInstructions += bb->size();
}
@@ -557,7 +557,7 @@ KFunction::KFunction(llvm::Function *_function,
bbie = function->end(); bbit != bbie; ++bbit) {
for (llvm::BasicBlock::iterator it = bbit->begin(), ie = bbit->end();
it != ie; ++it)
- registerMap[static_cast<Instruction *>(it)] = rnum++;
+ registerMap[&*it] = rnum++;
}
numRegisters = rnum;
@@ -577,7 +577,7 @@ KFunction::KFunction(llvm::Function *_function,
ki = new KInstruction(); break;
}
- Instruction *inst = static_cast<Instruction *>(it);
+ Instruction *inst = &*it;
ki->inst = inst;
ki->dest = registerMap[inst];
diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp
index 5cc6b991c6d1..b20c21ab34e4 100644
--- a/lib/Module/LowerSwitch.cpp
+++ b/lib/Module/LowerSwitch.cpp
@@ -44,7 +44,7 @@ bool LowerSwitchPass::runOnFunction(Function &F) {
bool changed = false;
for (Function::iterator I = F.begin(), E = F.end(); I != E; ) {
- BasicBlock *cur = static_cast<BasicBlock *>(I);
+ BasicBlock *cur = &*I;
I++; // Advance over block so we don't traverse new blocks
if (SwitchInst *SI = dyn_cast<SwitchInst>(cur->getTerminator())) {
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index 5fc54ef17743..113dcc621ae2 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -124,7 +124,7 @@ bool RaiseAsmPass::runOnModule(Module &M) {
for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) {
for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) {
for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) {
- Instruction *i = static_cast<Instruction *>(ii);
+ Instruction *i = &*ii;
++ii;
changed |= runOnInstruction(M, i);
}
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 94798dad3181..e5b8fa6c1b96 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -670,10 +670,10 @@ static int initEnv(Module *mainModule) {
klee_error("Cannot handle ""--posix-runtime"" when main() has less than two arguments.\n");
}
- Instruction *firstInst = static_cast<Instruction *>(mainFn->begin()->begin());
+ Instruction *firstInst = &*mainFn->begin()->begin();
- Value *oldArgc = static_cast<Argument *>(mainFn->arg_begin());
- Value *oldArgv = static_cast<Argument *>(++mainFn->arg_begin());
+ Value *oldArgc = &*mainFn->arg_begin();
+ Value *oldArgv = &*(++mainFn->arg_begin());
AllocaInst* argcPtr =
new AllocaInst(oldArgc->getType(), "argcPtr", firstInst);
@@ -1080,7 +1080,7 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir)
// naming conflict.
for (Module::iterator fi = mainModule->begin(), fe = mainModule->end();
fi != fe; ++fi) {
- Function *f = static_cast<Function *>(fi);
+ Function *f = &*fi;
const std::string &name = f->getName();
if (name[0]=='\01') {
unsigned size = name.size();
@@ -1139,8 +1139,8 @@ static llvm::Module *linkWithUclibc(llvm::Module *mainModule, StringRef libDir)
std::vector<llvm::Value*> args;
args.push_back(llvm::ConstantExpr::getBitCast(userMainFn,
ft->getParamType(0)));
- args.push_back(static_cast<Argument *>(stub->arg_begin())); // argc
- args.push_back(static_cast<Argument *>(++stub->arg_begin())); // argv
+ args.push_back(&*stub->arg_begin()); // argc
+ args.push_back(&*(++stub->arg_begin())); // argv
args.push_back(Constant::getNullValue(ft->getParamType(3))); // app_init
args.push_back(Constant::getNullValue(ft->getParamType(4))); // app_fini
args.push_back(Constant::getNullValue(ft->getParamType(5))); // rtld_fini
--
2.13.1

View File

@ -0,0 +1,141 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 7 Jun 2017 16:50:27 +0200
Subject: Core: TimingSolver, use WallTimer
Patch-mainline: no
Do not opencode what we already have in WallTimer. This simplifies the
code a lot and makes transition to LLVM 4.0 a lot easier.
We also introduce a helper to update the times.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Core/TimingSolver.cpp | 38 +++++++++++++++-----------------------
lib/Core/TimingSolver.h | 3 +++
2 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/lib/Core/TimingSolver.cpp b/lib/Core/TimingSolver.cpp
index b70bcbefcddc..77451111b676 100644
--- a/lib/Core/TimingSolver.cpp
+++ b/lib/Core/TimingSolver.cpp
@@ -13,17 +13,21 @@
#include "klee/ExecutionState.h"
#include "klee/Solver.h"
#include "klee/Statistics.h"
-#include "klee/Internal/System/Time.h"
+#include "klee/Internal/Support/Timer.h"
#include "CoreStats.h"
-#include "llvm/Support/TimeValue.h"
-
using namespace klee;
using namespace llvm;
/***/
+void TimingSolver::updateTimes(const ExecutionState& state, uint64_t usec)
+{
+ stats::solverTime += usec;
+ state.queryCost += usec / 1e6;
+}
+
bool TimingSolver::evaluate(const ExecutionState& state, ref<Expr> expr,
Solver::Validity &result) {
// Fast path, to avoid timer and OS overhead.
@@ -32,17 +36,14 @@ bool TimingSolver::evaluate(const ExecutionState& state, ref<Expr> expr,
return true;
}
- sys::TimeValue now = util::getWallTimeVal();
+ WallTimer timer;
if (simplifyExprs)
expr = state.constraints.simplifyExpr(expr);
bool success = solver->evaluate(Query(state.constraints, expr), result);
- sys::TimeValue delta = util::getWallTimeVal();
- delta -= now;
- stats::solverTime += delta.usec();
- state.queryCost += delta.usec()/1000000.;
+ updateTimes(state, timer.check());
return success;
}
@@ -55,17 +56,14 @@ bool TimingSolver::mustBeTrue(const ExecutionState& state, ref<Expr> expr,
return true;
}
- sys::TimeValue now = util::getWallTimeVal();
+ WallTimer timer;
if (simplifyExprs)
expr = state.constraints.simplifyExpr(expr);
bool success = solver->mustBeTrue(Query(state.constraints, expr), result);
- sys::TimeValue delta = util::getWallTimeVal();
- delta -= now;
- stats::solverTime += delta.usec();
- state.queryCost += delta.usec()/1000000.;
+ updateTimes(state, timer.check());
return success;
}
@@ -101,17 +99,14 @@ bool TimingSolver::getValue(const ExecutionState& state, ref<Expr> expr,
return true;
}
- sys::TimeValue now = util::getWallTimeVal();
+ WallTimer timer;
if (simplifyExprs)
expr = state.constraints.simplifyExpr(expr);
bool success = solver->getValue(Query(state.constraints, expr), result);
- sys::TimeValue delta = util::getWallTimeVal();
- delta -= now;
- stats::solverTime += delta.usec();
- state.queryCost += delta.usec()/1000000.;
+ updateTimes(state, timer.check());
return success;
}
@@ -125,16 +120,13 @@ TimingSolver::getInitialValues(const ExecutionState& state,
if (objects.empty())
return true;
- sys::TimeValue now = util::getWallTimeVal();
+ WallTimer timer;
bool success = solver->getInitialValues(Query(state.constraints,
ConstantExpr::alloc(0, Expr::Bool)),
objects, result);
- sys::TimeValue delta = util::getWallTimeVal();
- delta -= now;
- stats::solverTime += delta.usec();
- state.queryCost += delta.usec()/1000000.;
+ updateTimes(state, timer.check());
return success;
}
diff --git a/lib/Core/TimingSolver.h b/lib/Core/TimingSolver.h
index c98dd881b841..c1c229b08fc0 100644
--- a/lib/Core/TimingSolver.h
+++ b/lib/Core/TimingSolver.h
@@ -26,6 +26,9 @@ namespace klee {
Solver *solver;
bool simplifyExprs;
+ private:
+ void updateTimes(const ExecutionState& state, uint64_t usec);
+
public:
/// TimingSolver - Construct a new timing solver.
///
--
2.13.1

View File

@ -6,7 +6,7 @@ Patch-mainline: no
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
include/klee/Internal/Support/FloatEvaluation.h | 7 +++++++
lib/Core/ExternalDispatcher.cpp | 4 ++++
lib/Core/ExternalDispatcher.cpp | 3 +++
lib/Module/InstructionInfoTable.cpp | 8 +++++++-
lib/Module/IntrinsicCleaner.cpp | 14 ++++++++++++++
lib/Module/KModule.cpp | 13 ++++++++++++-
@ -14,7 +14,7 @@ Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
lib/Module/Optimize.cpp | 21 +++++++++++++++++++--
lib/Module/RaiseAsm.cpp | 5 ++++-
tools/klee/main.cpp | 6 +++++-
9 files changed, 91 insertions(+), 9 deletions(-)
9 files changed, 90 insertions(+), 9 deletions(-)
diff --git a/include/klee/Internal/Support/FloatEvaluation.h b/include/klee/Internal/Support/FloatEvaluation.h
index 6d9092f2ea37..436e0dc8152f 100644
@ -37,23 +37,21 @@ index 6d9092f2ea37..436e0dc8152f 100644
}
}
diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp
index 9701d35add85..d49373f84e64 100644
index df0dd9a9a12f..380c97e62db8 100644
--- a/lib/Core/ExternalDispatcher.cpp
+++ b/lib/Core/ExternalDispatcher.cpp
@@ -257,7 +257,11 @@ Function *ExternalDispatcher::createDispatcher(Function *target, Instruction *in
LLVM_TYPE_Q Type *argTy = (i < FTy->getNumParams() ? FTy->getParamType(i) :
(*ai)->getType());
Instruction *argI64p =
@@ -331,6 +331,9 @@ Function *ExternalDispatcherImpl::createDispatcher(Function *target,
LLVM_TYPE_Q Type *argTy =
(i < FTy->getNumParams() ? FTy->getParamType(i) : (*ai)->getType());
Instruction *argI64p = GetElementPtrInst::Create(
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+ GetElementPtrInst::Create(nullptr, argI64s,
+#else
GetElementPtrInst::Create(argI64s,
+ nullptr,
+#endif
ConstantInt::get(Type::getInt32Ty(ctx), idx),
"", dBB);
argI64s, ConstantInt::get(Type::getInt32Ty(ctx), idx), "", dBB);
Instruction *argp =
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index adf054423f13..625c4a297ead 100644
index 8e58c19b0bb2..44addc762daa 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -87,7 +87,7 @@ static void buildInstructionToLineMap(Module *m,
@ -112,7 +110,7 @@ index 3f7644af3d37..9af6f9f40f21 100644
}
ii->removeFromParent();
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 45dc34bfec46..4fac18739aba 100644
index bb74a71579c0..b31b7fd5a56d 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -46,8 +46,11 @@
@ -269,7 +267,7 @@ index c0f3f34ca8e8..68acd2b17dda 100644
dlpass->doInitialization(*M);
addPass(Passes, dlpass);
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index 5fc54ef17743..29576ad10e9e 100644
index 113dcc621ae2..668ce4853cca 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -103,7 +103,10 @@ bool RaiseAsmPass::runOnModule(Module &M) {
@ -285,10 +283,10 @@ index 5fc54ef17743..29576ad10e9e 100644
TLI = TM->getSubtargetImpl()->getTargetLowering();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 90d54e064dd3..20b1e33a6617 100644
index e5b8fa6c1b96..dd78d5410e28 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -46,6 +46,7 @@
@@ -47,6 +47,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
@ -296,7 +294,7 @@ index 90d54e064dd3..20b1e33a6617 100644
#include "llvm/Support/raw_ostream.h"
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0)
@@ -1290,8 +1291,11 @@ int main(int argc, char **argv, char **envp) {
@@ -1278,8 +1279,11 @@ int main(int argc, char **argv, char **envp) {
// from the std::unique_ptr
Buffer->release();
}
@ -310,5 +308,5 @@ index 90d54e064dd3..20b1e33a6617 100644
klee_error("error loading program '%s': %s", InputFile.c_str(),
ec.message().c_str());
--
2.12.0
2.13.1

View File

@ -15,10 +15,10 @@ Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
7 files changed, 78 insertions(+), 11 deletions(-)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 4148ca22caf3..794346e0950d 100644
index 2c0fc0d1290c..70354edc37ea 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -2301,8 +2301,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
@@ -2300,8 +2300,13 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
return terminateStateOnExecError(state, "Unsupported FRem operation");
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
llvm::APFloat Res(*fpWidthToSemantics(left->getWidth()), left->getAPValue());
@ -33,17 +33,17 @@ index 4148ca22caf3..794346e0950d 100644
llvm::APFloat Res(left->getAPValue());
Res.mod(APFloat(right->getAPValue()), APFloat::rmNearestTiesToEven);
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index b93796ecdff7..fc4cb786e902 100644
index 86de9586bd3f..798318ae8992 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -641,7 +641,11 @@ static std::vector<Instruction*> getSuccs(Instruction *i) {
for (succ_iterator it = succ_begin(bb), ie = succ_end(bb); it != ie; ++it)
res.push_back(static_cast<Instruction *>(it->begin()));
res.push_back(&*it->begin());
} else {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
+ res.push_back(static_cast<Instruction *>(++(i->getIterator())));
+ res.push_back(&*(++(i->getIterator())));
+#else
res.push_back(static_cast<Instruction *>(++BasicBlock::iterator(i)));
res.push_back(&*(++BasicBlock::iterator(i)));
+#endif
}
@ -78,7 +78,7 @@ index 9af6f9f40f21..1e43463e6a5c 100644
Value *op2 = ii->getArgOperand(1);
diff --git a/lib/Module/LowerSwitch.cpp b/lib/Module/LowerSwitch.cpp
index 5cc6b991c6d1..4a5658912a0c 100644
index b20c21ab34e4..147b5acb6d25 100644
--- a/lib/Module/LowerSwitch.cpp
+++ b/lib/Module/LowerSwitch.cpp
@@ -68,7 +68,11 @@ void LowerSwitchPass::switchConvert(CaseItr begin, CaseItr end,
@ -235,10 +235,10 @@ index 68acd2b17dda..46ab7d028224 100644
addPass(Passes, createLICMPass()); // Hoist loop invariants
addPass(Passes, createGVNPass()); // Remove redundancies
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 20b1e33a6617..4acefbf8c4de 100644
index dd78d5410e28..78ea1a6eb569 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -310,7 +310,12 @@ KleeHandler::KleeHandler(int argc, char **argv)
@@ -311,7 +311,12 @@ KleeHandler::KleeHandler(int argc, char **argv)
for (; i <= INT_MAX; ++i) {
SmallString<128> d(directory);
llvm::sys::path::append(d, "klee-out-");
@ -252,7 +252,7 @@ index 20b1e33a6617..4acefbf8c4de 100644
// create directory and try to link klee-last
if (mkdir(d.c_str(), 0775) == 0) {
@@ -1296,7 +1301,11 @@ int main(int argc, char **argv, char **envp) {
@@ -1284,7 +1289,11 @@ int main(int argc, char **argv, char **envp) {
#else
mainModule = *mainModuleOrError;
#endif
@ -265,5 +265,5 @@ index 20b1e33a6617..4acefbf8c4de 100644
ec.message().c_str());
}
--
2.12.0
2.13.1

View File

@ -0,0 +1,295 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 22 Feb 2017 15:57:55 +0100
Subject: llvm: make KLEE compile against LLVM 3.9
Patch-mainline: no
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Core/Executor.cpp | 16 ++++++++++++++++
lib/Core/MemoryManager.cpp | 5 ++++-
lib/Module/ModuleUtil.cpp | 33 ++++++++++++++++++++++++++++++---
lib/Module/Optimize.cpp | 29 ++++++++++++++++++++++++++++-
lib/Module/RaiseAsm.cpp | 11 +++++++++--
tools/kleaver/main.cpp | 4 ++++
tools/klee/main.cpp | 4 ++++
7 files changed, 95 insertions(+), 7 deletions(-)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 70354edc37ea..841734573abc 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1399,10 +1399,18 @@ void Executor::executeCall(ExecutionState &state,
//
// Alignment requirements for scalar types is the same as their size
if (argWidth > Expr::Int64) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ size = llvm::alignTo(size, 16);
+#else
size = llvm::RoundUpToAlignment(size, 16);
+#endif
requires16ByteAlignment = true;
}
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ size += llvm::alignTo(argWidth, WordSize) / 8;
+#else
size += llvm::RoundUpToAlignment(argWidth, WordSize) / 8;
+#endif
}
}
@@ -1435,10 +1443,18 @@ void Executor::executeCall(ExecutionState &state,
Expr::Width argWidth = arguments[i]->getWidth();
if (argWidth > Expr::Int64) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ offset = llvm::alignTo(offset, 16);
+#else
offset = llvm::RoundUpToAlignment(offset, 16);
+#endif
}
os->write(offset, arguments[i]);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ offset += llvm::alignTo(argWidth, WordSize) / 8;
+#else
offset += llvm::RoundUpToAlignment(argWidth, WordSize) / 8;
+#endif
}
}
}
diff --git a/lib/Core/MemoryManager.cpp b/lib/Core/MemoryManager.cpp
index 24e2ed97581f..f40e8bc9deb8 100644
--- a/lib/Core/MemoryManager.cpp
+++ b/lib/Core/MemoryManager.cpp
@@ -111,9 +111,12 @@ MemoryObject *MemoryManager::allocate(uint64_t size, bool isLocal,
uint64_t address = 0;
if (DeterministicAllocation) {
-
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ address = llvm::alignTo((uint64_t)nextFreeSlot + alignment - 1, alignment);
+#else
address = llvm::RoundUpToAlignment((uint64_t)nextFreeSlot + alignment - 1,
alignment);
+#endif
// Handle the case of 0-sized allocations as 1-byte allocations.
// This way, we make sure we have this allocation between its own red zones
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index 6b50b037bc65..14d48b026d14 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -212,7 +212,11 @@ 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, 5)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ Error Err;
+ 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)
for (object::Archive::child_iterator AI = archive->child_begin(),
AE = archive->child_end(); AI != AE; ++AI)
#else
@@ -252,7 +256,14 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
return false;
}
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ Expected<std::unique_ptr<llvm::object::Binary> > child =
+ childErr->getAsBinary();
+ if (!child) {
+ ec = errorToErrorCode(child.takeError());
+ consumeError(child.takeError());
+ }
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
ErrorOr<std::unique_ptr<llvm::object::Binary> > child =
childErr->getAsBinary();
ec = child.getError();
@@ -335,6 +346,13 @@ static bool linkBCA(object::Archive* archive, Module* composite, std::string& er
}
}
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ if (Err) {
+ SS << "Cannot iterate over archive";
+ SS.flush();
+ return false;
+ }
+#endif
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "Loaded " << archiveModules.size() << " modules\n");
@@ -505,7 +523,12 @@ Module *klee::linkWithLibrary(Module *module,
#endif
} else if (magic == sys::fs::file_magic::archive) {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ Expected<std::unique_ptr<object::Binary> > arch =
+ object::createBinary(Buffer, &Context);
+ if (!arch)
+ ec = errorToErrorCode(arch.takeError());
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
ErrorOr<std::unique_ptr<object::Binary> > arch =
object::createBinary(Buffer, &Context);
ec = arch.getError();
@@ -575,7 +598,11 @@ Function *klee::getDirectCallTarget(CallSite cs, bool moduleIsFullyLinked) {
if (Function *f = dyn_cast<Function>(v)) {
return f;
} else if (llvm::GlobalAlias *ga = dyn_cast<GlobalAlias>(v)) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ if (moduleIsFullyLinked || !(ga->isInterposable())) {
+#else
if (moduleIsFullyLinked || !(ga->mayBeOverridden())) {
+#endif
v = ga->getAliasee();
} else {
v = NULL;
diff --git a/lib/Module/Optimize.cpp b/lib/Module/Optimize.cpp
index 46ab7d028224..745d89f70027 100644
--- a/lib/Module/Optimize.cpp
+++ b/lib/Module/Optimize.cpp
@@ -16,6 +16,9 @@
//===----------------------------------------------------------------------===//
#include "klee/Config/Version.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
+#endif
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
#include "llvm/IR/LegacyPassManager.h"
#else
@@ -47,6 +50,9 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Scalar.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+#include "llvm/Transforms/Scalar/GVN.h"
+#endif
#include "llvm/Support/PluginLoader.h"
using namespace llvm;
@@ -127,7 +133,11 @@ static void AddStandardCompilePasses(PassManager &PM) {
addPass(PM, createPruneEHPass()); // Remove dead EH info
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ addPass(PM, createPostOrderFunctionAttrsLegacyPass());
+#else
addPass(PM, createPostOrderFunctionAttrsPass());
+#endif
addPass(PM, createReversePostOrderFunctionAttrsPass());
#else
addPass(PM, createFunctionAttrsPass()); // Deduce function attrs
@@ -143,7 +153,11 @@ static void AddStandardCompilePasses(PassManager &PM) {
addPass(PM, createInstructionCombiningPass()); // Cleanup for scalarrepl.
addPass(PM, createJumpThreadingPass()); // Thread jumps.
addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ addPass(PM, createSROAPass()); // Break up aggregate allocas
+#else
addPass(PM, createScalarReplAggregatesPass()); // Break up aggregate allocas
+#endif
addPass(PM, createInstructionCombiningPass()); // Combine silly seq's
addPass(PM, createTailCallEliminationPass()); // Eliminate tail calls
@@ -215,7 +229,12 @@ void Optimize(Module *M, const std::string &EntryPoint) {
// for a main function. If main is defined, mark all other functions
// internal.
if (!DisableInternalize) {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 2)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ auto PreserveEP = [=](const GlobalValue &GV) {
+ return GV.getName().equals(EntryPoint);
+ };
+ ModulePass *pass = createInternalizePass(PreserveEP);
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 2)
ModulePass *pass = createInternalizePass(
std::vector<const char *>(1, EntryPoint.c_str()));
#else
@@ -259,11 +278,19 @@ void Optimize(Module *M, const std::string &EntryPoint) {
// The IPO passes may leave cruft around. Clean up after them.
addPass(Passes, createInstructionCombiningPass());
addPass(Passes, createJumpThreadingPass()); // Thread jumps.
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ addPass(Passes, createSROAPass()); // Break up allocas
+#else
addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas
+#endif
// Run a few AA driven optimizations here and now, to cleanup the code.
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ addPass(Passes, createPostOrderFunctionAttrsLegacyPass());
+#else
addPass(Passes, createPostOrderFunctionAttrsPass());
+#endif
addPass(Passes, createReversePostOrderFunctionAttrsPass());
// addPass(Passes, createGlobalsAAWrapperPass());
#else
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index 668ce4853cca..08e78748d30c 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -75,7 +75,10 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
triple.getOS() == llvm::Triple::Darwin)) {
if (ia->getAsmString() == "" && ia->hasSideEffects()) {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ IRBuilder<> Builder(I);
+ Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent);
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
IRBuilder<> Builder(I);
Builder.CreateFence(llvm::SequentiallyConsistent);
#endif
@@ -103,7 +106,11 @@ bool RaiseAsmPass::runOnModule(Module &M) {
klee_warning("Warning: unable to select native target: %s", Err.c_str());
TLI = 0;
} else {
-#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions(),
+ None);
+ TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering();
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 7)
TM = NativeTarget->createTargetMachine(HostTriple, "", "", TargetOptions());
TLI = TM->getSubtargetImpl(*(M.begin()))->getTargetLowering();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
diff --git a/tools/kleaver/main.cpp b/tools/kleaver/main.cpp
index b8b32e31264a..800cece95e9c 100644
--- a/tools/kleaver/main.cpp
+++ b/tools/kleaver/main.cpp
@@ -400,7 +400,11 @@ static bool printInputAsSMTLIBv2(const char *Filename,
int main(int argc, char **argv) {
bool success = true;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+#else
llvm::sys::PrintStackTraceOnErrorSignal();
+#endif
llvm::cl::SetVersionPrinter(klee::printVersion);
llvm::cl::ParseCommandLineOptions(argc, argv);
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index 78ea1a6eb569..eac69ada30e0 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -1170,7 +1170,11 @@ int main(int argc, char **argv, char **envp) {
llvm::InitializeNativeTarget();
parseArguments(argc, argv);
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 9)
+ sys::PrintStackTraceOnErrorSignal(argv[0]);
+#else
sys::PrintStackTraceOnErrorSignal();
+#endif
if (Watchdog) {
if (MaxTime==0) {
--
2.13.1

View File

@ -56,21 +56,21 @@ Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
create mode 100644 test/regression/2007-08-16-invalid-constant-value.llvm38.c
diff --git a/test/Concrete/BoolReadWrite.ll b/test/Concrete/BoolReadWrite.ll
index f818ecafacd5..eb618d2726b7 100644
index f818ecafacd5..f2d76227c545 100644
--- a/test/Concrete/BoolReadWrite.ll
+++ b/test/Concrete/BoolReadWrite.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
declare void @print_i1(i1)
diff --git a/test/Concrete/BoolReadWrite.llvm38.ll b/test/Concrete/BoolReadWrite.llvm38.ll
new file mode 100644
index 000000000000..c68696d1a4c1
index 000000000000..d2c6c88aff32
--- /dev/null
+++ b/test/Concrete/BoolReadWrite.llvm38.ll
@@ -0,0 +1,16 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
+
+declare void @print_i1(i1)
@ -87,21 +87,21 @@ index 000000000000..c68696d1a4c1
+ ret i32 0
+}
diff --git a/test/Concrete/ConstantExpr.ll b/test/Concrete/ConstantExpr.ll
index d00c59a637e9..d5a97919634b 100644
index d00c59a637e9..84cf1ad0f517 100644
--- a/test/Concrete/ConstantExpr.ll
+++ b/test/Concrete/ConstantExpr.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
; Most of the test below use the *address* of gInt as part of their computation,
diff --git a/test/Concrete/ConstantExpr.llvm38.ll b/test/Concrete/ConstantExpr.llvm38.ll
new file mode 100644
index 000000000000..f02e59ffe49a
index 000000000000..dc9dce931ba8
--- /dev/null
+++ b/test/Concrete/ConstantExpr.llvm38.ll
@@ -0,0 +1,165 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
+
+; Most of the test below use the *address* of gInt as part of their computation,
@ -267,21 +267,21 @@ index 000000000000..f02e59ffe49a
+declare void @print_i32(i32)
+declare void @print_i64(i64)
diff --git a/test/Concrete/FloatingPointOps.ll b/test/Concrete/FloatingPointOps.ll
index 5dd6d2feb41e..20c99db798b1 100644
index 5dd6d2feb41e..12d8cd241d2f 100644
--- a/test/Concrete/FloatingPointOps.ll
+++ b/test/Concrete/FloatingPointOps.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
; casting error messages
diff --git a/test/Concrete/FloatingPointOps.llvm38.ll b/test/Concrete/FloatingPointOps.llvm38.ll
new file mode 100644
index 000000000000..44fa9f2a9ac1
index 000000000000..3dbbb49aef4b
--- /dev/null
+++ b/test/Concrete/FloatingPointOps.llvm38.ll
@@ -0,0 +1,680 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
+
+; casting error messages
@ -962,21 +962,21 @@ index 000000000000..44fa9f2a9ac1
+ ret i32 0
+}
diff --git a/test/Concrete/GlobalInitializers.ll b/test/Concrete/GlobalInitializers.ll
index e3657dad19e5..4399da750475 100755
index e3657dad19e5..b883ad40d940 100755
--- a/test/Concrete/GlobalInitializers.ll
+++ b/test/Concrete/GlobalInitializers.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
declare void @print_i32(i32)
diff --git a/test/Concrete/GlobalInitializers.llvm38.ll b/test/Concrete/GlobalInitializers.llvm38.ll
new file mode 100755
index 000000000000..604e999183f3
index 000000000000..98f5b6787f80
--- /dev/null
+++ b/test/Concrete/GlobalInitializers.llvm38.ll
@@ -0,0 +1,48 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
+
+declare void @print_i32(i32)
@ -1025,21 +1025,21 @@ index 000000000000..604e999183f3
+ ret i32 0
+}
diff --git a/test/Concrete/SimpleStoreAndLoad.ll b/test/Concrete/SimpleStoreAndLoad.ll
index 1edad0386916..1046c5d81bd3 100644
index 1edad0386916..6e8542f8f5fd 100644
--- a/test/Concrete/SimpleStoreAndLoad.ll
+++ b/test/Concrete/SimpleStoreAndLoad.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
declare void @print_i32(i32)
diff --git a/test/Concrete/SimpleStoreAndLoad.llvm38.ll b/test/Concrete/SimpleStoreAndLoad.llvm38.ll
new file mode 100644
index 000000000000..b8944ee9b939
index 000000000000..1a36c674c36d
--- /dev/null
+++ b/test/Concrete/SimpleStoreAndLoad.llvm38.ll
@@ -0,0 +1,20 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: %S/ConcreteTest.py --klee='%klee' --lli=%lli %s
+
+declare void @print_i32(i32)
@ -1060,21 +1060,21 @@ index 000000000000..b8944ee9b939
+ ret i32 0
+}
diff --git a/test/Feature/BitcastAlias.ll b/test/Feature/BitcastAlias.ll
index e0e3653feebc..0232903eb74a 100644
index e0e3653feebc..f29e739c9e75 100644
--- a/test/Feature/BitcastAlias.ll
+++ b/test/Feature/BitcastAlias.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
diff --git a/test/Feature/BitcastAlias.llvm38.ll b/test/Feature/BitcastAlias.llvm38.ll
new file mode 100644
index 000000000000..cecf68cc1f39
index 000000000000..ff7009b7711b
--- /dev/null
+++ b/test/Feature/BitcastAlias.llvm38.ll
@@ -0,0 +1,35 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
@ -1110,21 +1110,21 @@ index 000000000000..cecf68cc1f39
+ ret i32 0
+}
diff --git a/test/Feature/BitcastAliasMD2U.ll b/test/Feature/BitcastAliasMD2U.ll
index 24eabaa57c8c..ade6ba8a65db 100644
index 24eabaa57c8c..322012882f01 100644
--- a/test/Feature/BitcastAliasMD2U.ll
+++ b/test/Feature/BitcastAliasMD2U.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt -search=nurs:md2u %t1.bc > %t2
diff --git a/test/Feature/BitcastAliasMD2U.llvm38.ll b/test/Feature/BitcastAliasMD2U.llvm38.ll
new file mode 100644
index 000000000000..aa7c5dec500f
index 000000000000..f4e41293c347
--- /dev/null
+++ b/test/Feature/BitcastAliasMD2U.llvm38.ll
@@ -0,0 +1,35 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt -search=nurs:md2u %t1.bc > %t2
@ -1160,21 +1160,21 @@ index 000000000000..aa7c5dec500f
+ ret i32 0
+}
diff --git a/test/Feature/ConstantStruct.ll b/test/Feature/ConstantStruct.ll
index 4fe6b5d0e041..dfb304185d88 100644
index 4fe6b5d0e041..cb7ce2541bad 100644
--- a/test/Feature/ConstantStruct.ll
+++ b/test/Feature/ConstantStruct.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
diff --git a/test/Feature/ConstantStruct.llvm38.ll b/test/Feature/ConstantStruct.llvm38.ll
new file mode 100644
index 000000000000..2d468c13fae2
index 000000000000..b0e6ea835e1e
--- /dev/null
+++ b/test/Feature/ConstantStruct.llvm38.ll
@@ -0,0 +1,34 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
@ -1209,21 +1209,21 @@ index 000000000000..2d468c13fae2
+ ret i32 0
+}
diff --git a/test/Feature/GetElementPtr.ll b/test/Feature/GetElementPtr.ll
index da94441c685e..7a3b4cd53b7c 100644
index da94441c685e..cf3cc20d6dc2 100644
--- a/test/Feature/GetElementPtr.ll
+++ b/test/Feature/GetElementPtr.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
diff --git a/test/Feature/GetElementPtr.llvm38.ll b/test/Feature/GetElementPtr.llvm38.ll
new file mode 100644
index 000000000000..e063247918f3
index 000000000000..72c71f2b14d0
--- /dev/null
+++ b/test/Feature/GetElementPtr.llvm38.ll
@@ -0,0 +1,30 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
@ -1254,21 +1254,21 @@ index 000000000000..e063247918f3
+ ret i32 0
+}
diff --git a/test/Feature/InsertExtractValue.ll b/test/Feature/InsertExtractValue.ll
index 83e8f851ccea..55839bb18d28 100644
index 83e8f851ccea..a52222e2232a 100644
--- a/test/Feature/InsertExtractValue.ll
+++ b/test/Feature/InsertExtractValue.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
diff --git a/test/Feature/InsertExtractValue.llvm38.ll b/test/Feature/InsertExtractValue.llvm38.ll
new file mode 100644
index 000000000000..ca04c46745ae
index 000000000000..2b80b9385cb5
--- /dev/null
+++ b/test/Feature/InsertExtractValue.llvm38.ll
@@ -0,0 +1,34 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
@ -1303,21 +1303,21 @@ index 000000000000..ca04c46745ae
+ ret i32 0
+}
diff --git a/test/Feature/Overflow.ll b/test/Feature/Overflow.ll
index 35dfbd10fe02..9632e1e02d1c 100644
index 35dfbd10fe02..08ece1189a54 100644
--- a/test/Feature/Overflow.ll
+++ b/test/Feature/Overflow.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
diff --git a/test/Feature/Overflow.llvm38.ll b/test/Feature/Overflow.llvm38.ll
new file mode 100644
index 000000000000..f7fcf71b7f11
index 000000000000..c84aeb26bc23
--- /dev/null
+++ b/test/Feature/Overflow.llvm38.ll
@@ -0,0 +1,45 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
@ -1363,21 +1363,21 @@ index 000000000000..f7fcf71b7f11
+ ret i32 0
+}
diff --git a/test/Feature/OverflowMul.ll b/test/Feature/OverflowMul.ll
index 7026aa74bfbe..513cefd68277 100644
index 7026aa74bfbe..422672e37f51 100644
--- a/test/Feature/OverflowMul.ll
+++ b/test/Feature/OverflowMul.ll
@@ -1,3 +1,4 @@
+; REQUIRES: not-llvm-3.8
+; REQUIRES: lt-llvm-3.8
; RUN: llvm-as %s -f -o %t1.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
diff --git a/test/Feature/OverflowMul.llvm38.ll b/test/Feature/OverflowMul.llvm38.ll
new file mode 100644
index 000000000000..8ad119bd6893
index 000000000000..84f5242e9e92
--- /dev/null
+++ b/test/Feature/OverflowMul.llvm38.ll
@@ -0,0 +1,45 @@
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: llvm-as %s -f -o %t1.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee --output-dir=%t.klee-out -disable-opt %t1.bc > %t2
@ -1500,7 +1500,7 @@ index 000000000000..7114daabb6c2
+ ret i32 %res
+}
diff --git a/test/Intrinsics/objectsize.ll b/test/Intrinsics/objectsize.ll
index 8b75ce8feda5..255c7156017d 100644
index 8b75ce8feda5..08dd81460a6e 100644
--- a/test/Intrinsics/objectsize.ll
+++ b/test/Intrinsics/objectsize.ll
@@ -1,7 +1,7 @@
@ -1508,20 +1508,20 @@ index 8b75ce8feda5..255c7156017d 100644
; so this LLVM IR fails to verify for that version.
;
-; REQUIRES: not-llvm-2.9
+; REQUIRES: not-llvm-2.9, not-llvm-3.8
+; REQUIRES: not-llvm-2.9, lt-llvm-3.8
; RUN: %llvmas %s -o=%t.bc
; RUN: rm -rf %t.klee-out
; RUN: %klee -exit-on-error --output-dir=%t.klee-out -disable-opt %t.bc
diff --git a/test/Intrinsics/objectsize.llvm38.ll b/test/Intrinsics/objectsize.llvm38.ll
new file mode 100644
index 000000000000..af193daf0fd1
index 000000000000..d3f733ef6758
--- /dev/null
+++ b/test/Intrinsics/objectsize.llvm38.ll
@@ -0,0 +1,36 @@
+; Unfortunately LLVM 2.9 has a different suffix for the ``llvm.objectsize`` instrinsic
+; so this LLVM IR fails to verify for that version.
+;
+; REQUIRES: llvm-3.8
+; REQUIRES: geq-llvm-3.8
+; RUN: %llvmas %s -o=%t.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee -exit-on-error --output-dir=%t.klee-out -disable-opt %t.bc
@ -1555,10 +1555,10 @@ index 000000000000..af193daf0fd1
+
+declare void @abort() noreturn nounwind
diff --git a/test/lit.cfg b/test/lit.cfg
index 6ce6dc955847..90cd4aceb6f9 100644
index 9c557a78cc8f..6922cbce3313 100644
--- a/test/lit.cfg
+++ b/test/lit.cfg
@@ -130,7 +130,7 @@ if int(config.llvm_version_major) == 2:
@@ -158,7 +158,7 @@ if int(config.llvm_version_major) == 2:
# Add feature for the LLVM version in use, so it can be tested in REQUIRES and
# XFAIL checks. We also add "not-XXX" variants, for the same reason.
@ -1568,21 +1568,21 @@ index 6ce6dc955847..90cd4aceb6f9 100644
config.llvm_version_minor)
config.available_features.add("llvm-" + current_llvm_version)
diff --git a/test/regression/2007-08-16-invalid-constant-value.c b/test/regression/2007-08-16-invalid-constant-value.c
index e0b304f40b01..d65be6af4929 100644
index e0b304f40b01..2b428f643ec5 100644
--- a/test/regression/2007-08-16-invalid-constant-value.c
+++ b/test/regression/2007-08-16-invalid-constant-value.c
@@ -1,3 +1,4 @@
+// REQUIRES: not-llvm-3.8
+// REQUIRES: lt-llvm-3.8
// RUN: rm -f %t4.out %t4.err %t4.log
// RUN: %llvmgcc %s -emit-llvm -O2 -c -o %t1.bc
// RUN: llvm-as -f %p/../Feature/_utils._ll -o %t2.bc
diff --git a/test/regression/2007-08-16-invalid-constant-value.llvm38.c b/test/regression/2007-08-16-invalid-constant-value.llvm38.c
new file mode 100644
index 000000000000..907749e3cf83
index 000000000000..71daeac5b523
--- /dev/null
+++ b/test/regression/2007-08-16-invalid-constant-value.llvm38.c
@@ -0,0 +1,33 @@
+// REQUIRES: llvm-3.8
+// REQUIRES: geq-llvm-3.8
+// RUN: rm -f %t4.out %t4.err %t4.log
+// RUN: %llvmgcc %s -emit-llvm -O2 -c -o %t1.bc
+// RUN: llvm-as -f %p/../Feature/_utils.llvm38._ll -o %t2.bc
@ -1616,5 +1616,5 @@ index 000000000000..907749e3cf83
+ return 0;
+}
--
2.12.0
2.13.1

View File

@ -0,0 +1,57 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Thu, 23 Feb 2017 15:27:56 +0100
Subject: travis CI: add LLVM 3.8 build tests
Patch-mainline: no
3.9 does not seem to be in deb repos yet.
3.7 is not in debian repos either (already).
Legacy build system is not supported since 3.8.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
.travis.yml | 4 +++-
.travis/install-llvm-and-runtime-compiler.sh | 5 ++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 9a337952b17c..7c6b93c497ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,7 +20,7 @@ env:
###########################################################################
# Check a subset of the matrix of:
- # LLVM : {2.9, 3.4, 3.5, 3.6}
+ # LLVM : {2.9, 3.4, 3.5, 3.6, 3.8, 3.9}
# SOLVERS : {Z3, STP, STP:Z3, metaSMT}
# STP_VERSION : {2.1.2, master}
# METASMT_VERSION : {v4.rc1}
@@ -41,6 +41,8 @@ env:
# TODO: Add Doxygen build
# Check KLEE CMake build in a few configurations
+# This should be 3.9, but debian does not seem to have llvm 3.9 yet.
+ - LLVM_VERSION=3.8 SOLVERS=STP:Z3 STP_VERSION=2.1.2 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1 USE_CMAKE=1
- LLVM_VERSION=3.6 SOLVERS=STP:Z3 STP_VERSION=2.1.2 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1 USE_CMAKE=1
- LLVM_VERSION=3.5 SOLVERS=STP:Z3 STP_VERSION=2.1.2 KLEE_UCLIBC=klee_uclibc_v1.0.0 DISABLE_ASSERTIONS=0 ENABLE_OPTIMIZED=1 COVERAGE=0 USE_TCMALLOC=1 USE_CMAKE=1
diff --git a/.travis/install-llvm-and-runtime-compiler.sh b/.travis/install-llvm-and-runtime-compiler.sh
index 8e8e98633aac..c5993a7b2e84 100755
--- a/.travis/install-llvm-and-runtime-compiler.sh
+++ b/.travis/install-llvm-and-runtime-compiler.sh
@@ -5,7 +5,10 @@ if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
sudo apt-get install -y llvm-${LLVM_VERSION} llvm-${LLVM_VERSION}-dev
if [ "${LLVM_VERSION}" != "2.9" ]; then
- sudo apt-get install -y llvm-${LLVM_VERSION}-tools clang-${LLVM_VERSION}
+ sudo apt-get install -y clang-${LLVM_VERSION}
+ if [ "${LLVM_VERSION}" != "3.8" -a "${LLVM_VERSION}" != "3.9" ]; then
+ sudo apt-get install -y llvm-${LLVM_VERSION}-tools
+ fi
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} 20
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} 20
else
--
2.13.1

View File

@ -0,0 +1,84 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 7 Jun 2017 14:57:45 +0200
Subject: llvm40: handle different header names
Patch-mainline: no
LLVM 4.0 renamed and split some headers. Take this into account in
includes.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Module/KModule.cpp | 4 ++++
lib/Module/ModuleUtil.cpp | 6 ++++++
tools/klee/main.cpp | 7 ++++++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index b31b7fd5a56d..a47e0a43615a 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -21,7 +21,11 @@
#include "klee/Internal/Support/Debug.h"
#include "klee/Internal/Support/ModuleUtil.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+#include "llvm/Bitcode/BitcodeWriter.h"
+#else
#include "llvm/Bitcode/ReaderWriter.h"
+#endif
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
diff --git a/lib/Module/ModuleUtil.cpp b/lib/Module/ModuleUtil.cpp
index 14d48b026d14..6bdea479ee06 100644
--- a/lib/Module/ModuleUtil.cpp
+++ b/lib/Module/ModuleUtil.cpp
@@ -19,7 +19,11 @@
#endif
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 3)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+#include <llvm/Bitcode/BitcodeReader.h>
+#else
#include "llvm/Bitcode/ReaderWriter.h"
+#endif
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -31,7 +35,9 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/SourceMgr.h"
+#if LLVM_VERSION_CODE < LLVM_VERSION(4, 0)
#include "llvm/Support/DataStream.h"
+#endif
#else
#include "llvm/Function.h"
#include "llvm/Instructions.h"
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index eac69ada30e0..eccc79776bb5 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -43,13 +43,18 @@
#endif
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+#include <llvm/Bitcode/BitcodeReader.h>
+#else
+#include <llvm/Bitcode/ReaderWriter.h>
+#endif
+
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 0)
#include "llvm/Target/TargetSelect.h"
#else
--
2.13.1

View File

@ -0,0 +1,39 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 7 Jun 2017 14:54:32 +0200
Subject: llvm: APFloat members are functions in LLVM 4.0
Patch-mainline: no
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
lib/Core/Executor.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 841734573abc..4a0239dace49 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1542,12 +1542,21 @@ static bool isDebugIntrinsic(const Function *f, KModule *KM) {
static inline const llvm::fltSemantics * fpWidthToSemantics(unsigned width) {
switch(width) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ case Expr::Int32:
+ return &llvm::APFloat::IEEEsingle();
+ case Expr::Int64:
+ return &llvm::APFloat::IEEEdouble();
+ case Expr::Fl80:
+ return &llvm::APFloat::x87DoubleExtended();
+#else
case Expr::Int32:
return &llvm::APFloat::IEEEsingle;
case Expr::Int64:
return &llvm::APFloat::IEEEdouble;
case Expr::Fl80:
return &llvm::APFloat::x87DoubleExtended;
+#endif
default:
return 0;
}
--
2.13.1

View File

@ -0,0 +1,134 @@
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

View File

@ -0,0 +1,199 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Wed, 7 Jun 2017 13:36:28 +0200
Subject: llvm: use chrono helpers from LLVM 4.0
Patch-mainline: no
LLVM 4.0 removes the old time interface and starts using the C++11's
chrono. So swiych to that in klee for LLVM 4.0 too.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
include/klee/Internal/Support/Timer.h | 8 ++++++++
include/klee/Internal/System/Time.h | 11 +++++++++++
lib/Core/StatsTracker.cpp | 24 ++++++++++++++++++++++++
lib/Support/Time.cpp | 32 ++++++++++++++++++++++++++++++++
lib/Support/Timer.cpp | 16 ++++++++++++++++
5 files changed, 91 insertions(+)
diff --git a/include/klee/Internal/Support/Timer.h b/include/klee/Internal/Support/Timer.h
index a422abd027f3..d80ccb31f647 100644
--- a/include/klee/Internal/Support/Timer.h
+++ b/include/klee/Internal/Support/Timer.h
@@ -12,9 +12,17 @@
#include <stdint.h>
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+#include <llvm/Support/Chrono.h>
+#endif
+
namespace klee {
class WallTimer {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ llvm::sys::TimePoint<> start;
+#else
uint64_t startMicroseconds;
+#endif
public:
WallTimer();
diff --git a/include/klee/Internal/System/Time.h b/include/klee/Internal/System/Time.h
index 14d235364401..feeeed8affa2 100644
--- a/include/klee/Internal/System/Time.h
+++ b/include/klee/Internal/System/Time.h
@@ -10,7 +10,13 @@
#ifndef KLEE_UTIL_TIME_H
#define KLEE_UTIL_TIME_H
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+#include <chrono>
+
+#include <llvm/Support/Chrono.h>
+#else
#include <llvm/Support/TimeValue.h>
+#endif
namespace klee {
namespace util {
@@ -22,7 +28,12 @@ namespace klee {
double getWallTime();
/// Wall time as TimeValue object.
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ double durationToDouble(std::chrono::nanoseconds dur);
+ llvm::sys::TimePoint<> getWallTimeVal();
+#else
llvm::sys::TimeValue getWallTimeVal();
+#endif
}
}
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index 798318ae8992..abfc6bf823be 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -294,6 +294,29 @@ void StatsTracker::done() {
void StatsTracker::stepInstruction(ExecutionState &es) {
if (OutputIStats) {
if (TrackInstructionTime) {
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ static sys::TimePoint<> lastNowTime;
+ static std::chrono::nanoseconds lastUserTime(0);
+
+ if (lastUserTime.count() == 0) {
+ std::chrono::nanoseconds sys;
+ sys::Process::GetTimeUsage(lastNowTime, lastUserTime, sys);
+ } else {
+ sys::TimePoint<> now;
+ std::chrono::nanoseconds user, sys;
+
+ sys::Process::GetTimeUsage(now, user, sys);
+
+ std::chrono::microseconds delta =
+ std::chrono::duration_cast<std::chrono::microseconds>(user - lastUserTime);
+ std::chrono::microseconds deltaNow =
+ std::chrono::duration_cast<std::chrono::microseconds>(now - lastNowTime);
+ stats::instructionTime += delta.count();
+ stats::instructionRealTime += deltaNow.count();
+ lastUserTime = user;
+ lastNowTime = now;
+ }
+#else
static sys::TimeValue lastNowTime(0,0),lastUserTime(0,0);
if (lastUserTime.seconds()==0 && lastUserTime.nanoseconds()==0) {
@@ -309,6 +332,7 @@ void StatsTracker::stepInstruction(ExecutionState &es) {
lastUserTime = user;
lastNowTime = now;
}
+#endif
}
Instruction *inst = es.pc->inst;
diff --git a/lib/Support/Time.cpp b/lib/Support/Time.cpp
index be5eaf186958..c931c058ffd0 100644
--- a/lib/Support/Time.cpp
+++ b/lib/Support/Time.cpp
@@ -10,12 +10,43 @@
#include "klee/Config/Version.h"
#include "klee/Internal/System/Time.h"
+#include <chrono>
+
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+#include <llvm/Support/Chrono.h>
+#else
#include "llvm/Support/TimeValue.h"
+#endif
+
#include "llvm/Support/Process.h"
using namespace llvm;
using namespace klee;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+double util::durationToDouble(std::chrono::nanoseconds dur)
+{
+ return dur.count() / 1e9;
+}
+
+double util::getUserTime() {
+ sys::TimePoint<> now;
+ std::chrono::nanoseconds user, sys;
+
+ sys::Process::GetTimeUsage(now, user, sys);
+
+ return durationToDouble(user);
+}
+
+double util::getWallTime() {
+ return durationToDouble(getWallTimeVal().time_since_epoch());
+}
+
+sys::TimePoint<> util::getWallTimeVal() {
+ return std::chrono::system_clock::now();
+}
+
+#else
double util::getUserTime() {
sys::TimeValue now(0,0),user(0,0),sys(0,0);
sys::Process::GetTimeUsage(now,user,sys);
@@ -30,3 +61,4 @@ double util::getWallTime() {
sys::TimeValue util::getWallTimeVal() {
return sys::TimeValue::now();
}
+#endif
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index da96981079ae..a223b39ada57 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -15,6 +15,20 @@
using namespace klee;
using namespace llvm;
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+
+WallTimer::WallTimer() {
+ start = util::getWallTimeVal();
+}
+
+uint64_t WallTimer::check() {
+ sys::TimePoint<> now = util::getWallTimeVal();
+ return std::chrono::duration_cast<std::chrono::microseconds>(now -
+ start).count();
+}
+
+#else
+
WallTimer::WallTimer() {
startMicroseconds = util::getWallTimeVal().usec();
}
@@ -22,3 +36,5 @@ WallTimer::WallTimer() {
uint64_t WallTimer::check() {
return util::getWallTimeVal().usec() - startMicroseconds;
}
+
+#endif
--
2.13.1

View File

@ -0,0 +1,108 @@
From: Jiri Slaby <jirislaby@gmail.com>
Date: Thu, 8 Jun 2017 13:25:56 +0200
Subject: llvm: PointerType is not SequentialType in LLVM 4
Patch-mainline: no
So handle the type specially whenever needed.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
include/klee/util/GetElementPtrTypeIterator.h | 5 +++++
lib/Core/Executor.cpp | 22 +++++++++++++++++++---
lib/Core/ExecutorUtil.cpp | 17 ++++++++++++++---
3 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/include/klee/util/GetElementPtrTypeIterator.h b/include/klee/util/GetElementPtrTypeIterator.h
index 2d145cd67f14..b551d772eaac 100644
--- a/include/klee/util/GetElementPtrTypeIterator.h
+++ b/include/klee/util/GetElementPtrTypeIterator.h
@@ -93,6 +93,11 @@ namespace klee {
if (LLVM_TYPE_Q llvm::CompositeType *CT =
dyn_cast<llvm::CompositeType>(CurTy)) {
CurTy = CT->getTypeAtIndex(getOperand());
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ } else if (LLVM_TYPE_Q llvm::PointerType *ptr =
+ dyn_cast<llvm::PointerType>(CurTy)) {
+ CurTy = ptr->getElementType();
+#endif
} else {
CurTy = 0;
}
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 4a0239dace49..fd5cb5e4e751 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -2648,8 +2648,7 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue());
constantOffset = constantOffset->Add(ConstantExpr::alloc(addend,
Context::get().getPointerWidth()));
- } else {
- const SequentialType *set = cast<SequentialType>(*ii);
+ } else if (const SequentialType *set = dyn_cast<SequentialType>(*ii)) {
uint64_t elementSize =
kmodule->targetData->getTypeStoreSize(set->getElementType());
Value *operand = ii.getOperand();
@@ -2663,7 +2662,24 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) {
} else {
kgepi->indices.push_back(std::make_pair(index, elementSize));
}
- }
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ } else if (const PointerType *ptr = dyn_cast<PointerType>(*ii)) {
+ uint64_t elementSize =
+ kmodule->targetData->getTypeStoreSize(ptr->getElementType());
+ Value *operand = ii.getOperand();
+ if (Constant *c = dyn_cast<Constant>(operand)) {
+ ref<ConstantExpr> index =
+ evalConstant(c)->SExt(Context::get().getPointerWidth());
+ ref<ConstantExpr> addend =
+ index->Mul(ConstantExpr::alloc(elementSize,
+ Context::get().getPointerWidth()));
+ constantOffset = constantOffset->Add(addend);
+ } else {
+ kgepi->indices.push_back(std::make_pair(index, elementSize));
+ }
+#endif
+ } else
+ assert("invalid type" && 0);
index++;
}
kgepi->offset = constantOffset->getZExtValue();
diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp
index b91b5deec173..a63b891bf925 100644
--- a/lib/Core/ExecutorUtil.cpp
+++ b/lib/Core/ExecutorUtil.cpp
@@ -102,8 +102,7 @@ namespace klee {
addend = ConstantExpr::alloc(sl->getElementOffset((unsigned)
ci->getZExtValue()),
Context::get().getPointerWidth());
- } else {
- const SequentialType *set = cast<SequentialType>(*ii);
+ } else if (const SequentialType *set = dyn_cast<SequentialType>(*ii)) {
ref<ConstantExpr> index =
evalConstant(cast<Constant>(ii.getOperand()));
unsigned elementSize =
@@ -112,7 +111,19 @@ namespace klee {
index = index->ZExt(Context::get().getPointerWidth());
addend = index->Mul(ConstantExpr::alloc(elementSize,
Context::get().getPointerWidth()));
- }
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
+ } else if (const PointerType *ptr = dyn_cast<PointerType>(*ii)) {
+ ref<ConstantExpr> index =
+ evalConstant(cast<Constant>(ii.getOperand()));
+ unsigned elementSize =
+ kmodule->targetData->getTypeStoreSize(ptr->getElementType());
+
+ index = index->ZExt(Context::get().getPointerWidth());
+ addend = index->Mul(ConstantExpr::alloc(elementSize,
+ Context::get().getPointerWidth()));
+#endif
+ } else
+ assert("invalid type" && 0);
base = base->Add(addend);
}
--
2.13.1

1397
FileCheck.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
<servicedata>
<service name="tar_scm">
<param name="url">git://github.com/klee/klee.git</param>
<param name="changesrevision">28872c1a0cb8a8f6b835af67719b9cd9aba66d3f</param></service></servicedata>
<param name="changesrevision">1310855836fb7e931371647f4464801c277b0f7c</param></service></servicedata>

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3742053b828c281cddc02058e5f5e346d6fe5c990a9602e5a0ad8679c17010d9
size 648972

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f7f50ca108de38c50c00c988a83bdaef0ba90f50b31dc62d194dd783dcf59ff8
size 652804

View File

@ -1,3 +1,59 @@
-------------------------------------------------------------------
Thu Jun 08 08:48:58 UTC 2017 - jslaby@suse.com
- Build against LLVM 4
- Update to version 1.3.0+20170607:
* Fix test failure on systems with libstdc++ corresponding to gcc7.
* llvm: rename ExitOnError to OptExitOnError
* Prevent test failure when realloc fails in test/Feature/Realloc.c
- added patches:
0001-llvm-don-t-use-clEnumValEnd-for-LLVM-4.0.patch
0002-llvm-get-rid-of-static_casts-from-iterators.patch
0003-Core-TimingSolver-use-WallTimer.patch
0004-llvm-make-KLEE-compile-against-LLVM-3.7.patch
0005-llvm-make-KLEE-compile-against-LLVM-3.8.patch
0006-llvm-make-KLEE-compile-against-LLVM-3.9.patch
0007-test-add-versions-of-some-tests-for-LLVM-3.8.patch
0008-travis-CI-add-LLVM-3.8-build-tests.patch
0009-llvm40-handle-different-header-names.patch
0010-llvm-APFloat-members-are-functions-in-LLVM-4.0.patch
0011-llvm40-errorOr-and-similar.patch
0012-llvm-use-chrono-helpers-from-LLVM-4.0.patch
0013-llvm-PointerType-is-not-SequentialType-in-LLVM-4.patch
- removed patches (renamed to the above):
0001-test-add-versions-of-some-tests-for-LLVM-3.8.patch
0002-Make-KLEE-compile-against-LLVM-3.7.patch
0003-Make-KLEE-compile-against-LLVM-3.8.patch
-------------------------------------------------------------------
Mon Jun 05 07:45:51 UTC 2017 - jslaby@suse.com
- Update to version 1.3.0+20170602:
* use METASMT_REQUIRE_RTTI flag to decide whether we need RTTI
* [travis] add environment variable METASMT_BOOST_VERSION to control the boost version used by metaSMT and test it with the combination LLVM-2.9 + metaSMT
* [CMake] change WARNING to FATAL_ERROR when building with a non-RTTI LLVM version and a metaSMT version that requires RTTI
* [TravisCI] Try to unbreak the build against upstream STP.
* Remove redundant KLEE prefix while logging
* llvm: make KLEE compile against LLVM 3.5 and 3.6
* travis CI: add LLVM 3.5 and 3.6 tests
* Rearchitect ExternalDispatcher
* gitignore build
* [Z3] Support another solver failure reason that Z3 might give. I'm going to guess it means timeout but I'm not 100% sure about this.
* [Z3] Add assertions in Z3 builder to catch underflow with bad widths.
* [Z3] Move the `dump()` methods of the Z3NodeHandle<> specializations into `Z3Builder.cpp` so they can be called from in gdb.
* Refactor file opening code out of `main.cpp` and into `klee_open_output_file()` function so that it can be used by the Z3Solver.
* [Z3] Add the `-debug-z3-dump-queries=<path>` command line option. This is useful for getting access to the constraints being stored in the Z3 solver in the SMT-LIBv2.5 format.
* [Z3] Add option to manually validate Z3 models.
* [Z3] Implement API logging.
* [Z3] In `getConstraintLog()` use a separate builder from that of the solver. This is to avoid tampering with the cache of the builder the solver is using.
* [Z3] Switch from `Z3_mk_simple_solver()` to `Z3_mk_solver()`.
* [Z3] Add `-debug-z3-verbosity=<N>` option which behaves like Z3's `-v:<N>` option. This lets us see what Z3 is doing execution (e.g. which tactic is being applied) which is very useful for debugging.
* [Z3] Remove unused include.
* replace handleMetaSMT() with klee::createMetaSMTSolver() and move it into MetaSMTSolver.cpp so that the backend headers only need to be included once there
* hide backend solver declarations from public include
- remove 0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch
It is upstream already.
-------------------------------------------------------------------
Wed Apr 26 09:18:55 UTC 2017 - jslaby@suse.com

View File

@ -15,11 +15,11 @@
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
%define llvm_version_major 3
%define llvm_version_minor 8
%define llvm_version %{llvm_version_major}_%{llvm_version_minor}
%define llvm_version_major 4
%define llvm_version_minor 0
%define llvm_version %{llvm_version_major}
%define version_unconverted 1.3.0+20170409
%define version_unconverted 1.3.0+20170607
%ifarch %{ix86} x86_64
%define with_uclibc 1
@ -31,23 +31,34 @@ Name: klee
Summary: LLVM Execution Engine
License: NCSA
Group: Development/Languages/Other
Version: 1.3.0+20170409
Version: 1.3.0+20170607
Release: 0
Url: http://klee.github.io/
Source0: %{name}-%{version}.tar.xz
Source1: %{name}-rpmlintrc
Source2: https://raw.githubusercontent.com/llvm-mirror/llvm/release_%{llvm_version_major}%{llvm_version_minor}/utils/not/not.cpp
Patch0: 0001-Make-KLEE-compile-against-LLVM-3.5-and-3.6.patch
Patch1: 0002-Make-KLEE-compile-against-LLVM-3.7.patch
Patch2: 0003-Make-KLEE-compile-against-LLVM-3.8.patch
Patch3: 0001-test-add-versions-of-some-tests-for-LLVM-3.8.patch
Patch4: 0001-errno-define-__errno_location.patch
Patch5: 0001-test-DirSeek-make-it-XFAIL-temporarily.patch
Source3: https://raw.githubusercontent.com/llvm-mirror/llvm/release_%{llvm_version_major}%{llvm_version_minor}/utils/FileCheck/FileCheck.cpp
Patch0: 0001-errno-define-__errno_location.patch
Patch1: 0001-test-DirSeek-make-it-XFAIL-temporarily.patch
Patch2: 0001-llvm-don-t-use-clEnumValEnd-for-LLVM-4.0.patch
Patch3: 0002-llvm-get-rid-of-static_casts-from-iterators.patch
Patch4: 0003-Core-TimingSolver-use-WallTimer.patch
Patch5: 0004-llvm-make-KLEE-compile-against-LLVM-3.7.patch
Patch6: 0005-llvm-make-KLEE-compile-against-LLVM-3.8.patch
Patch7: 0006-llvm-make-KLEE-compile-against-LLVM-3.9.patch
Patch8: 0007-test-add-versions-of-some-tests-for-LLVM-3.8.patch
Patch9: 0008-travis-CI-add-LLVM-3.8-build-tests.patch
Patch10: 0009-llvm40-handle-different-header-names.patch
Patch11: 0010-llvm-APFloat-members-are-functions-in-LLVM-4.0.patch
Patch12: 0011-llvm40-errorOr-and-similar.patch
Patch13: 0012-llvm-use-chrono-helpers-from-LLVM-4.0.patch
Patch14: 0013-llvm-PointerType-is-not-SequentialType-in-LLVM-4.patch
BuildRequires: clang%{llvm_version}
BuildRequires: cmake
BuildRequires: gperftools-devel
%if %{with_uclibc}
BuildRequires: klee-uclibc-devel-static
BuildRequires: klee-uclibc-devel-static(llvm%{llvm_version})
%endif
BuildRequires: libacl-devel
BuildRequires: libcap-devel
@ -73,8 +84,18 @@ information on what KLEE is and what it can do, see the OSDI 2008 paper.
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
mkdir -p build/test/
cp %{SOURCE2} build/test/
cp %{SOURCE3} build/test/
%build
%define __builder ninja

View File

@ -12,7 +12,6 @@
// not --crash cmd
// Will return true if cmd crashes (e.g. for testing crash reporting).
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;