aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-11-14 18:11:39 +0800
committerYoichi Hirai <i@yoichihirai.com>2016-11-14 18:11:39 +0800
commit81f5734cbe029b93aa143e5eb7f57869ab63af7b (patch)
treefb525d37e91b5d3711250bb1ea8a943bc19d9730 /libsolidity
parent20c2ca39922f4230b504888644d04f4bc8d6b8f3 (diff)
downloaddexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.tar
dexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.tar.gz
dexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.tar.bz2
dexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.tar.lz
dexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.tar.xz
dexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.tar.zst
dexon-solidity-81f5734cbe029b93aa143e5eb7f57869ab63af7b.zip
codegen: move the enum overflow checking closer to the conversion into enums
Diffstat (limited to 'libsolidity')
-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)