Use "if" instead of "switch" in codegen for the deployment time address of a library

This commit is contained in:
Alex Beregszaszi 2019-02-25 23:59:13 +00:00
parent 6b12726f51
commit bd51589f1a

View File

@ -177,6 +177,7 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract)
solAssert(m_context.runtimeSub() != size_t(-1), "Runtime sub not registered");
m_context.pushSubroutineSize(m_context.runtimeSub());
m_context.pushSubroutineOffset(m_context.runtimeSub());
// This code replaces the address added by appendDeployTimeAddress().
m_context.appendInlineAssembly(R"(
{
// If code starts at 11, an mstore(0) writes to the full PUSH20 plus data
@ -184,8 +185,7 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract)
let codepos := 11
codecopy(codepos, subOffset, subSize)
// Check that the first opcode is a PUSH20
switch eq(0x73, byte(0, mload(codepos)))
case 0 { invalid() }
if iszero(eq(0x73, byte(0, mload(codepos)))) { invalid() }
mstore(0, address())
mstore8(codepos, 0x73)
return(codepos, subSize)