mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Enable the -Wconversion warning
This commit is contained in:
@@ -146,4 +146,3 @@ set(sources
|
||||
|
||||
add_library(solidity ${sources})
|
||||
target_link_libraries(solidity PUBLIC yul evmasm langutil smtutil solutil Boost::boost)
|
||||
|
||||
|
||||
@@ -71,8 +71,7 @@ public:
|
||||
using KindCompareType = std::underlying_type<VariableOccurrence::Kind>::type;
|
||||
return
|
||||
std::make_pair(m_declaration.id(), static_cast<KindCompareType>(m_occurrenceKind)) <
|
||||
std::make_pair(_rhs.m_declaration.id(), static_cast<KindCompareType>(_rhs.m_occurrenceKind))
|
||||
;
|
||||
std::make_pair(_rhs.m_declaration.id(), static_cast<KindCompareType>(_rhs.m_occurrenceKind));
|
||||
}
|
||||
|
||||
VariableDeclaration const& declaration() const { return m_declaration; }
|
||||
|
||||
@@ -156,14 +156,14 @@ private:
|
||||
static std::string literalTokenKind(Token _token);
|
||||
static std::string type(Expression const& _expression);
|
||||
static std::string type(VariableDeclaration const& _varDecl);
|
||||
static int nodeId(ASTNode const& _node)
|
||||
static int64_t nodeId(ASTNode const& _node)
|
||||
{
|
||||
return _node.id();
|
||||
}
|
||||
template<class Container>
|
||||
static Json::Value getContainerIds(Container const& _container, bool _order = false)
|
||||
{
|
||||
std::vector<int> tmp;
|
||||
std::vector<int64_t> tmp;
|
||||
|
||||
for (auto const& element: _container)
|
||||
{
|
||||
@@ -174,7 +174,7 @@ private:
|
||||
std::sort(tmp.begin(), tmp.end());
|
||||
Json::Value json(Json::arrayValue);
|
||||
|
||||
for (int val: tmp)
|
||||
for (int64_t val: tmp)
|
||||
json.append(val);
|
||||
|
||||
return json;
|
||||
|
||||
@@ -368,7 +368,7 @@ RationalNumberType const* TypeProvider::rationalNumber(Literal const& _literal)
|
||||
{
|
||||
size_t const digitCount = _literal.valueWithoutUnderscores().length() - 2;
|
||||
if (digitCount % 2 == 0 && (digitCount / 2) <= 32)
|
||||
compatibleBytesType = fixedBytes(digitCount / 2);
|
||||
compatibleBytesType = fixedBytes(static_cast<unsigned>(digitCount / 2));
|
||||
}
|
||||
|
||||
return rationalNumber(std::get<1>(validLiteral), compatibleBytesType);
|
||||
|
||||
@@ -811,7 +811,7 @@ tuple<bool, rational> RationalNumberType::parseRational(string const& _value)
|
||||
denominator = bigint(string(fractionalBegin, _value.end()));
|
||||
denominator /= boost::multiprecision::pow(
|
||||
bigint(10),
|
||||
static_cast<size_t>(distance(radixPoint + 1, _value.end()))
|
||||
static_cast<unsigned>(distance(radixPoint + 1, _value.end()))
|
||||
);
|
||||
numerator = bigint(string(_value.begin(), radixPoint));
|
||||
value = numerator + denominator;
|
||||
|
||||
@@ -294,6 +294,7 @@ public:
|
||||
return *m_stackItems;
|
||||
}
|
||||
/// Total number of stack slots occupied by this type. This is the sum of ``sizeOnStack`` of all ``stackItems()``.
|
||||
// TODO: consider changing the return type to be size_t
|
||||
unsigned sizeOnStack() const
|
||||
{
|
||||
if (!m_stackSize)
|
||||
@@ -306,7 +307,7 @@ public:
|
||||
++sizeOnStack;
|
||||
m_stackSize = sizeOnStack;
|
||||
}
|
||||
return *m_stackSize;
|
||||
return static_cast<unsigned>(*m_stackSize);
|
||||
}
|
||||
/// If it is possible to initialize such a value in memory by just writing zeros
|
||||
/// of the size memoryHeadSize().
|
||||
|
||||
@@ -248,7 +248,7 @@ void CompilerContext::removeVariablesAboveStackHeight(unsigned _stackHeight)
|
||||
|
||||
unsigned CompilerContext::numberOfLocalVariables() const
|
||||
{
|
||||
return m_localVariables.size();
|
||||
return static_cast<unsigned>(m_localVariables.size());
|
||||
}
|
||||
|
||||
shared_ptr<evmasm::Assembly> CompilerContext::compiledContract(ContractDefinition const& _contract) const
|
||||
@@ -421,10 +421,10 @@ void CompilerContext::appendInlineAssembly(
|
||||
util::errinfo_comment("Stack too deep (" + to_string(stackDiff) + "), try removing local variables.")
|
||||
);
|
||||
if (_context == yul::IdentifierContext::RValue)
|
||||
_assembly.appendInstruction(dupInstruction(stackDiff));
|
||||
_assembly.appendInstruction(dupInstruction(static_cast<unsigned>(stackDiff)));
|
||||
else
|
||||
{
|
||||
_assembly.appendInstruction(swapInstruction(stackDiff));
|
||||
_assembly.appendInstruction(swapInstruction(static_cast<unsigned>(stackDiff)));
|
||||
_assembly.appendInstruction(Instruction::POP);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -928,7 +928,7 @@ void CompilerUtils::convertType(
|
||||
{
|
||||
auto const& arrayType = dynamic_cast<ArrayType const&>(_targetType);
|
||||
solAssert(arrayType.isByteArray(), "");
|
||||
unsigned storageSize = 32 + ((data.size() + 31) / 32) * 32;
|
||||
size_t storageSize = 32 + ((data.size() + 31) / 32) * 32;
|
||||
allocateMemory(storageSize);
|
||||
// stack: mempos
|
||||
m_context << Instruction::DUP1 << u256(data.size());
|
||||
|
||||
@@ -192,7 +192,7 @@ size_t ContractCompiler::packIntoContractCreator(ContractDefinition const& _cont
|
||||
auto const& immutables = contractType.immutableVariables();
|
||||
// Push all immutable values on the stack.
|
||||
for (auto const& immutable: immutables)
|
||||
CompilerUtils(m_context).loadFromMemory(m_context.immutableMemoryOffset(*immutable), *immutable->annotation().type);
|
||||
CompilerUtils(m_context).loadFromMemory(static_cast<unsigned>(m_context.immutableMemoryOffset(*immutable)), *immutable->annotation().type);
|
||||
m_context.pushSubroutineSize(m_context.runtimeSub());
|
||||
if (immutables.empty())
|
||||
m_context << Instruction::DUP1;
|
||||
@@ -662,7 +662,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_context << swapInstruction(stackLayout.size() - static_cast<unsigned>(stackLayout.back()) - 1u);
|
||||
m_context << swapInstruction(static_cast<unsigned>(stackLayout.size()) - static_cast<unsigned>(stackLayout.back()) - 1u);
|
||||
swap(stackLayout[static_cast<size_t>(stackLayout.back())], stackLayout.back());
|
||||
}
|
||||
for (size_t i = 0; i < stackLayout.size(); ++i)
|
||||
|
||||
@@ -131,7 +131,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
|
||||
// stack: <keys..> <slot position>
|
||||
|
||||
// copy key[i] to top.
|
||||
utils().copyToStackTop(paramTypes.size() - i + 1, 1);
|
||||
utils().copyToStackTop(static_cast<unsigned>(paramTypes.size() - i + 1), 1);
|
||||
|
||||
m_context.appendInlineAssembly(R"({
|
||||
let key_len := mload(key_ptr)
|
||||
@@ -155,7 +155,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
|
||||
utils().storeInMemory(32);
|
||||
|
||||
// move key to memory.
|
||||
utils().copyToStackTop(paramTypes.size() - i, 1);
|
||||
utils().copyToStackTop(static_cast<unsigned>(paramTypes.size() - i), 1);
|
||||
utils().storeInMemory(0);
|
||||
m_context << u256(64) << u256(0);
|
||||
m_context << Instruction::KECCAK256;
|
||||
@@ -169,7 +169,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
|
||||
{
|
||||
// pop offset
|
||||
m_context << Instruction::POP;
|
||||
utils().copyToStackTop(paramTypes.size() - i + 1, 1);
|
||||
utils().copyToStackTop(static_cast<unsigned>(paramTypes.size() - i + 1), 1);
|
||||
|
||||
ArrayUtils(m_context).retrieveLength(*arrayType, 1);
|
||||
// Stack: ref [length] index length
|
||||
@@ -190,9 +190,9 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
|
||||
m_context << Instruction::SWAP2 << Instruction::POP << Instruction::SWAP1;
|
||||
else if (paramTypes.size() >= 2)
|
||||
{
|
||||
m_context << swapInstruction(paramTypes.size());
|
||||
m_context << swapInstruction(static_cast<unsigned>(paramTypes.size()));
|
||||
m_context << Instruction::POP;
|
||||
m_context << swapInstruction(paramTypes.size());
|
||||
m_context << swapInstruction(static_cast<unsigned>(paramTypes.size()));
|
||||
utils().popStackSlots(paramTypes.size() - 1);
|
||||
}
|
||||
unsigned retSizeOnStack = 0;
|
||||
@@ -841,7 +841,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
unsigned numIndexed = 0;
|
||||
TypePointers paramTypes = function.parameterTypes();
|
||||
// All indexed arguments go to the stack
|
||||
for (unsigned arg = arguments.size(); arg > 0; --arg)
|
||||
for (size_t arg = arguments.size(); arg > 0; --arg)
|
||||
if (event.parameters()[arg - 1]->isIndexed())
|
||||
{
|
||||
++numIndexed;
|
||||
@@ -1293,7 +1293,7 @@ bool ExpressionCompiler::visit(FunctionCallOptions const& _functionCallOptions)
|
||||
solAssert(!contains(presentOptions, newOption), "");
|
||||
ptrdiff_t insertPos = presentOptions.end() - lower_bound(presentOptions.begin(), presentOptions.end(), newOption);
|
||||
|
||||
utils().moveIntoStack(static_cast<size_t>(insertPos), 1);
|
||||
utils().moveIntoStack(static_cast<unsigned>(insertPos), 1);
|
||||
presentOptions.insert(presentOptions.end() - insertPos, newOption);
|
||||
}
|
||||
|
||||
|
||||
@@ -1489,7 +1489,7 @@ public:
|
||||
|
||||
bytes serialise() const
|
||||
{
|
||||
unsigned size = m_data.size() + 1;
|
||||
size_t size = m_data.size() + 1;
|
||||
solAssert(size <= 0xffff, "Metadata too large.");
|
||||
solAssert(m_entryCount <= 0x1f, "Too many map entries.");
|
||||
|
||||
@@ -1505,7 +1505,7 @@ public:
|
||||
private:
|
||||
void pushTextString(string const& key)
|
||||
{
|
||||
unsigned length = key.size();
|
||||
size_t length = key.size();
|
||||
if (length < 24)
|
||||
{
|
||||
m_data += bytes{static_cast<unsigned char>(0x60 + length)};
|
||||
@@ -1521,7 +1521,7 @@ private:
|
||||
}
|
||||
void pushByteString(bytes const& key)
|
||||
{
|
||||
unsigned length = key.size();
|
||||
size_t length = key.size();
|
||||
if (length < 24)
|
||||
{
|
||||
m_data += bytes{static_cast<unsigned char>(0x40 + length)};
|
||||
|
||||
Reference in New Issue
Block a user