Merge pull request #12016 from ethereum/external-fp-10358

Add ``.address`` and ``.selector`` in inside assembly for external function pointers
This commit is contained in:
chriseth
2021-10-05 14:48:58 +02:00
committed by GitHub
16 changed files with 211 additions and 5 deletions
+20
View File
@@ -823,6 +823,16 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
if (suffix == "length")
stackDiff--;
}
else if (
auto const* functionType = dynamic_cast<FunctionType const*>(variable->type());
functionType && functionType->kind() == FunctionType::Kind::External
)
{
solAssert(suffix == "selector" || suffix == "address", "");
solAssert(variable->type()->sizeOnStack() == 2, "");
if (suffix == "selector")
stackDiff--;
}
else
solAssert(false, "");
}
@@ -889,6 +899,16 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
solAssert(suffix.empty(), "");
}
}
else if (
auto const* functionType = dynamic_cast<FunctionType const*>(variable->type());
functionType && functionType->kind() == FunctionType::Kind::External
)
{
solAssert(suffix == "selector" || suffix == "address", "");
solAssert(variable->type()->sizeOnStack() == 2, "");
if (suffix == "selector")
stackDiff--;
}
else
solAssert(suffix.empty(), "");
@@ -188,6 +188,18 @@ private:
solAssert(suffix == "offset" || suffix == "length", "");
value = IRVariable{*varDecl}.part(suffix).name();
}
else if (
auto const* functionType = dynamic_cast<FunctionType const*>(varDecl->type());
functionType && functionType->kind() == FunctionType::Kind::External
)
{
solAssert(suffix == "selector" || suffix == "address", "");
solAssert(varDecl->type()->sizeOnStack() == 2, "");
if (suffix == "selector")
value = IRVariable{*varDecl}.part("functionSelector").name();
else
value = IRVariable{*varDecl}.part("address").name();
}
else
solAssert(false, "");