Makes array length access read-only.

This commit is contained in:
Erik Kundt
2019-11-19 16:09:21 +01:00
parent 94272d44aa
commit ecaed1030f
9 changed files with 13 additions and 143 deletions
@@ -800,14 +800,12 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
//m_context << Instruction::SWAP1 << Instruction::POP;
break;
case DataLocation::Storage:
setLValue(_memberAccess, make_unique<IRStorageArrayLength>(
m_context.utils(),
m_context.variable(_memberAccess.expression()),
*_memberAccess.annotation().type,
type
));
{
string slot = m_context.variable(_memberAccess.expression());
defineExpression(_memberAccess) <<
m_utils.arrayLengthFunction(type) + "(" + slot + ")\n";
break;
}
case DataLocation::Memory:
defineExpression(_memberAccess) <<
"mload(" <<
-33
View File
@@ -148,39 +148,6 @@ string IRStorageItem::setToZero() const
")\n";
}
IRStorageArrayLength::IRStorageArrayLength(
YulUtilFunctions _utils,
string _slot,
Type const& _type,
ArrayType const& _arrayType
):
IRLValue(std::move(_utils), &_type), m_arrayType(_arrayType), m_slot(move(_slot))
{
solAssert(*m_type == *TypeProvider::uint256(), "Must be uint256!");
}
string IRStorageArrayLength::retrieveValue() const
{
return m_utils.arrayLengthFunction(m_arrayType) + "(" + m_slot + ")";
}
string IRStorageArrayLength::storeValue(std::string const& _value, Type const& _type) const
{
solAssert(_type == *m_type, "Different type, but might not be an error.");
return m_utils.resizeDynamicArrayFunction(m_arrayType) +
"(" +
m_slot +
", " +
_value +
")\n";
}
string IRStorageArrayLength::setToZero() const
{
return storeValue("0", *TypeProvider::uint256());
}
IRMemoryItem::IRMemoryItem(
YulUtilFunctions _utils,
std::string _address,
-24
View File
@@ -110,30 +110,6 @@ private:
boost::variant<std::string, unsigned> const m_offset;
};
/**
* Reference to the "length" member of a dynamically-sized storage array. This is an LValue with special
* semantics since assignments to it might reduce its length and thus the array's members have to be
* deleted.
*/
class IRStorageArrayLength: public IRLValue
{
public:
IRStorageArrayLength(
YulUtilFunctions _utils,
std::string _slot,
Type const& _type,
ArrayType const& _arrayType
);
std::string retrieveValue() const override;
std::string storeValue(std::string const& _value, Type const& _type) const override;
std::string setToZero() const override;
private:
ArrayType const& m_arrayType;
std::string const m_slot;
};
class IRMemoryItem: public IRLValue
{
public: