From 207b4fbeec7dc0979e4f96eb347c6ab02134982a Mon Sep 17 00:00:00 2001 From: Marenz Date: Thu, 7 Oct 2021 18:11:19 +0200 Subject: [PATCH] PR fixes --- Changelog.md | 2 +- libevmasm/AssemblyItem.cpp | 13 ++++++------- libevmasm/AssemblyItem.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Changelog.md b/Changelog.md index bd0fa5554..b6b2b500f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ Compiler Features: Bugfixes: + * Code Generator: Fixes source mappings for immutables. * Commandline Interface: Fix extra newline character being appended to sources passed through standard input, affecting their hashes. * SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``). * TypeChecker: Fix internal error when using user defined value types in public library functions. @@ -27,7 +28,6 @@ Important Bugfixes: Bugfixes: * AST: Export ``canonicalName`` for ``UserDefinedValueTypeDefinition`` and ``ContractDefinition``. - * Code Generator: Fixes source mappings for immutables. diff --git a/libevmasm/AssemblyItem.cpp b/libevmasm/AssemblyItem.cpp index 10afe8015..97d60fd4d 100644 --- a/libevmasm/AssemblyItem.cpp +++ b/libevmasm/AssemblyItem.cpp @@ -87,9 +87,9 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength) const case PushImmutable: return 1 + 32; case AssignImmutable: - if (!m_immutableOccurrences) - return 0; - else if (m_immutableOccurrences.value() != 0) + solAssert(m_immutableOccurrences, ""); + + if (m_immutableOccurrences.value() != 0) // (DUP DUP PUSH ADD MSTORE)* (PUSH ADD MSTORE) return (*m_immutableOccurrences - 1) * (5 + 32) + (3 + 32); else @@ -335,10 +335,9 @@ size_t AssemblyItem::opcodeCount() const noexcept // For n immutable occurrences the first (n - 1) occurrences will // generate 5 opcodes and the last will generate 3 opcodes, // because it is reusing the 2 top-most elements on the stack. - if (!m_immutableOccurrences) - // AssignImmutable without any uses does not need to be assigned to at all. - return 0; - else if (m_immutableOccurrences.value() != 0) + solAssert(m_immutableOccurrences, ""); + + if (m_immutableOccurrences.value() != 0) return (*m_immutableOccurrences - 1) * 5 + 3; else return 2; // two POP's diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h index 2a5966f9c..0f66a0a60 100644 --- a/libevmasm/AssemblyItem.h +++ b/libevmasm/AssemblyItem.h @@ -172,9 +172,9 @@ public: void setImmutableOccurrences(size_t _n) const { m_immutableOccurrences = _n; } +private: size_t opcodeCount() const noexcept; -private: AssemblyItemType m_type; Instruction m_instruction; ///< Only valid if m_type == Operation std::shared_ptr m_data; ///< Only valid if m_type != Operation