Skip to content

Commit 2536b14

Browse files
authored
Merge pull request #15934 from ethereum/default-initialize-instruction-in-assembly-item
AssemblyItem gets an optional instruction
2 parents 28982f1 + 08c9f53 commit 2536b14

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

libevmasm/AssemblyItem.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class AssemblyItem
105105

106106
explicit AssemblyItem(bytes _verbatimData, size_t _arguments, size_t _returnVariables):
107107
m_type(VerbatimBytecode),
108-
m_instruction{},
109108
m_verbatimBytecode{{_arguments, _returnVariables, std::move(_verbatimData)}},
110109
m_debugData{langutil::DebugData::create()}
111110
{}
@@ -195,7 +194,7 @@ class AssemblyItem
195194
/// @returns true if the item has m_instruction properly set.
196195
bool hasInstruction() const
197196
{
198-
return
197+
bool const shouldHaveInstruction =
199198
m_type == Operation ||
200199
m_type == EOFCreate ||
201200
m_type == ReturnContract ||
@@ -206,12 +205,14 @@ class AssemblyItem
206205
m_type == RetF ||
207206
m_type == SwapN ||
208207
m_type == DupN;
208+
solAssert(shouldHaveInstruction == m_instruction.has_value());
209+
return shouldHaveInstruction;
209210
}
210211
/// @returns the instruction of this item (only valid if hasInstruction returns true)
211212
Instruction instruction() const
212213
{
213214
solAssert(hasInstruction());
214-
return m_instruction;
215+
return *m_instruction;
215216
}
216217

217218
/// @returns true if the type and data of the items are equal.
@@ -323,7 +324,7 @@ class AssemblyItem
323324
size_t opcodeCount() const noexcept;
324325

325326
AssemblyItemType m_type;
326-
Instruction m_instruction; ///< Only valid if m_type == Operation
327+
std::optional<Instruction> m_instruction; ///< Only valid for item types that represent a specific opcode
327328
std::shared_ptr<u256> m_data; ///< Only valid if m_type != Operation
328329
std::optional<FunctionSignature> m_functionSignature; ///< Only valid if m_type == CallF or JumpF
329330
/// If m_type == VerbatimBytecode, this holds number of arguments, number of

0 commit comments

Comments
 (0)