From 1d4ea994537803b9580feab3fe4c9c12b080a134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 26 Jun 2015 14:38:20 +0200 Subject: [PATCH] Fix for incorrect BYTE instruction results. It is actually a LLVM bug workaround. --- libevmjit/Compiler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libevmjit/Compiler.cpp b/libevmjit/Compiler.cpp index 55a8b9203..00fe7f7d0 100644 --- a/libevmjit/Compiler.cpp +++ b/libevmjit/Compiler.cpp @@ -481,7 +481,9 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, RuntimeManager& _runti auto idxValid = m_builder.CreateICmpULT(idx, Constant::get(32), "idxValid"); auto bytes = m_builder.CreateBitCast(value, llvm::VectorType::get(Type::Byte, 32), "bytes"); - auto byte = m_builder.CreateExtractElement(bytes, idx, "byte"); + // Workaround for LLVM bug. Using index of type i256 can produce incorrect results + auto safeIdx = m_builder.CreateZExt(m_builder.CreateTrunc(idx, m_builder.getIntNTy(5)), Type::Size); + auto byte = m_builder.CreateExtractElement(bytes, safeIdx, "byte"); value = m_builder.CreateZExt(byte, Type::Word); value = m_builder.CreateSelect(idxValid, value, Constant::get(0)); stack.push(value);