From 3ec667f59bac067b45cac8b542e135ff4c02d12f Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Tue, 24 Apr 2018 23:39:25 +0200 Subject: Add virtual destructor in LValue class. --- libsolidity/codegen/LValue.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/LValue.h b/libsolidity/codegen/LValue.h index f8b68362..c576f9de 100644 --- a/libsolidity/codegen/LValue.h +++ b/libsolidity/codegen/LValue.h @@ -49,6 +49,7 @@ protected: m_context(_compilerContext), m_dataType(_dataType) {} public: + virtual ~LValue() {} /// @returns the number of stack slots occupied by the lvalue reference virtual unsigned sizeOnStack() const { return 1; } /// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true, -- cgit v1.2.3 From 22bfd3da41ae9efa6e68e884f722502ab3adcf50 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 29 Mar 2018 09:56:51 +0100 Subject: Use native shift instructions on Constantinople --- libsolidity/codegen/CompilerUtils.cpp | 10 ++++++++-- libsolidity/codegen/ExpressionCompiler.cpp | 13 +++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 4af7d905..46e81d49 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1265,13 +1265,19 @@ void CompilerUtils::cleanHigherOrderBits(IntegerType const& _typeOnStack) void CompilerUtils::leftShiftNumberOnStack(unsigned _bits) { solAssert(_bits < 256, ""); - m_context << (u256(1) << _bits) << Instruction::MUL; + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << _bits << Instruction::SHL; + else + m_context << (u256(1) << _bits) << Instruction::MUL; } void CompilerUtils::rightShiftNumberOnStack(unsigned _bits, bool _isSigned) { solAssert(_bits < 256, ""); - m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV); + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << _bits << (_isSigned ? Instruction::SAR : Instruction::SHR); + else + m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV); } unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3cf46a9d..1a33fe7c 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1706,13 +1706,22 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator, Type co m_context.appendConditionalInvalid(); } + m_context << Instruction::SWAP1; + // stack: value_to_shift shift_amount + switch (_operator) { case Token::SHL: - m_context << Instruction::SWAP1 << u256(2) << Instruction::EXP << Instruction::MUL; + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << Instruction::SHL; + else + m_context << u256(2) << Instruction::EXP << Instruction::MUL; break; case Token::SAR: - m_context << Instruction::SWAP1 << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV); + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << (c_valueSigned ? Instruction::SAR : Instruction::SHR); + else + m_context << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV); break; case Token::SHR: default: -- cgit v1.2.3 From c3608eaf90b49771b2785d86bb0c73dca6e61046 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 5 Apr 2018 16:56:02 +0200 Subject: Use native shift instructions in ABIFunctions on Constantinople --- libsolidity/codegen/ABIFunctions.cpp | 87 +++++++++++++++++++++++++---------- libsolidity/codegen/ABIFunctions.h | 6 +++ libsolidity/codegen/CompilerContext.h | 3 +- 3 files changed, 70 insertions(+), 26 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 8e890854..f6aa714d 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -1401,37 +1401,74 @@ string ABIFunctions::copyToMemoryFunction(bool _fromCalldata) string ABIFunctions::shiftLeftFunction(size_t _numBits) { + solAssert(_numBits < 256, ""); + string functionName = "shift_left_" + to_string(_numBits); - return createFunction(functionName, [&]() { - solAssert(_numBits < 256, ""); - return - Whiskers(R"( - function (value) -> newValue { - newValue := mul(value, ) - } - )") - ("functionName", functionName) - ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits)) - .render(); - }); + if (m_evmVersion.hasBitwiseShifting()) + { + return createFunction(functionName, [&]() { + return + Whiskers(R"( + function (value) -> newValue { + newValue := shl(, value) + } + )") + ("functionName", functionName) + ("numBits", to_string(_numBits)) + .render(); + }); + } + else + { + return createFunction(functionName, [&]() { + return + Whiskers(R"( + function (value) -> newValue { + newValue := mul(value, ) + } + )") + ("functionName", functionName) + ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits)) + .render(); + }); + } } string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed) { + solAssert(_numBits < 256, ""); + string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned"); - return createFunction(functionName, [&]() { - solAssert(_numBits < 256, ""); - return - Whiskers(R"( - function (value) -> newValue { - newValue :=
(value, ) - } - )") - ("functionName", functionName) - ("div", _signed ? "sdiv" : "div") - ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits)) - .render(); - }); + if (m_evmVersion.hasBitwiseShifting()) + { + return createFunction(functionName, [&]() { + return + Whiskers(R"( + function (value) -> newValue { + newValue := (, value) + } + )") + ("functionName", functionName) + ("shiftOp", _signed ? "sar" : "shr") + ("numBits", to_string(_numBits)) + .render(); + }); + } + else + { + return createFunction(functionName, [&]() { + return + Whiskers(R"( + function (value) -> newValue { + newValue :=
(value, ) + } + )") + ("functionName", functionName) + ("div", _signed ? "sdiv" : "div") + ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits)) + .render(); + }); + } } string ABIFunctions::roundUpFunction() diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index 2b582e84..41bb70b2 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -22,6 +22,8 @@ #pragma once +#include + #include #include @@ -48,6 +50,8 @@ using TypePointers = std::vector; class ABIFunctions { public: + explicit ABIFunctions(EVMVersion _evmVersion = EVMVersion{}) : m_evmVersion(_evmVersion) {} + /// @returns name of an assembly function to ABI-encode values of @a _givenTypes /// into memory, converting the types to @a _targetTypes on the fly. /// Parameters are: ... , i.e. @@ -225,6 +229,8 @@ private: /// Map from function name to code for a multi-use function. std::map m_requestedFunctions; + + EVMVersion m_evmVersion; }; } diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 098472f7..5776b5d1 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -55,7 +55,8 @@ public: explicit CompilerContext(EVMVersion _evmVersion = EVMVersion{}, CompilerContext* _runtimeContext = nullptr): m_asm(std::make_shared()), m_evmVersion(_evmVersion), - m_runtimeContext(_runtimeContext) + m_runtimeContext(_runtimeContext), + m_abiFunctions(m_evmVersion) { if (m_runtimeContext) m_runtimeSub = size_t(m_asm->newSub(m_runtimeContext->m_asm).data()); -- cgit v1.2.3 From 52c94418795f829c4a225fdf4742eec7a1961232 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 6 Apr 2018 14:54:21 +0200 Subject: Do not use SAR instead of SDIV in shifts because it rounds differently --- libsolidity/codegen/ABIFunctions.cpp | 7 ++++--- libsolidity/codegen/CompilerUtils.cpp | 5 +++-- libsolidity/codegen/ExpressionCompiler.cpp | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index f6aa714d..6c4ddc02 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -1439,17 +1439,18 @@ string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed) solAssert(_numBits < 256, ""); string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned"); - if (m_evmVersion.hasBitwiseShifting()) + + // NOTE: SAR rounds differently than SDIV + if (m_evmVersion.hasBitwiseShifting() && !_signed) { return createFunction(functionName, [&]() { return Whiskers(R"( function (value) -> newValue { - newValue := (, value) + newValue := shr(, value) } )") ("functionName", functionName) - ("shiftOp", _signed ? "sar" : "shr") ("numBits", to_string(_numBits)) .render(); }); diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 46e81d49..45ad1f47 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1274,8 +1274,9 @@ void CompilerUtils::leftShiftNumberOnStack(unsigned _bits) void CompilerUtils::rightShiftNumberOnStack(unsigned _bits, bool _isSigned) { solAssert(_bits < 256, ""); - if (m_context.evmVersion().hasBitwiseShifting()) - m_context << _bits << (_isSigned ? Instruction::SAR : Instruction::SHR); + // NOTE: SAR rounds differently than SDIV + if (m_context.evmVersion().hasBitwiseShifting() && !_isSigned) + m_context << _bits << Instruction::SHR; else m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV); } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 1a33fe7c..019867c5 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1718,8 +1718,9 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator, Type co m_context << u256(2) << Instruction::EXP << Instruction::MUL; break; case Token::SAR: - if (m_context.evmVersion().hasBitwiseShifting()) - m_context << (c_valueSigned ? Instruction::SAR : Instruction::SHR); + // NOTE: SAR rounds differently than SDIV + if (m_context.evmVersion().hasBitwiseShifting() && !c_valueSigned) + m_context << Instruction::SHR; else m_context << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV); break; -- cgit v1.2.3 From 2968639406888d97bfae70e4adf41674ac60fd83 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 6 Apr 2018 16:25:13 +0200 Subject: Removed signed shift right from the utilities. --- libsolidity/codegen/ABIFunctions.cpp | 22 +++++++++++----------- libsolidity/codegen/ABIFunctions.h | 2 +- libsolidity/codegen/CompilerUtils.cpp | 18 +++++++++--------- libsolidity/codegen/CompilerUtils.h | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- libsolidity/codegen/LValue.cpp | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 6c4ddc02..3e3aa0ae 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -371,7 +371,7 @@ string ABIFunctions::conversionFunction(Type const& _from, Type const& _to) if (toCategory == Type::Category::Integer) body = Whiskers("converted := ((value))") - ("shift", shiftRightFunction(256 - from.numBytes() * 8, false)) + ("shift", shiftRightFunction(256 - from.numBytes() * 8)) ("convert", conversionFunction(IntegerType(from.numBytes() * 8), _to)) .render(); else @@ -458,8 +458,8 @@ string ABIFunctions::splitExternalFunctionIdFunction() } )") ("functionName", functionName) - ("shr32", shiftRightFunction(32, false)) - ("shr64", shiftRightFunction(64, false)) + ("shr32", shiftRightFunction(32)) + ("shr64", shiftRightFunction(64)) .render(); }); } @@ -831,7 +831,7 @@ string ABIFunctions::abiEncodingFunctionCompactStorageArray( templ("encodeToMemoryFun", encodeToMemoryFun); std::vector> items(itemsPerSlot); for (size_t i = 0; i < itemsPerSlot; ++i) - items[i]["shiftRightFun"] = shiftRightFunction(i * storageBytes * 8, false); + items[i]["shiftRightFun"] = shiftRightFunction(i * storageBytes * 8); templ("items", items); return templ.render(); } @@ -927,7 +927,7 @@ string ABIFunctions::abiEncodingFunctionStruct( } else memberTempl("preprocess", ""); - memberTempl("retrieveValue", shiftRightFunction(intraSlotOffset * 8, false) + "(slotValue)"); + memberTempl("retrieveValue", shiftRightFunction(intraSlotOffset * 8) + "(slotValue)"); } else { @@ -1434,14 +1434,15 @@ string ABIFunctions::shiftLeftFunction(size_t _numBits) } } -string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed) +string ABIFunctions::shiftRightFunction(size_t _numBits) { solAssert(_numBits < 256, ""); - string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned"); + // Note that if this is extended with signed shifts, + // the opcodes SAR and SDIV behave differently with regards to rounding! - // NOTE: SAR rounds differently than SDIV - if (m_evmVersion.hasBitwiseShifting() && !_signed) + string functionName = "shift_right_" + to_string(_numBits) + "_unsigned"; + if (m_evmVersion.hasBitwiseShifting()) { return createFunction(functionName, [&]() { return @@ -1461,11 +1462,10 @@ string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed) return Whiskers(R"( function (value) -> newValue { - newValue :=
(value, ) + newValue := div(value, ) } )") ("functionName", functionName) - ("div", _signed ? "sdiv" : "div") ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits)) .render(); }); diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index 41bb70b2..db4d40f5 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -195,7 +195,7 @@ private: std::string copyToMemoryFunction(bool _fromCalldata); std::string shiftLeftFunction(size_t _numBits); - std::string shiftRightFunction(size_t _numBits, bool _signed); + std::string shiftRightFunction(size_t _numBits); /// @returns the name of a function that rounds its input to the next multiple /// of 32 or the input if it is a multiple of 32. std::string roundUpFunction(); diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 45ad1f47..48b77eb3 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -599,15 +599,15 @@ void CompilerUtils::splitExternalFunctionType(bool _leftAligned) if (_leftAligned) { m_context << Instruction::DUP1; - rightShiftNumberOnStack(64 + 32, false); + rightShiftNumberOnStack(64 + 32); //
m_context << Instruction::SWAP1; - rightShiftNumberOnStack(64, false); + rightShiftNumberOnStack(64); } else { m_context << Instruction::DUP1; - rightShiftNumberOnStack(32, false); + rightShiftNumberOnStack(32); m_context << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1; } m_context << u256(0xffffffffUL) << Instruction::AND; @@ -675,7 +675,7 @@ void CompilerUtils::convertType( // conversion from bytes to integer. no need to clean the high bit // only to shift right because of opposite alignment IntegerType const& targetIntegerType = dynamic_cast(_targetType); - rightShiftNumberOnStack(256 - typeOnStack.numBytes() * 8, false); + rightShiftNumberOnStack(256 - typeOnStack.numBytes() * 8); if (targetIntegerType.numBits() < typeOnStack.numBytes() * 8) convertType(IntegerType(typeOnStack.numBytes() * 8), _targetType, _cleanupNeeded); } @@ -1242,7 +1242,7 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda bool leftAligned = _type.category() == Type::Category::FixedBytes; // add leading or trailing zeros by dividing/multiplying depending on alignment int shiftFactor = (32 - numBytes) * 8; - rightShiftNumberOnStack(shiftFactor, false); + rightShiftNumberOnStack(shiftFactor); if (leftAligned) leftShiftNumberOnStack(shiftFactor); } @@ -1271,14 +1271,14 @@ void CompilerUtils::leftShiftNumberOnStack(unsigned _bits) m_context << (u256(1) << _bits) << Instruction::MUL; } -void CompilerUtils::rightShiftNumberOnStack(unsigned _bits, bool _isSigned) +void CompilerUtils::rightShiftNumberOnStack(unsigned _bits) { solAssert(_bits < 256, ""); - // NOTE: SAR rounds differently than SDIV - if (m_context.evmVersion().hasBitwiseShifting() && !_isSigned) + // NOTE: If we add signed right shift, SAR rounds differently than SDIV + if (m_context.evmVersion().hasBitwiseShifting()) m_context << _bits << Instruction::SHR; else - m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV); + m_context << (u256(1) << _bits) << Instruction::SWAP1 << Instruction::DIV; } unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords) diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h index 476a7559..8e3a8a5d 100644 --- a/libsolidity/codegen/CompilerUtils.h +++ b/libsolidity/codegen/CompilerUtils.h @@ -254,7 +254,7 @@ public: /// Helper function to shift top value on the stack to the right. /// Stack pre: /// Stack post: - void rightShiftNumberOnStack(unsigned _bits, bool _isSigned = false); + void rightShiftNumberOnStack(unsigned _bits); /// Appends code that computes tha Keccak-256 hash of the topmost stack element of 32 byte type. void computeHashStatic(); diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 019867c5..a8222e21 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -548,7 +548,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) if (m_context.runtimeContext()) // We have a runtime context, so we need the creation part. - utils().rightShiftNumberOnStack(32, false); + utils().rightShiftNumberOnStack(32); else // Extract the runtime part. m_context << ((u256(1) << 32) - 1) << Instruction::AND; diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index e19cf41e..77684683 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -267,7 +267,7 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc else if (m_dataType->category() == Type::Category::FixedBytes) { solAssert(_sourceType.category() == Type::Category::FixedBytes, "source not fixed bytes"); - CompilerUtils(m_context).rightShiftNumberOnStack(256 - 8 * dynamic_cast(*m_dataType).numBytes(), false); + CompilerUtils(m_context).rightShiftNumberOnStack(256 - 8 * dynamic_cast(*m_dataType).numBytes()); } else { -- cgit v1.2.3 From aa1542a9e12177311e7d426b7606823ae45ee88e Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 30 Apr 2018 22:58:04 -0700 Subject: Change bytes to unsigned in FixedBytesType --- libsolidity/codegen/CompilerUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 48b77eb3..fc1ff0eb 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -688,7 +688,7 @@ void CompilerUtils::convertType( m_context << Instruction::POP << u256(0); else if (targetType.numBytes() > typeOnStack.numBytes() || _cleanupNeeded) { - int bytes = min(typeOnStack.numBytes(), targetType.numBytes()); + unsigned bytes = min(typeOnStack.numBytes(), targetType.numBytes()); m_context << ((u256(1) << (256 - bytes * 8)) - 1); m_context << Instruction::NOT << Instruction::AND; } @@ -796,7 +796,7 @@ void CompilerUtils::convertType( bytesConstRef data(value); if (targetTypeCategory == Type::Category::FixedBytes) { - int const numBytes = dynamic_cast(_targetType).numBytes(); + unsigned const numBytes = dynamic_cast(_targetType).numBytes(); solAssert(data.size() <= 32, ""); m_context << (h256::Arith(h256(data, h256::AlignLeft)) & (~(u256(-1) >> (8 * numBytes)))); } -- cgit v1.2.3 From 51b4dc37522f82c0fe4549c7cb24b1567ee1b316 Mon Sep 17 00:00:00 2001 From: njwest Date: Sun, 6 May 2018 18:52:12 -0400 Subject: fixed grammar in error in CompilerUtils.cpp line 399, 'less variables.' should be 'fewer variables.' --- libsolidity/codegen/CompilerUtils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index fc1ff0eb..a39e799c 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -110,7 +110,7 @@ void CompilerUtils::loadFromMemoryDynamic( bool _padToWordBoundaries, bool _keepUpdatedMemoryOffset ) -{ +{ if (_keepUpdatedMemoryOffset) m_context << Instruction::DUP1; @@ -396,7 +396,7 @@ void CompilerUtils::encodeToMemory( // leave end_of_mem as dyn head pointer m_context << Instruction::DUP1 << u256(32) << Instruction::ADD; dynPointers++; - solAssert((argSize + dynPointers) < 16, "Stack too deep, try using less variables."); + solAssert((argSize + dynPointers) < 16, "Stack too deep, try using fewer variables."); } else { @@ -741,7 +741,7 @@ void CompilerUtils::convertType( else if (targetTypeCategory == Type::Category::FixedPoint) { solAssert( - stackTypeCategory == Type::Category::Integer || + stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::RationalNumber || stackTypeCategory == Type::Category::FixedPoint, "Invalid conversion to FixedMxNType requested." -- cgit v1.2.3 From c03a29dea8cf8718d34a4776534be0c75cc4c8c3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 4 May 2018 03:18:52 +0100 Subject: Fix revert with reason coming from a string variable --- libsolidity/codegen/CompilerUtils.cpp | 1 - libsolidity/codegen/ExpressionCompiler.cpp | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index a39e799c..d9f17263 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -89,7 +89,6 @@ void CompilerUtils::revertWithStringData(Type const& _argumentType) abiEncode({_argumentType.shared_from_this()}, {make_shared(DataLocation::Memory, true)}); toSizeAfterFreeMemoryPointer(); m_context << Instruction::REVERT; - m_context.adjustStackOffset(_argumentType.sizeOnStack()); } unsigned CompilerUtils::loadFromMemory( diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index a8222e21..4bcc1fa9 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -933,7 +933,11 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // condition was not met, flag an error m_context.appendInvalid(); else if (arguments.size() > 1) + { utils().revertWithStringData(*arguments.at(1)->annotation().type); + // Here, the argument is consumed, but in the other branch, it is still there. + m_context.adjustStackOffset(arguments.at(1)->annotation().type->sizeOnStack()); + } else m_context.appendRevert(); // the success branch -- cgit v1.2.3