diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index d0c197b1f..1583a8d63 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -414,7 +414,8 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( fromArrayType.isByteArray() || *fromArrayType.baseType() == *TypeProvider::uint256() || *fromArrayType.baseType() == FixedBytesType(32), - ""); + "" + ); solAssert(fromArrayType.calldataStride() == toArrayType.memoryStride(), ""); solAssert( diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 08d30f537..6a07ae102 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -1055,28 +1055,27 @@ void ArrayUtils::accessIndex(ArrayType const& _arrayType, bool _doBoundsCheck, b switch (location) { case DataLocation::Memory: + // stack: + if (!_arrayType.isByteArray()) + m_context << u256(_arrayType.memoryHeadSize()) << Instruction::MUL; + if (_arrayType.isDynamicallySized()) + m_context << u256(32) << Instruction::ADD; + if (_keepReference) + m_context << Instruction::DUP2; + m_context << Instruction::ADD; + break; case DataLocation::CallData: if (!_arrayType.isByteArray()) { - if (location == DataLocation::CallData) - { - if (_arrayType.baseType()->isDynamicallyEncoded()) - m_context << u256(0x20); - else - m_context << _arrayType.baseType()->calldataEncodedSize(); - } + if (_arrayType.baseType()->isDynamicallyEncoded()) + m_context << u256(0x20); else - m_context << u256(_arrayType.memoryHeadSize()); + m_context << _arrayType.baseType()->calldataEncodedSize(); m_context << Instruction::MUL; } // stack: - - if (location == DataLocation::Memory && _arrayType.isDynamicallySized()) - m_context << u256(32) << Instruction::ADD; - if (_keepReference) m_context << Instruction::DUP2; - m_context << Instruction::ADD; break; case DataLocation::Storage: diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index d6be20328..77534ee34 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -816,7 +816,12 @@ void CompilerUtils::convertType( } else { - solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract || targetTypeCategory == Type::Category::Address, ""); + solAssert( + targetTypeCategory == Type::Category::Integer || + targetTypeCategory == Type::Category::Contract || + targetTypeCategory == Type::Category::Address, + "" + ); IntegerType addressType(160); IntegerType const& targetType = targetTypeCategory == Type::Category::Integer ? dynamic_cast(_targetType) : addressType; @@ -923,7 +928,6 @@ void CompilerUtils::convertType( // stack: (variably sized) if (targetType.baseType()->isValueType()) { - solAssert(typeOnStack.baseType()->isValueType(), ""); copyToStackTop(2 + stackSize, stackSize); ArrayUtils(m_context).copyArrayToMemory(typeOnStack); } @@ -957,10 +961,11 @@ void CompilerUtils::convertType( } case DataLocation::CallData: solAssert( - targetType.isByteArray() && - typeOnStack.isByteArray() && - typeOnStack.location() == DataLocation::CallData, - "Invalid conversion to calldata type."); + targetType.isByteArray() && + typeOnStack.isByteArray() && + typeOnStack.location() == DataLocation::CallData, + "Invalid conversion to calldata type." + ); break; } break; diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index d50e4f4d5..6e2e74e45 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -54,7 +54,13 @@ class StackHeightChecker public: explicit StackHeightChecker(CompilerContext const& _context): m_context(_context), stackHeight(m_context.stackHeight()) {} - void check() { solAssert(m_context.stackHeight() == stackHeight, std::string("I sense a disturbance in the stack: ") + to_string(m_context.stackHeight()) + " vs " + to_string(stackHeight)); } + void check() + { + solAssert( + m_context.stackHeight() == stackHeight, + std::string("I sense a disturbance in the stack: ") + to_string(m_context.stackHeight()) + " vs " + to_string(stackHeight) + ); + } private: CompilerContext const& m_context; unsigned stackHeight; @@ -893,9 +899,9 @@ bool ContractCompiler::visit(VariableDeclarationStatement const& _variableDeclar // Local variable slots are reserved when their declaration is visited, // and freed in the end of their scope. - for (auto _decl: _variableDeclarationStatement.declarations()) - if (_decl) - appendStackVariableInitialisation(*_decl); + for (auto decl: _variableDeclarationStatement.declarations()) + if (decl) + appendStackVariableInitialisation(*decl); StackHeightChecker checker(m_context); if (Expression const* expression = _variableDeclarationStatement.initialValue())