From ade71d58f8c65086aa2cf02161f429080a5fb629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 10 Nov 2020 14:26:29 +0100 Subject: [PATCH] Assume that enums always take 1-byte in the codegen and type system --- libsolidity/ast/Types.cpp | 10 ++++------ libsolidity/codegen/YulUtilFunctions.cpp | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index b21d867ca..80c3b5ef0 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2629,7 +2629,8 @@ vector StructType::decomposition() const TypePointer EnumType::encodingType() const { - return TypeProvider::uint(8 * storageBytes()); + solAssert(numberOfMembers() <= 256, ""); + return TypeProvider::uint(8); } TypeResult EnumType::unaryOperatorResult(Token _operator) const @@ -2652,11 +2653,8 @@ bool EnumType::operator==(Type const& _other) const unsigned EnumType::storageBytes() const { - size_t elements = numberOfMembers(); - if (elements <= 1) - return 1; - else - return util::bytesRequired(elements - 1); + solAssert(numberOfMembers() <= 256, ""); + return 1; } string EnumType::toString(bool) const diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index 7f1e08b8a..9bb884305 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -203,8 +203,8 @@ string YulUtilFunctions::leftAlignFunction(Type const& _type) break; case Type::Category::Enum: { - unsigned storageBytes = dynamic_cast(_type).storageBytes(); - templ("body", "aligned := " + leftAlignFunction(IntegerType(8 * storageBytes)) + "(value)"); + solAssert(dynamic_cast(_type).storageBytes() == 1, ""); + templ("body", "aligned := " + leftAlignFunction(IntegerType(8)) + "(value)"); break; } case Type::Category::InaccessibleDynamic: