From 4bd078ed7e92698d1250a0d73cf66e4a02c0d000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 30 May 2020 00:32:35 +0200 Subject: [PATCH] CommandLineInterface: Disallow --output-dir, --gas and --combined-json in assembly mode --- solc/CommandLineInterface.cpp | 26 ++++++++++++------- .../strict_asm_invalid_option_output_dir/args | 1 + .../strict_asm_invalid_option_output_dir/err | 1 + .../strict_asm_invalid_option_output_dir/exit | 1 + .../input.yul | 3 +++ 5 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 test/cmdlineTests/strict_asm_invalid_option_output_dir/args create mode 100644 test/cmdlineTests/strict_asm_invalid_option_output_dir/err create mode 100644 test/cmdlineTests/strict_asm_invalid_option_output_dir/exit create mode 100644 test/cmdlineTests/strict_asm_invalid_option_output_dir/input.yul diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 712740cd0..bbf0eeb53 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1190,6 +1190,22 @@ bool CommandLineInterface::processInput() if (m_args.count(g_argAssemble) || m_args.count(g_argStrictAssembly) || m_args.count(g_argYul)) { + vector 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; @@ -1197,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 yulOptimiserSteps; if (m_args.count(g_strYulOptimizations)) diff --git a/test/cmdlineTests/strict_asm_invalid_option_output_dir/args b/test/cmdlineTests/strict_asm_invalid_option_output_dir/args new file mode 100644 index 000000000..ba341ccc5 --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_output_dir/args @@ -0,0 +1 @@ +--strict-assembly --output-dir /tmp/ diff --git a/test/cmdlineTests/strict_asm_invalid_option_output_dir/err b/test/cmdlineTests/strict_asm_invalid_option_output_dir/err new file mode 100644 index 000000000..a9b56e9c7 --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_output_dir/err @@ -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. diff --git a/test/cmdlineTests/strict_asm_invalid_option_output_dir/exit b/test/cmdlineTests/strict_asm_invalid_option_output_dir/exit new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_output_dir/exit @@ -0,0 +1 @@ +1 diff --git a/test/cmdlineTests/strict_asm_invalid_option_output_dir/input.yul b/test/cmdlineTests/strict_asm_invalid_option_output_dir/input.yul new file mode 100644 index 000000000..f21cd2b7e --- /dev/null +++ b/test/cmdlineTests/strict_asm_invalid_option_output_dir/input.yul @@ -0,0 +1,3 @@ +{ + sstore(0, 1) +}