Fix calldata index access.

This commit is contained in:
chriseth 2020-11-11 18:41:38 +01:00
parent 826ed58b2f
commit 8f570a3184
2 changed files with 11 additions and 10 deletions

View File

@ -1998,28 +1998,27 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess)
}
case DataLocation::CallData:
{
IRVariable var(m_context.newYulVariable(), *arrayType.baseType());
define(var) <<
m_utils.calldataArrayIndexAccessFunction(arrayType) <<
"(" <<
IRVariable(_indexAccess.baseExpression()).commaSeparatedList() <<
", " <<
expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) <<
string const indexAccessFunctionCall =
m_utils.calldataArrayIndexAccessFunction(arrayType) +
"(" +
IRVariable(_indexAccess.baseExpression()).commaSeparatedList() +
", " +
expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) +
")\n";
if (arrayType.isByteArray())
define(_indexAccess) <<
m_utils.cleanupFunction(*arrayType.baseType()) <<
"(calldataload(" <<
var.name() <<
indexAccessFunctionCall <<
"))\n";
else if (arrayType.baseType()->isValueType())
define(_indexAccess) <<
m_utils.readFromCalldata(*arrayType.baseType()) <<
"(" <<
var.commaSeparatedList() <<
indexAccessFunctionCall <<
")\n";
else
define(_indexAccess, var);
define(_indexAccess) << indexAccessFunctionCall;
break;
}
}

View File

@ -25,6 +25,8 @@ contract C {
return reenc ? this.f_reenc(a) : this.f(a);
}
}
// ====
// compileViaYul: also
// ----
// g(bool): false -> 23, 37, 71
// g(bool): true -> 23, 37, 71