Skip to content

Commit

Permalink
Merge pull request #5944 from ethereum/fix_asmstack_opt_bug
Browse files Browse the repository at this point in the history
Modify language assertion in AssemblyStack::optimize
  • Loading branch information
chriseth committed Feb 12, 2019
2 parents 0b392ff + 7751fa7 commit f0f3498
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion libsolidity/interface/AssemblyStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions test/cmdlineTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit f0f3498

Please sign in to comment.