Merge pull request #8672 from ethereum/fixYulEmptyTupleAssign

Fix tuple assignments for empty tuples in Yul IR.
This commit is contained in:
Daniel Kirchner 2020-04-15 12:36:46 +02:00 committed by GitHub
commit 95349b3634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 24 deletions

View File

@ -2079,7 +2079,7 @@ string YulUtilFunctions::conversionFunctionSpecial(Type const& _from, Type const
{
conversions +=
suffixedVariableNameList("converted", destStackSize, destStackSize + toComponent->sizeOnStack()) +
" := " +
(toComponent->sizeOnStack() > 0 ? " := " : "") +
conversionFunction(*fromComponent, *toComponent) +
"(" +
suffixedVariableNameList("value", sourceStackSize, sourceStackSize + fromComponent->sizeOnStack()) +
@ -2089,12 +2089,13 @@ string YulUtilFunctions::conversionFunctionSpecial(Type const& _from, Type const
sourceStackSize += fromComponent->sizeOnStack();
}
return Whiskers(R"(
function <functionName>(<values>) -> <converted> {
function <functionName>(<values>) <arrow> <converted> {
<conversions>
}
)")
("functionName", functionName)
("values", suffixedVariableNameList("value", 0, sourceStackSize))
("arrow", destStackSize > 0 ? "->" : "")
("converted", suffixedVariableNameList("converted", 0, destStackSize))
("conversions", conversions)
.render();

View File

@ -1465,15 +1465,18 @@ void IRGeneratorForStatements::declareAssign(IRVariable const& _lhs, IRVariable
else
m_code << (_declare ? "let ": "") << _lhs.part(stackItemName).name() << " := " << _rhs.part(stackItemName).name() << "\n";
else
{
if (_lhs.type().sizeOnStack() > 0)
m_code <<
(_declare ? "let ": "") <<
_lhs.commaSeparatedList() <<
" := " <<
m_context.utils().conversionFunction(_rhs.type(), _lhs.type()) <<
" := ";
m_code << m_context.utils().conversionFunction(_rhs.type(), _lhs.type()) <<
"(" <<
_rhs.commaSeparatedList() <<
")\n";
}
}
IRVariable IRGeneratorForStatements::zeroValue(Type const& _type, bool _splitFunctionTypes)
{

View File

@ -15,6 +15,16 @@ contract test {
(((, a),)) = ((1, 2), 3);
return a;
}
function f3() public returns(int) {
int a = 3;
((, ), ) = ((7, 8), 9);
return a;
}
function f4() public returns(int) {
int a;
(a, ) = (4, (8, 16, 32));
return a;
}
}
// ====
// compileViaYul: also
@ -22,3 +32,5 @@ contract test {
// f0() -> 2, true
// f1() -> 1
// f2() -> 2
// f3() -> 3
// f4() -> 4

View File

@ -1,17 +0,0 @@
contract test {
function f3() public returns(int) {
int a = 3;
((, ), ) = ((7, 8), 9);
return a;
}
function f4() public returns(int) {
int a;
(a, ) = (4, (8, 16, 32));
return a;
}
}
// ====
// compileViaYul: false
// ----
// f3() -> 3
// f4() -> 4