mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9075 from ethereum/commandline-invalid-asm-mode-options
Disallow invalid command-line option combinations in assembly mode
This commit is contained in:
commit
4b3ae0b206
@ -5,6 +5,7 @@ Language Features:
|
||||
|
||||
Compiler Features:
|
||||
* NatSpec: Add fields "kind" and "version" to the JSON output.
|
||||
* Commandline Interface: Prevent some incompatible commandline options from being used together.
|
||||
|
||||
|
||||
Bugfixes:
|
||||
|
@ -58,6 +58,7 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#ifdef _WIN32 // windows
|
||||
@ -1129,6 +1130,21 @@ bool CommandLineInterface::processInput()
|
||||
}
|
||||
}
|
||||
|
||||
vector<string> const exclusiveModes = {
|
||||
g_argStandardJSON,
|
||||
g_argLink,
|
||||
g_argAssemble,
|
||||
g_argStrictAssembly,
|
||||
g_argYul,
|
||||
g_argImportAst,
|
||||
};
|
||||
if (countEnabledOptions(exclusiveModes) > 1)
|
||||
{
|
||||
serr() << "The following options are mutually exclusive: " << joinOptionNames(exclusiveModes) << ". ";
|
||||
serr() << "Select at most one." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_args.count(g_argStandardJSON))
|
||||
{
|
||||
vector<string> inputFiles;
|
||||
@ -1174,6 +1190,22 @@ bool CommandLineInterface::processInput()
|
||||
|
||||
if (m_args.count(g_argAssemble) || m_args.count(g_argStrictAssembly) || m_args.count(g_argYul))
|
||||
{
|
||||
vector<string> const nonAssemblyModeOptions = {
|
||||
// TODO: The list is not complete. Add more.
|
||||
g_argOutputDir,
|
||||
g_argGas,
|
||||
g_argCombinedJson,
|
||||
g_strOptimizeYul,
|
||||
g_strNoOptimizeYul,
|
||||
};
|
||||
if (countEnabledOptions(nonAssemblyModeOptions) >= 1)
|
||||
{
|
||||
serr() << "The following options are invalid in assembly mode: ";
|
||||
serr() << joinOptionNames(nonAssemblyModeOptions) << ". ";
|
||||
serr() << "Optimization is disabled by default and can be enabled with --" << g_argOptimize << "." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// switch to assembly mode
|
||||
m_onlyAssemble = true;
|
||||
using Input = yul::AssemblyStack::Language;
|
||||
@ -1181,16 +1213,6 @@ bool CommandLineInterface::processInput()
|
||||
Input inputLanguage = m_args.count(g_argYul) ? Input::Yul : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly);
|
||||
Machine targetMachine = Machine::EVM;
|
||||
bool optimize = m_args.count(g_argOptimize);
|
||||
if (m_args.count(g_strOptimizeYul))
|
||||
{
|
||||
serr() << "--" << g_strOptimizeYul << " is invalid in assembly mode. Use --" << g_argOptimize << " instead." << endl;
|
||||
return false;
|
||||
}
|
||||
if (m_args.count(g_strNoOptimizeYul))
|
||||
{
|
||||
serr() << "--" << g_strNoOptimizeYul << " is invalid in assembly mode. Optimization is disabled by default and can be enabled with --" << g_argOptimize << "." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
optional<string> yulOptimiserSteps;
|
||||
if (m_args.count(g_strYulOptimizations))
|
||||
@ -1273,6 +1295,13 @@ bool CommandLineInterface::processInput()
|
||||
|
||||
return assemble(inputLanguage, targetMachine, optimize, yulOptimiserSteps);
|
||||
}
|
||||
else if (countEnabledOptions({g_strYulDialect, g_argMachine}) >= 1)
|
||||
{
|
||||
serr() << "--" << g_strYulDialect << " and --" << g_argMachine << " ";
|
||||
serr() << "are only valid in assembly mode." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_args.count(g_argLink))
|
||||
{
|
||||
// switch to linker mode
|
||||
@ -1879,4 +1908,21 @@ void CommandLineInterface::outputCompilationResults()
|
||||
}
|
||||
}
|
||||
|
||||
size_t CommandLineInterface::countEnabledOptions(vector<string> const& _optionNames) const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (string const& _option: _optionNames)
|
||||
count += m_args.count(_option);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
string CommandLineInterface::joinOptionNames(vector<string> const& _optionNames, string _separator)
|
||||
{
|
||||
return boost::algorithm::join(
|
||||
_optionNames | boost::adaptors::transformed([](string const& _option){ return "--" + _option; }),
|
||||
_separator
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,6 +103,9 @@ private:
|
||||
/// @arg _json json string to be written
|
||||
void createJson(std::string const& _fileName, std::string const& _json);
|
||||
|
||||
size_t countEnabledOptions(std::vector<std::string> const& _optionNames) const;
|
||||
static std::string joinOptionNames(std::vector<std::string> const& _optionNames, std::string _separator = ", ");
|
||||
|
||||
bool m_error = false; ///< If true, some error occurred.
|
||||
|
||||
bool m_onlyAssemble = false;
|
||||
|
@ -0,0 +1 @@
|
||||
--strict-assembly --output-dir /tmp/
|
@ -0,0 +1 @@
|
||||
The following options are invalid in assembly mode: --output-dir, --gas, --combined-json, --optimize-yul, --no-optimize-yul. Optimization is disabled by default and can be enabled with --optimize.
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
sstore(0, 1)
|
||||
}
|
@ -0,0 +1 @@
|
||||
--yul-dialect evm --machine ewasm
|
1
test/cmdlineTests/strict_asm_options_in_non_asm_mode/err
Normal file
1
test/cmdlineTests/strict_asm_options_in_non_asm_mode/err
Normal file
@ -0,0 +1 @@
|
||||
--yul-dialect and --machine are only valid in assembly mode.
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
|
||||
contract C
|
||||
{
|
||||
function f() public pure {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user