From 03ccc6df704aae4ea19698f0167798013c14536e Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 10 Nov 2016 11:33:15 +0100 Subject: codegen: truncate a boolean calldata down to one bit --- libsolidity/codegen/CompilerUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index d5361ac6..ff0f8b9c 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -925,6 +925,8 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda if (leftAligned) m_context << shiftFactor << Instruction::MUL; } + if (_fromCalldata && _type.category() == Type::Category::Bool) + m_context << Instruction::ISZERO << Instruction::ISZERO; return numBytes; } -- cgit From 0123e74a2eeac35bfa55886d0c6db391c07e7ec6 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 10 Nov 2016 14:41:50 +0100 Subject: codegen: cleanup booleans before storing them into memory --- libsolidity/codegen/CompilerUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index ff0f8b9c..ce5bb1d2 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -950,6 +950,8 @@ unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWordBou else { solAssert(numBytes <= 32, "Memory store of more than 32 bytes requested."); + if (_type.category() == Type::Category::Bool) + m_context << Instruction::ISZERO << Instruction::ISZERO; if (numBytes != 32 && !leftAligned && !_padToWordBoundaries) // shift the value accordingly before storing m_context << (u256(1) << ((32 - numBytes) * 8)) << Instruction::MUL; -- cgit From fb9babce54f76251b9616f192822e0c015411159 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 10 Nov 2016 15:38:08 +0100 Subject: codegen: truncate booleans before they enter storage --- libsolidity/codegen/LValue.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'libsolidity') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 23fe2d4e..b9e141d8 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -223,7 +223,6 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc { solAssert(m_dataType->storageBytes() <= 32, "Invalid storage bytes size."); solAssert(m_dataType->storageBytes() > 0, "Invalid storage bytes size."); - if (m_dataType->storageBytes() == 32) { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size."); -- cgit From 547deec4be55fc10b44de9ff92bb2d598d5b04f5 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 24 Nov 2016 11:57:28 +0100 Subject: codegen: clean any data from the input --- libsolidity/codegen/CompilerUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index ce5bb1d2..6763e995 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -925,8 +925,8 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda if (leftAligned) m_context << shiftFactor << Instruction::MUL; } - if (_fromCalldata && _type.category() == Type::Category::Bool) - m_context << Instruction::ISZERO << Instruction::ISZERO; + if (_fromCalldata) + convertType(_type, _type, true); return numBytes; } -- cgit From d77c8f730ce6a7c4caa86bb8e3bf1e5ca13b2117 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 25 Nov 2016 10:17:40 +0100 Subject: codegen: clean not only booleans but all types before storing them into memory --- libsolidity/codegen/CompilerUtils.cpp | 5 ++--- libsolidity/codegen/CompilerUtils.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 6763e995..edf457a1 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -941,7 +941,7 @@ void CompilerUtils::cleanHigherOrderBits(IntegerType const& _typeOnStack) m_context << ((u256(1) << _typeOnStack.numBits()) - 1) << Instruction::AND; } -unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWordBoundaries) const +unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWordBoundaries) { unsigned numBytes = _type.calldataEncodedSize(_padToWordBoundaries); bool leftAligned = _type.category() == Type::Category::FixedBytes; @@ -950,8 +950,7 @@ unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWordBou else { solAssert(numBytes <= 32, "Memory store of more than 32 bytes requested."); - if (_type.category() == Type::Category::Bool) - m_context << Instruction::ISZERO << Instruction::ISZERO; + convertType(_type, _type, true); if (numBytes != 32 && !leftAligned && !_padToWordBoundaries) // shift the value accordingly before storing m_context << (u256(1) << ((32 - numBytes) * 8)) << Instruction::MUL; diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h index 4baf48ff..0a5d8e1c 100644 --- a/libsolidity/codegen/CompilerUtils.h +++ b/libsolidity/codegen/CompilerUtils.h @@ -185,7 +185,7 @@ private: void cleanHigherOrderBits(IntegerType const& _typeOnStack); /// Prepares the given type for storing in memory by shifting it if necessary. - unsigned prepareMemoryStore(Type const& _type, bool _padToWordBoundaries) const; + unsigned prepareMemoryStore(Type const& _type, bool _padToWordBoundaries); /// Loads type from memory assuming memory offset is on stack top. unsigned loadFromMemoryHelper(Type const& _type, bool _fromCalldata, bool _padToWordBoundaries); -- cgit