From 90a03ec025f8d0632abfd16d01413a8ad4d3cf27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 29 Jun 2015 16:33:48 +0200 Subject: [PATCH] Better BYTE fix. --- libevmjit/Compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libevmjit/Compiler.cpp b/libevmjit/Compiler.cpp index 00fe7f7d0..cde86c747 100644 --- a/libevmjit/Compiler.cpp +++ b/libevmjit/Compiler.cpp @@ -481,8 +481,8 @@ 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"); - // 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); + // Workaround for LLVM bug. Using big value of index causes invalid memory access. + auto safeIdx = m_builder.CreateTrunc(idx, m_builder.getIntNTy(5)); auto byte = m_builder.CreateExtractElement(bytes, safeIdx, "byte"); value = m_builder.CreateZExt(byte, Type::Word); value = m_builder.CreateSelect(idxValid, value, Constant::get(0));