From 356b9a7904759c0763d566b5c8ba7a72707da64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 2 Jul 2020 14:14:36 +0200 Subject: [PATCH] Restrict `linkersymbol` builtin to object dialect of Yul --- libyul/backends/evm/EVMDialect.cpp | 21 +++++++++---------- .../inlineAssembly/linkersymbol_builtin.sol | 10 +++++++++ .../inlineAssembly/linkersymbol_function.sol | 10 +++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_builtin.sol create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_function.sol diff --git a/libyul/backends/evm/EVMDialect.cpp b/libyul/backends/evm/EVMDialect.cpp index b6a46043e..342c0e6ed 100644 --- a/libyul/backends/evm/EVMDialect.cpp +++ b/libyul/backends/evm/EVMDialect.cpp @@ -124,19 +124,18 @@ map createBuiltins(langutil::EVMVersion _evmVe ) builtins.emplace(createEVMFunction(instr.first, instr.second)); - builtins.emplace(createFunction("linkersymbol", 1, 1, SideEffects{}, {true}, []( - FunctionCall const& _call, - AbstractAssembly& _assembly, - BuiltinContext&, - function - ) { - yulAssert(_call.arguments.size() == 1, ""); - Expression const& arg = _call.arguments.front(); - _assembly.appendLinkerSymbol(std::get(arg).value.str()); - })); - if (_objectAccess) { + builtins.emplace(createFunction("linkersymbol", 1, 1, SideEffects{}, {true}, []( + FunctionCall const& _call, + AbstractAssembly& _assembly, + BuiltinContext&, + function + ) { + yulAssert(_call.arguments.size() == 1, ""); + Expression const& arg = _call.arguments.front(); + _assembly.appendLinkerSymbol(std::get(arg).value.str()); + })); builtins.emplace(createFunction("datasize", 1, 1, SideEffects{}, {true}, []( FunctionCall const& _call, AbstractAssembly& _assembly, diff --git a/test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_builtin.sol b/test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_builtin.sol new file mode 100644 index 000000000..9f761f187 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_builtin.sol @@ -0,0 +1,10 @@ +contract C { + function f() public pure { + assembly { + pop(linkersymbol("contract/library.sol:L")) + } + } +} +// ---- +// DeclarationError 4619: (67-79): Function not found. +// TypeError 3950: (67-105): Expected expression to evaluate to one value, but got 0 values instead. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_function.sol b/test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_function.sol new file mode 100644 index 000000000..9d1d6c4f3 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/linkersymbol_function.sol @@ -0,0 +1,10 @@ +contract C { + function f() public pure { + assembly { + function linkersymbol(a) {} + + linkersymbol("contract/library.sol:L") + } + } +} +// ----