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

View File

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

View File

@ -15,6 +15,16 @@ contract test {
(((, a),)) = ((1, 2), 3); (((, a),)) = ((1, 2), 3);
return a; 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 // compileViaYul: also
@ -22,3 +32,5 @@ contract test {
// f0() -> 2, true // f0() -> 2, true
// f1() -> 1 // f1() -> 1
// f2() -> 2 // 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