From 3f9f725737dd04485211fedc8533fdac983f2b04 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Fri, 18 Nov 2016 17:13:20 -0600 Subject: Fix licensing headers Signed-off-by: VoR0220 --- libsolidity/codegen/LValue.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 2ec7f800..3f1730d1 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** * @author Christian -- cgit v1.2.3 From 5b8a77398608689088938454583d284afd58ab50 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 15 Nov 2016 17:54:09 +0100 Subject: codegen: cleanup value types before storing them --- libsolidity/codegen/LValue.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 3f1730d1..933c0419 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -221,6 +221,11 @@ 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."); + + m_context << Instruction::SWAP2; + CompilerUtils(m_context).convertType(*m_dataType, *m_dataType, true); + m_context << Instruction::SWAP2; + if (m_dataType->storageBytes() == 32) { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size."); -- cgit v1.2.3 From 56d664108614fa8fdf63a02d8f605bf5afcd0837 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 21 Nov 2016 16:41:02 +0100 Subject: codegen: cleanup stored values in a more consistent way --- libsolidity/codegen/LValue.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 933c0419..78854588 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -216,16 +216,14 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const { CompilerUtils utils(m_context); + solAssert(m_dataType, ""); + // stack: value storage_key storage_offset if (m_dataType->isValueType()) { solAssert(m_dataType->storageBytes() <= 32, "Invalid storage bytes size."); solAssert(m_dataType->storageBytes() > 0, "Invalid storage bytes size."); - m_context << Instruction::SWAP2; - CompilerUtils(m_context).convertType(*m_dataType, *m_dataType, true); - m_context << Instruction::SWAP2; - if (m_dataType->storageBytes() == 32) { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size."); @@ -233,10 +231,23 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc m_context << Instruction::POP; if (!_move) m_context << Instruction::DUP2 << Instruction::SWAP1; + + m_context << Instruction::SWAP1; + utils.convertType(_sourceType, _sourceType, true); + utils.convertType(*m_dataType, *m_dataType, true); + m_context << Instruction::SWAP1; + m_context << Instruction::SSTORE; } else { + if (_sourceType.sizeOnStack() == 1) + { + m_context << Instruction::SWAP2; + utils.convertType(_sourceType, _sourceType, true); + m_context << Instruction::SWAP2; + } + // OR the value into the other values in the storage slot m_context << u256(0x100) << Instruction::EXP; // stack: value storage_ref multiplier @@ -269,6 +280,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type."); // remove the higher order bits + utils.convertType(*m_dataType, *m_dataType, true); m_context << (u256(1) << (8 * (32 - m_dataType->storageBytes()))) << Instruction::SWAP1 -- cgit v1.2.3 From ea628001d5f34ee1d85398a17f93e7c4f55429fe Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 21 Nov 2016 17:07:10 +0100 Subject: codegen: add an option to CovertType so that it can truncate sign bits --- libsolidity/codegen/LValue.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 78854588..df74e836 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -234,7 +234,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc m_context << Instruction::SWAP1; utils.convertType(_sourceType, _sourceType, true); - utils.convertType(*m_dataType, *m_dataType, true); + utils.convertType(*m_dataType, *m_dataType, true, true); m_context << Instruction::SWAP1; m_context << Instruction::SSTORE; @@ -280,13 +280,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type."); // remove the higher order bits - utils.convertType(*m_dataType, *m_dataType, true); - m_context - << (u256(1) << (8 * (32 - m_dataType->storageBytes()))) - << Instruction::SWAP1 - << Instruction::DUP2 - << Instruction::MUL - << Instruction::DIV; + utils.convertType(*m_dataType, *m_dataType, true, true); } m_context << Instruction::MUL << Instruction::OR; // stack: value storage_ref updated_value -- cgit v1.2.3 From 9d25b5601e6e2713e14803777390c2d45be3d51c Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 24 Nov 2016 16:49:54 +0100 Subject: codegen: merge type conversion and cleaning up --- libsolidity/codegen/LValue.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index df74e836..63729d27 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -233,8 +233,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc m_context << Instruction::DUP2 << Instruction::SWAP1; m_context << Instruction::SWAP1; - utils.convertType(_sourceType, _sourceType, true); - utils.convertType(*m_dataType, *m_dataType, true, true); + utils.convertType(_sourceType, *m_dataType, true); m_context << Instruction::SWAP1; m_context << Instruction::SSTORE; @@ -244,7 +243,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc if (_sourceType.sizeOnStack() == 1) { m_context << Instruction::SWAP2; - utils.convertType(_sourceType, _sourceType, true); + utils.convertType(_sourceType, *m_dataType, true); m_context << Instruction::SWAP2; } -- cgit v1.2.3 From 548b7ce42d1650d18ce71c3d11486ab4d27e6c0f Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 25 Nov 2016 15:38:02 +0100 Subject: codegen: storing of non-value types; add some assertions --- libsolidity/codegen/LValue.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'libsolidity/codegen/LValue.cpp') diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 63729d27..23fe2d4e 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -240,13 +240,6 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc } else { - if (_sourceType.sizeOnStack() == 1) - { - m_context << Instruction::SWAP2; - utils.convertType(_sourceType, *m_dataType, true); - m_context << Instruction::SWAP2; - } - // OR the value into the other values in the storage slot m_context << u256(0x100) << Instruction::EXP; // stack: value storage_ref multiplier @@ -263,6 +256,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc // stack: value storage_ref cleared_value multiplier value if (FunctionType const* fun = dynamic_cast(m_dataType)) { + solAssert(_sourceType == *m_dataType, "function item stored but target is not equal to source"); if (fun->location() == FunctionType::Location::External) // Combine the two-item function type into a single stack slot. utils.combineExternalFunctionType(false); @@ -272,14 +266,17 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc Instruction::AND; } else if (m_dataType->category() == Type::Category::FixedBytes) + { + solAssert(_sourceType.category() == Type::Category::FixedBytes, "source not fixed bytes"); m_context << (u256(0x1) << (256 - 8 * dynamic_cast(*m_dataType).numBytes())) << Instruction::SWAP1 << Instruction::DIV; + } else { solAssert(m_dataType->sizeOnStack() == 1, "Invalid stack size for opaque type."); // remove the higher order bits - utils.convertType(*m_dataType, *m_dataType, true, true); + utils.convertType(_sourceType, *m_dataType, true, true); } m_context << Instruction::MUL << Instruction::OR; // stack: value storage_ref updated_value -- cgit v1.2.3 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/codegen/LValue.cpp') 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 v1.2.3