From 4d2dc802e8b2a69b72fd93eff21bc42651536a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 12 Feb 2015 11:00:07 +0100 Subject: [PATCH] Introducing CHECK macro - an assert that always has a value --- libevmjit/Cache.cpp | 5 ++++- libevmjit/ExecutionEngine.cpp | 8 +++++--- libevmjit/Utils.h | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libevmjit/Cache.cpp b/libevmjit/Cache.cpp index d7d6f1bbb..fe226eefb 100644 --- a/libevmjit/Cache.cpp +++ b/libevmjit/Cache.cpp @@ -13,6 +13,7 @@ #include "preprocessor/llvm_includes_end.h" #include "ExecutionEngine.h" +#include "Utils.h" namespace dev { @@ -43,7 +44,9 @@ std::unique_ptr Cache::getObject(std::string const& id) g_listener->stateChanged(ExecState::CacheLoad); CACHE_LOG << id << ": search\n"; - assert(!g_lastObject); + if (!CHECK(!g_lastObject)) + g_lastObject = nullptr; + llvm::SmallString<256> cachePath; llvm::sys::path::system_temp_directory(false, cachePath); llvm::sys::path::append(cachePath, "evm_objs", id); diff --git a/libevmjit/ExecutionEngine.cpp b/libevmjit/ExecutionEngine.cpp index ff4c64cee..1d2ff91b1 100644 --- a/libevmjit/ExecutionEngine.cpp +++ b/libevmjit/ExecutionEngine.cpp @@ -18,6 +18,7 @@ #include "Compiler.h" #include "Cache.h" #include "ExecStats.h" +#include "Utils.h" #include "BuildInfo.gen.h" namespace dev @@ -98,7 +99,7 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) module->setTargetTriple(triple.str()); ee.reset(builder.create()); - if (!ee) + if (!CHECK(ee)) return ReturnCode::LLVMConfigError; module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module ee->setObjectCache(objectCache); @@ -111,7 +112,7 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) auto entryFuncPtr = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName); if (!entryFuncPtr) - { + { auto module = objectCache ? Cache::getObject(mainFuncName) : nullptr; if (!module) { @@ -127,7 +128,8 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env) listener->stateChanged(ExecState::CodeGen); entryFuncPtr = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName); } - assert(entryFuncPtr); //TODO: Replace it with safe exception + if (!CHECK(entryFuncPtr)) + return ReturnCode::LLVMLinkError; listener->stateChanged(ExecState::Execution); auto returnCode = entryFuncPtr(&runtime); diff --git a/libevmjit/Utils.h b/libevmjit/Utils.h index 7e6133ced..aad975f5b 100644 --- a/libevmjit/Utils.h +++ b/libevmjit/Utils.h @@ -16,6 +16,9 @@ struct JIT: public NoteChannel { static const char* name() { return "JIT"; } }; //#define clog(CHANNEL) std::cerr #define clog(CHANNEL) std::ostream(nullptr) +// The same as assert, but expression is always evaluated and result returned +#define CHECK(expr) (assert(expr), expr) + } } }