mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adding fixes for signedness conversion warnings in libyul
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
co-authored by
Kamil Śliwak
parent
21a9d3dd21
commit
33e7b24df0
@@ -112,7 +112,7 @@ void WordSizeTransform::operator()(Block& _block)
|
||||
yulAssert(varDecl.variables.size() == 1, "");
|
||||
auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name);
|
||||
vector<Statement> ret;
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
ret.emplace_back(VariableDeclaration{
|
||||
varDecl.location,
|
||||
{TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}},
|
||||
@@ -143,7 +143,7 @@ void WordSizeTransform::operator()(Block& _block)
|
||||
auto newRhs = expandValue(*varDecl.value);
|
||||
auto newLhs = generateU64IdentifierNames(varDecl.variables[0].name);
|
||||
vector<Statement> ret;
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
ret.emplace_back(VariableDeclaration{
|
||||
varDecl.location,
|
||||
{TypedName{varDecl.location, newLhs[i], m_targetDialect.defaultType}},
|
||||
@@ -172,7 +172,7 @@ void WordSizeTransform::operator()(Block& _block)
|
||||
yulAssert(assignment.variableNames.size() == 1, "");
|
||||
auto newLhs = generateU64IdentifierNames(assignment.variableNames[0].name);
|
||||
vector<Statement> ret;
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
ret.emplace_back(Assignment{
|
||||
assignment.location,
|
||||
{Identifier{assignment.location, newLhs[i]}},
|
||||
@@ -203,7 +203,7 @@ void WordSizeTransform::operator()(Block& _block)
|
||||
auto newRhs = expandValue(*assignment.value);
|
||||
YulString lhsName = assignment.variableNames[0].name;
|
||||
vector<Statement> ret;
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
ret.emplace_back(Assignment{
|
||||
assignment.location,
|
||||
{Identifier{assignment.location, m_variableMapping.at(lhsName)[i]}},
|
||||
@@ -382,7 +382,7 @@ std::vector<Statement> WordSizeTransform::handleSwitch(Switch& _switch)
|
||||
array<YulString, 4> WordSizeTransform::generateU64IdentifierNames(YulString const& _s)
|
||||
{
|
||||
yulAssert(m_variableMapping.find(_s) == m_variableMapping.end(), "");
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
m_variableMapping[_s][i] = m_nameDispenser.newName(YulString{_s.str() + "_" + to_string(i)});
|
||||
return m_variableMapping[_s];
|
||||
}
|
||||
@@ -392,19 +392,20 @@ array<unique_ptr<Expression>, 4> WordSizeTransform::expandValue(Expression const
|
||||
array<unique_ptr<Expression>, 4> ret;
|
||||
if (holds_alternative<Identifier>(_e))
|
||||
{
|
||||
Identifier const& id = std::get<Identifier>(_e);
|
||||
for (int i = 0; i < 4; i++)
|
||||
auto const& id = std::get<Identifier>(_e);
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
ret[i] = make_unique<Expression>(Identifier{id.location, m_variableMapping.at(id.name)[i]});
|
||||
}
|
||||
else if (holds_alternative<Literal>(_e))
|
||||
{
|
||||
Literal const& lit = std::get<Literal>(_e);
|
||||
auto const& lit = std::get<Literal>(_e);
|
||||
u256 val = valueOfLiteral(lit);
|
||||
for (int i = 3; i >= 0; i--)
|
||||
for (size_t exprIndex = 0; exprIndex < 4; ++exprIndex)
|
||||
{
|
||||
size_t exprIndexReverse = 3 - exprIndex;
|
||||
u256 currentVal = val & std::numeric_limits<uint64_t>::max();
|
||||
val >>= 64;
|
||||
ret[i] = make_unique<Expression>(
|
||||
ret[exprIndexReverse] = make_unique<Expression>(
|
||||
Literal{
|
||||
lit.location,
|
||||
LiteralKind::Number,
|
||||
@@ -426,4 +427,3 @@ vector<Expression> WordSizeTransform::expandValueToVector(Expression const& _e)
|
||||
ret.emplace_back(std::move(*val));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user