Browse Source

Handling pop() from the empty EVM stack.

[#80895676]
cl-refactor
artur-zawlocki 10 years ago
parent
commit
080cf20f84
  1. 7
      libevmjit/Compiler.cpp
  2. 8
      libevmjit/Stack.cpp
  3. 1
      libevmjit/Type.h
  4. 2
      libevmjit/VM.cpp

7
libevmjit/Compiler.cpp

@ -925,6 +925,9 @@ void Compiler::linkBasicBlocks(Stack& stack)
{ {
auto& bbInfo = pair.second; auto& bbInfo = pair.second;
if (bbInfo.predecessors.empty())
bbInfo.inputItems = 0; // no consequences for other blocks, so leave valuesChanged false
for (auto predInfo : bbInfo.predecessors) for (auto predInfo : bbInfo.predecessors)
{ {
if (predInfo->outputItems < bbInfo.inputItems) if (predInfo->outputItems < bbInfo.inputItems)
@ -996,10 +999,10 @@ void Compiler::dumpBasicBlockGraph(std::ostream& out)
std::vector<BasicBlock*> blocks; std::vector<BasicBlock*> blocks;
for (auto& pair : this->basicBlocks) for (auto& pair : this->basicBlocks)
{
blocks.push_back(&pair.second); blocks.push_back(&pair.second);
} if (m_jumpTableBlock.get())
blocks.push_back(m_jumpTableBlock.get()); blocks.push_back(m_jumpTableBlock.get());
if (m_badJumpBlock.get())
blocks.push_back(m_badJumpBlock.get()); blocks.push_back(m_badJumpBlock.get());
// Output nodes // Output nodes

8
libevmjit/Stack.cpp

@ -1,5 +1,8 @@
#include "Stack.h" #include "Stack.h"
#include "Runtime.h" #include "Runtime.h"
#include "Type.h"
#include <csetjmp>
#include <llvm/IR/Function.h> #include <llvm/IR/Function.h>
#include <llvm/IR/TypeBuilder.h> #include <llvm/IR/TypeBuilder.h>
@ -51,9 +54,14 @@ extern "C"
using namespace dev::eth::jit; using namespace dev::eth::jit;
extern std::jmp_buf* rt_jmpBuf;
EXPORT void stack_pop(i256* _ret) EXPORT void stack_pop(i256* _ret)
{ {
auto& stack = Runtime::getStack(); auto& stack = Runtime::getStack();
if (stack.size() == 0)
longjmp(*rt_jmpBuf, static_cast<uint64_t>(ReturnCode::StackTooSmall));
assert(stack.size() > 0); assert(stack.size() > 0);
*_ret = stack.back(); *_ret = stack.back();
stack.pop_back(); stack.pop_back();

1
libevmjit/Type.h

@ -39,6 +39,7 @@ enum class ReturnCode
BadJumpDestination = 101, BadJumpDestination = 101,
OutOfGas = 102, OutOfGas = 102,
StackTooSmall = 103
}; };
struct Constant struct Constant

2
libevmjit/VM.cpp

@ -26,6 +26,8 @@ bytes VM::go(ExtVMFace& _ext)
BOOST_THROW_EXCEPTION(BadJumpDestination()); BOOST_THROW_EXCEPTION(BadJumpDestination());
case 102: case 102:
BOOST_THROW_EXCEPTION(OutOfGas()); BOOST_THROW_EXCEPTION(OutOfGas());
case 103:
BOOST_THROW_EXCEPTION(StackTooSmall(1,0));
} }
return std::move(engine.returnData); return std::move(engine.returnData);

Loading…
Cancel
Save