From 767ec1d670808cd479ac74780bff51a1f1900f04 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 1 Dec 2016 12:12:10 +0000 Subject: Support explicit conversion of external function type to address --- libsolidity/codegen/CompilerUtils.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 477f021a..469bd0ed 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -787,6 +787,18 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp if (_cleanupNeeded) m_context << Instruction::ISZERO << Instruction::ISZERO; break; + case Type::Category::Function: + { + solAssert(targetTypeCategory == Type::Category::Integer, "Invalid conversion for function type."); + IntegerType const& targetType = dynamic_cast(_targetType); + solAssert(targetType.isAddress(), "Function type can only be converted to address."); + FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); + solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted."); + + // stack:
+ m_context << Instruction::POP; + break; + } default: // All other types should not be convertible to non-equal types. solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); -- cgit v1.2.3 From 4361797ddca240dc55c9f88c6579383eb558b309 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 1 Feb 2017 12:22:14 +0000 Subject: Only capture function type to address conversion --- libsolidity/codegen/CompilerUtils.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 469bd0ed..9f019d27 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -789,15 +789,17 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp break; case Type::Category::Function: { - solAssert(targetTypeCategory == Type::Category::Integer, "Invalid conversion for function type."); - IntegerType const& targetType = dynamic_cast(_targetType); - solAssert(targetType.isAddress(), "Function type can only be converted to address."); - FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); - solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted."); + if (targetTypeCategory == Type::Category::Integer) + { + IntegerType const& targetType = dynamic_cast(_targetType); + solAssert(targetType.isAddress(), "Function type can only be converted to address."); + FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); + solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted."); - // stack:
- m_context << Instruction::POP; - break; + // stack:
+ m_context << Instruction::POP; + break; + } } default: // All other types should not be convertible to non-equal types. -- cgit v1.2.3 From ba0015cf256b3cf5f90a0daf225072286d8d3da4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 01:29:24 +0000 Subject: Warn early when exhausting stack --- libsolidity/codegen/CompilerUtils.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'libsolidity/codegen/CompilerUtils.cpp') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 9f019d27..42323abd 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -200,6 +200,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."); } else { -- cgit v1.2.3