From aefb6e5fcf9adc7c58da9ec0454707305f7e9ac9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 5 Oct 2016 11:30:28 +0100 Subject: Rename dev::sha3 to dev::keccak256 --- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 26acd8a4..3d05edd3 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -670,7 +670,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) } if (!event.isAnonymous()) { - m_context << u256(h256::Arith(dev::sha3(function.externalSignature()))); + m_context << u256(h256::Arith(dev::keccak256(function.externalSignature()))); ++numIndexed; } solAssert(numIndexed <= 4, "Too many indexed arguments."); -- cgit v1.2.3 From 0e33b6346802581cfcc45195344a705ebd683c1f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 20 Oct 2016 01:09:57 +0100 Subject: Allow warnings for inline assembly block --- libsolidity/codegen/ContractCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 18b42fce..ebb84784 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -575,7 +575,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) return true; } ); - solAssert(errors.empty(), "Code generation for inline assembly with errors requested."); + solAssert(Error::containsOnlyWarnings(errors), "Code generation for inline assembly with errors requested."); m_context.setStackOffset(startStackHeight); return false; } -- cgit v1.2.3 From 7cee39fc17a94bb14ccf60dee6209162e21a7b97 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 21 Oct 2016 10:05:36 +0200 Subject: codegen: skip contract L for L.Foo where Foo is a type Fixes #1116 --- libsolidity/codegen/ExpressionCompiler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3d05edd3..da3e56cc 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -861,11 +861,12 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) } // Special processing for TypeType because we do not want to visit the library itself - // for internal functions. + // for internal functions, or enum/struct definitions. if (TypeType const* type = dynamic_cast(_memberAccess.expression().annotation().type.get())) { if (dynamic_cast(type->actualType().get())) { + solAssert(_memberAccess.annotation().type, "_memberAccess has no type"); if (auto funType = dynamic_cast(_memberAccess.annotation().type.get())) { if (funType->location() != FunctionType::Location::Internal) @@ -883,6 +884,10 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) m_context << m_context.functionEntryLabel(*function).pushTag(); } } + else if (dynamic_cast(_memberAccess.annotation().type.get())) + { + // no-op + } else _memberAccess.expression().accept(*this); } -- cgit v1.2.3 From acba7b92e5456d14bda1db8b3c71909d6d49c53f Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 21 Oct 2016 20:02:31 +0200 Subject: codegen: if a member access has been resolved as a variable, follow that This fixes at least the first example in #988 --- libsolidity/codegen/ExpressionCompiler.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index da3e56cc..1cb74c06 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -888,6 +888,18 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) { // no-op } + else if (auto variable = dynamic_cast(_memberAccess.annotation().referencedDeclaration)) + { + // TODO duplicate code should be unified + + if (!variable->isConstant()) + setLValueFromDeclaration(*_memberAccess.annotation().referencedDeclaration, _memberAccess); + else + { + variable->value()->accept(*this); + utils().convertType(*variable->value()->annotation().type, *variable->annotation().type); + } + } else _memberAccess.expression().accept(*this); } -- cgit v1.2.3 From 5245a3cf744260be3b4b02bed56759ed89ffc89a Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 21 Oct 2016 20:16:21 +0200 Subject: codegen: refactor common code --- libsolidity/codegen/ExpressionCompiler.cpp | 33 ++++++++++++------------------ libsolidity/codegen/ExpressionCompiler.h | 2 ++ 2 files changed, 15 insertions(+), 20 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 1cb74c06..98b7f6e5 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -889,17 +889,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) // no-op } else if (auto variable = dynamic_cast(_memberAccess.annotation().referencedDeclaration)) - { - // TODO duplicate code should be unified - - if (!variable->isConstant()) - setLValueFromDeclaration(*_memberAccess.annotation().referencedDeclaration, _memberAccess); - else - { - variable->value()->accept(*this); - utils().convertType(*variable->value()->annotation().type, *variable->annotation().type); - } - } + appendVariable(*variable, static_cast(_memberAccess)); else _memberAccess.expression().accept(*this); } @@ -1213,15 +1203,7 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier) else if (FunctionDefinition const* functionDef = dynamic_cast(declaration)) m_context << m_context.virtualFunctionEntryLabel(*functionDef).pushTag(); else if (auto variable = dynamic_cast(declaration)) - { - if (!variable->isConstant()) - setLValueFromDeclaration(*declaration, _identifier); - else - { - variable->value()->accept(*this); - utils().convertType(*variable->value()->annotation().type, *variable->annotation().type); - } - } + appendVariable(*variable, static_cast(_identifier)); else if (auto contract = dynamic_cast(declaration)) { if (contract->isLibrary()) @@ -1650,6 +1632,17 @@ void ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType, utils().storeInMemoryDynamic(_expectedType); } +void ExpressionCompiler::appendVariable(VariableDeclaration const& _variable, Expression const& _expression) +{ + if (!_variable.isConstant()) + setLValueFromDeclaration(_variable, _expression); + else + { + _variable.value()->accept(*this); + utils().convertType(*_variable.value()->annotation().type, *_variable.annotation().type); + } +} + void ExpressionCompiler::setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression) { if (m_context.isLocalVariable(&_declaration)) diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h index 43a92a10..f4ce1fec 100644 --- a/libsolidity/codegen/ExpressionCompiler.h +++ b/libsolidity/codegen/ExpressionCompiler.h @@ -103,6 +103,8 @@ private: /// expected to be on the stack and is updated by this call. void appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression); + /// Appends code for a variable that might be a constant or not + void appendVariable(VariableDeclaration const& _variable, Expression const& _expression); /// Sets the current LValue to a new one (of the appropriate type) from the given declaration. /// Also retrieves the value if it was not requested by @a _expression. void setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression); -- cgit v1.2.3 From f25aa0c68bd8d4c2acf9425c9aba15fc56b16ccc Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 21 Oct 2016 12:30:58 +0200 Subject: More checks for missing mobile type. --- libsolidity/codegen/CompilerUtils.cpp | 3 +++ libsolidity/codegen/ExpressionCompiler.cpp | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'libsolidity/codegen') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index ec496df8..e064c1a6 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -368,8 +368,11 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp m_context << (u256(1) << (256 - targetBytesType.numBytes() * 8)) << Instruction::MUL; } else if (targetTypeCategory == Type::Category::Enum) + { + solAssert(_typeOnStack.mobileType(), ""); // just clean convertType(_typeOnStack, *_typeOnStack.mobileType(), true); + } else if (targetTypeCategory == Type::Category::FixedPoint) { solAssert( diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index da3e56cc..6d54b48b 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -56,8 +56,10 @@ void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration c if (_varDecl.annotation().type->dataStoredIn(DataLocation::Storage)) { // reference type, only convert value to mobile type and do final conversion in storeValue. - utils().convertType(*type, *type->mobileType()); - type = type->mobileType(); + auto mt = type->mobileType(); + solAssert(mt, ""); + utils().convertType(*type, *mt); + type = mt; } else { @@ -1437,11 +1439,17 @@ void ExpressionCompiler::appendExternalFunctionCall( // Evaluate arguments. TypePointers argumentTypes; TypePointers parameterTypes = _functionType.parameterTypes(); - bool manualFunctionId = + bool manualFunctionId = false; + if ( (funKind == FunctionKind::Bare || funKind == FunctionKind::BareCallCode || funKind == FunctionKind::BareDelegateCall) && - !_arguments.empty() && - _arguments.front()->annotation().type->mobileType()->calldataEncodedSize(false) == + !_arguments.empty() + ) + { + solAssert(_arguments.front()->annotation().type->mobileType(), ""); + manualFunctionId = + _arguments.front()->annotation().type->mobileType()->calldataEncodedSize(false) == CompilerUtils::dataStartOffset; + } if (manualFunctionId) { // If we have a Bare* and the first type has exactly 4 bytes, use it as -- cgit v1.2.3