aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/CompilerUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/codegen/CompilerUtils.cpp')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 2f30f53e..dd133aea 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -315,6 +315,8 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
Type::Category stackTypeCategory = _typeOnStack.category();
Type::Category targetTypeCategory = _targetType.category();
+ bool enumOverflowCheckPending = (targetTypeCategory == Type::Category::Enum);
+
switch (stackTypeCategory)
{
case Type::Category::FixedBytes:
@@ -349,6 +351,14 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
break;
case Type::Category::Enum:
solAssert(_targetType == _typeOnStack || targetTypeCategory == Type::Category::Integer, "");
+ if (enumOverflowCheckPending)
+ {
+ EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType);
+ solAssert(enumType.numberOfMembers() > 0, "empty enum should have caused a parser error.");
+ m_context << u256(enumType.numberOfMembers() - 1) << Instruction::DUP2 << Instruction::GT;
+ m_context.appendConditionalJumpTo(m_context.errorTag());
+ enumOverflowCheckPending = false;
+ }
break;
case Type::Category::FixedPoint:
solAssert(false, "Not yet implemented - FixedPointType.");
@@ -372,6 +382,11 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
solAssert(_typeOnStack.mobileType(), "");
// just clean
convertType(_typeOnStack, *_typeOnStack.mobileType(), true);
+ EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType);
+ solAssert(enumType.numberOfMembers() > 0, "empty enum should have caused a parser error.");
+ m_context << u256(enumType.numberOfMembers() - 1) << Instruction::DUP2 << Instruction::GT;
+ m_context.appendConditionalJumpTo(m_context.errorTag());
+ enumOverflowCheckPending = false;
}
else if (targetTypeCategory == Type::Category::FixedPoint)
{
@@ -657,14 +672,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
break;
}
- // Check the conversion result fits in a range.
- if (targetTypeCategory == Type::Category::Enum)
- {
- EnumType const& enumType = dynamic_cast<decltype(enumType)>(_targetType);
- solAssert(enumType.numberOfMembers() > 0, "empty enum should have caused a parser error.");
- m_context << u256(enumType.numberOfMembers() - 1) << Instruction::DUP2 << Instruction::GT;
- m_context.appendConditionalJumpTo(m_context.errorTag());
- }
+ solAssert(!enumOverflowCheckPending, "enum overflow checking missing.");
}
void CompilerUtils::pushZeroValue(Type const& _type)