Ensure we fail gracefully when user tries to optimize Yul code

This commit is contained in:
Bhargava Shastry 2019-02-06 14:39:43 +01:00
parent 0b392fff7e
commit 7751fa740f
4 changed files with 6 additions and 7 deletions

View File

@ -6,6 +6,7 @@ Bugfixes:
* Type Checker: Dissallow mappings with data locations other than 'storage'
* Type Checker: Fix internal error when a struct array index does not fit into a uint256.
* Type system: Properly report packed encoded size for arrays and structs (mostly unused until now).
* Commandline interface: Allow yul optimizer only for strict assembly.
Language Features:

View File

@ -84,7 +84,8 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
void AssemblyStack::optimize()
{
solAssert(m_language != Language::Assembly, "Optimization requested for loose assembly.");
if (m_language != Language::StrictAssembly)
solUnimplemented("Optimizer for both loose assembly and Yul is not yet implemented");
solAssert(m_analysisSuccessful, "Analysis was not successful.");
m_analysisSuccessful = false;
optimize(*m_parserResult);

View File

@ -861,13 +861,11 @@ bool CommandLineInterface::processInput()
return false;
}
}
if (optimize && inputLanguage == Input::Assembly)
if (optimize && inputLanguage != Input::StrictAssembly)
{
serr() <<
"Optimizer cannot be used for loose assembly. Use --" <<
"Optimizer can only be used for strict assembly. Use --" <<
g_strStrictAssembly <<
" or --" <<
g_strYul <<
"." <<
endl;
return false;

View File

@ -332,13 +332,12 @@ printTask "Testing assemble, yul, strict-assembly and optimize..."
# Test options above in conjunction with --optimize.
# Using both, --assemble and --optimize should fail.
! echo '{}' | "$SOLC" - --assemble --optimize &>/dev/null
! echo '{}' | "$SOLC" - --yul --optimize &>/dev/null
# Test yul and strict assembly output
# Non-empty code results in non-empty binary representation with optimizations turned off,
# while it results in empty binary representation with optimizations turned on.
test_solc_assembly_output "{ let x:u256 := 0:u256 }" "{ let x:u256 := 0:u256 }" "--yul"
test_solc_assembly_output "{ let x:u256 := 0:u256 }" "{ }" "--yul --optimize"
test_solc_assembly_output "{ let x := 0 }" "{ let x := 0 }" "--strict-assembly"
test_solc_assembly_output "{ let x := 0 }" "{ }" "--strict-assembly --optimize"
)