mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9092 from ethereum/libEvmasmConversionWarnings
Fixing signedness conversion warnings in libevmasm
This commit is contained in:
commit
59fc88ca17
@ -41,7 +41,7 @@ using namespace solidity::util;
|
||||
AssemblyItem const& Assembly::append(AssemblyItem const& _i)
|
||||
{
|
||||
assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
|
||||
m_deposit += _i.deposit();
|
||||
m_deposit += static_cast<int>(_i.deposit());
|
||||
m_items.emplace_back(_i);
|
||||
if (!m_items.back().location().isValid() && m_currentSourceLocation.isValid())
|
||||
m_items.back().setLocation(m_currentSourceLocation);
|
||||
@ -77,10 +77,10 @@ string locationFromSources(StringMap const& _sourceCodes, SourceLocation const&
|
||||
return "";
|
||||
|
||||
string const& source = it->second;
|
||||
if (size_t(_location.start) >= source.size())
|
||||
if (static_cast<size_t>(_location.start) >= source.size())
|
||||
return "";
|
||||
|
||||
string cut = source.substr(_location.start, _location.end - _location.start);
|
||||
string cut = source.substr(static_cast<size_t>(_location.start), static_cast<size_t>(_location.end - _location.start));
|
||||
auto newLinePos = cut.find_first_of("\n");
|
||||
if (newLinePos != string::npos)
|
||||
cut = cut.substr(0, newLinePos) + "...";
|
||||
@ -106,7 +106,7 @@ public:
|
||||
if (!(
|
||||
_item.canBeFunctional() &&
|
||||
_item.returnValues() <= 1 &&
|
||||
_item.arguments() <= int(m_pending.size())
|
||||
_item.arguments() <= m_pending.size()
|
||||
))
|
||||
{
|
||||
flush();
|
||||
@ -117,7 +117,7 @@ public:
|
||||
if (_item.arguments() > 0)
|
||||
{
|
||||
expression += "(";
|
||||
for (int i = 0; i < _item.arguments(); ++i)
|
||||
for (size_t i = 0; i < _item.arguments(); ++i)
|
||||
{
|
||||
expression += m_pending.back();
|
||||
m_pending.pop_back();
|
||||
@ -225,12 +225,12 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
|
||||
Json::Value& collection = root[".code"] = Json::arrayValue;
|
||||
for (AssemblyItem const& i: m_items)
|
||||
{
|
||||
unsigned sourceIndex = unsigned(-1);
|
||||
int sourceIndex = -1;
|
||||
if (i.location().source)
|
||||
{
|
||||
auto iter = _sourceIndices.find(i.location().source->name());
|
||||
if (iter != _sourceIndices.end())
|
||||
sourceIndex = iter->second;
|
||||
sourceIndex = static_cast<int>(iter->second);
|
||||
}
|
||||
|
||||
switch (i.type())
|
||||
@ -340,7 +340,7 @@ AssemblyItem Assembly::namedTag(string const& _name)
|
||||
{
|
||||
assertThrow(!_name.empty(), AssemblyException, "Empty named tag.");
|
||||
if (!m_namedTags.count(_name))
|
||||
m_namedTags[_name] = size_t(newTag().data());
|
||||
m_namedTags[_name] = static_cast<size_t>(newTag().data());
|
||||
return AssemblyItem{Tag, m_namedTags.at(_name)};
|
||||
}
|
||||
|
||||
@ -441,7 +441,7 @@ map<u256, u256> Assembly::optimiseInternal(
|
||||
for (auto const& replacement: deduplicator.replacedTags())
|
||||
{
|
||||
assertThrow(
|
||||
replacement.first <= size_t(-1) && replacement.second <= size_t(-1),
|
||||
replacement.first <= numeric_limits<size_t>::max() && replacement.second <= numeric_limits<size_t>::max(),
|
||||
OptimizerException,
|
||||
"Invalid tag replacement."
|
||||
);
|
||||
@ -451,8 +451,8 @@ map<u256, u256> Assembly::optimiseInternal(
|
||||
"Replacement already known."
|
||||
);
|
||||
tagReplacements[replacement.first] = replacement.second;
|
||||
if (_tagsReferencedFromOutside.erase(size_t(replacement.first)))
|
||||
_tagsReferencedFromOutside.insert(size_t(replacement.second));
|
||||
if (_tagsReferencedFromOutside.erase(static_cast<size_t>(replacement.first)))
|
||||
_tagsReferencedFromOutside.insert(static_cast<size_t>(replacement.second));
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@ -479,7 +479,7 @@ map<u256, u256> Assembly::optimiseInternal(
|
||||
try
|
||||
{
|
||||
optimisedChunk = eliminator.getOptimizedItems();
|
||||
shouldReplace = (optimisedChunk.size() < size_t(iter - orig));
|
||||
shouldReplace = (optimisedChunk.size() < static_cast<size_t>(iter - orig));
|
||||
}
|
||||
catch (StackTooDeepException const&)
|
||||
{
|
||||
@ -544,7 +544,7 @@ LinkerObject const& Assembly::assemble() const
|
||||
immutableReferencesBySub = linkerObject.immutableReferences;
|
||||
}
|
||||
for (size_t tagPos: sub->m_tagPositionsInBytecode)
|
||||
if (tagPos != size_t(-1) && tagPos > subTagSize)
|
||||
if (tagPos != numeric_limits<size_t>::max() && tagPos > subTagSize)
|
||||
subTagSize = tagPos;
|
||||
}
|
||||
|
||||
@ -567,7 +567,7 @@ LinkerObject const& Assembly::assemble() const
|
||||
);
|
||||
|
||||
size_t bytesRequiredForCode = bytesRequired(subTagSize);
|
||||
m_tagPositionsInBytecode = vector<size_t>(m_usedTags, -1);
|
||||
m_tagPositionsInBytecode = vector<size_t>(m_usedTags, numeric_limits<size_t>::max());
|
||||
map<size_t, pair<size_t, size_t>> tagRef;
|
||||
multimap<h256, unsigned> dataRef;
|
||||
multimap<size_t, size_t> subRef;
|
||||
@ -586,7 +586,7 @@ LinkerObject const& Assembly::assemble() const
|
||||
for (AssemblyItem const& i: m_items)
|
||||
{
|
||||
// store position of the invalid jump destination
|
||||
if (i.type() != Tag && m_tagPositionsInBytecode[0] == size_t(-1))
|
||||
if (i.type() != Tag && m_tagPositionsInBytecode[0] == numeric_limits<size_t>::max())
|
||||
m_tagPositionsInBytecode[0] = ret.bytecode.size();
|
||||
|
||||
switch (i.type())
|
||||
@ -629,15 +629,15 @@ LinkerObject const& Assembly::assemble() const
|
||||
ret.bytecode.resize(ret.bytecode.size() + bytesPerDataRef);
|
||||
break;
|
||||
case PushSub:
|
||||
assertThrow(i.data() <= size_t(-1), AssemblyException, "");
|
||||
assertThrow(i.data() <= numeric_limits<size_t>::max(), AssemblyException, "");
|
||||
ret.bytecode.push_back(dataRefPush);
|
||||
subRef.insert(make_pair(size_t(i.data()), ret.bytecode.size()));
|
||||
subRef.insert(make_pair(static_cast<size_t>(i.data()), ret.bytecode.size()));
|
||||
ret.bytecode.resize(ret.bytecode.size() + bytesPerDataRef);
|
||||
break;
|
||||
case PushSubSize:
|
||||
{
|
||||
assertThrow(i.data() <= size_t(-1), AssemblyException, "");
|
||||
auto s = m_subs.at(size_t(i.data()))->assemble().bytecode.size();
|
||||
assertThrow(i.data() <= numeric_limits<size_t>::max(), AssemblyException, "");
|
||||
auto s = m_subs.at(static_cast<size_t>(i.data()))->assemble().bytecode.size();
|
||||
i.setPushedValue(u256(s));
|
||||
uint8_t b = max<unsigned>(1, util::bytesRequired(s));
|
||||
ret.bytecode.push_back((uint8_t)Instruction::PUSH1 - 1 + b);
|
||||
@ -683,10 +683,10 @@ LinkerObject const& Assembly::assemble() const
|
||||
break;
|
||||
case Tag:
|
||||
assertThrow(i.data() != 0, AssemblyException, "Invalid tag position.");
|
||||
assertThrow(i.splitForeignPushTag().first == size_t(-1), AssemblyException, "Foreign tag.");
|
||||
assertThrow(i.splitForeignPushTag().first == numeric_limits<size_t>::max(), AssemblyException, "Foreign tag.");
|
||||
assertThrow(ret.bytecode.size() < 0xffffffffL, AssemblyException, "Tag too large.");
|
||||
assertThrow(m_tagPositionsInBytecode[size_t(i.data())] == size_t(-1), AssemblyException, "Duplicate tag position.");
|
||||
m_tagPositionsInBytecode[size_t(i.data())] = ret.bytecode.size();
|
||||
assertThrow(m_tagPositionsInBytecode[static_cast<size_t>(i.data())] == numeric_limits<size_t>::max(), AssemblyException, "Duplicate tag position.");
|
||||
m_tagPositionsInBytecode[static_cast<size_t>(i.data())] = ret.bytecode.size();
|
||||
ret.bytecode.push_back((uint8_t)Instruction::JUMPDEST);
|
||||
break;
|
||||
default:
|
||||
@ -722,14 +722,14 @@ LinkerObject const& Assembly::assemble() const
|
||||
size_t subId;
|
||||
size_t tagId;
|
||||
tie(subId, tagId) = i.second;
|
||||
assertThrow(subId == size_t(-1) || subId < m_subs.size(), AssemblyException, "Invalid sub id");
|
||||
assertThrow(subId == numeric_limits<size_t>::max() || subId < m_subs.size(), AssemblyException, "Invalid sub id");
|
||||
std::vector<size_t> const& tagPositions =
|
||||
subId == size_t(-1) ?
|
||||
subId == numeric_limits<size_t>::max() ?
|
||||
m_tagPositionsInBytecode :
|
||||
m_subs[subId]->m_tagPositionsInBytecode;
|
||||
assertThrow(tagId < tagPositions.size(), AssemblyException, "Reference to non-existing tag.");
|
||||
size_t pos = tagPositions[tagId];
|
||||
assertThrow(pos != size_t(-1), AssemblyException, "Reference to tag without position.");
|
||||
assertThrow(pos != numeric_limits<size_t>::max(), AssemblyException, "Reference to tag without position.");
|
||||
assertThrow(util::bytesRequired(pos) <= bytesPerTag, AssemblyException, "Tag too large for reserved space.");
|
||||
bytesRef r(ret.bytecode.data() + i.first, bytesPerTag);
|
||||
toBigEndian(pos, r);
|
||||
|
@ -34,7 +34,7 @@ AssemblyItem AssemblyItem::toSubAssemblyTag(size_t _subId) const
|
||||
{
|
||||
assertThrow(data() < (u256(1) << 64), util::Exception, "Tag already has subassembly set.");
|
||||
assertThrow(m_type == PushTag || m_type == Tag, util::Exception, "");
|
||||
size_t tag = size_t(u256(data()) & 0xffffffffffffffffULL);
|
||||
auto tag = static_cast<size_t>(u256(data()) & 0xffffffffffffffffULL);
|
||||
AssemblyItem r = *this;
|
||||
r.m_type = PushTag;
|
||||
r.setPushTagSubIdAndTag(_subId, tag);
|
||||
@ -45,8 +45,8 @@ pair<size_t, size_t> AssemblyItem::splitForeignPushTag() const
|
||||
{
|
||||
assertThrow(m_type == PushTag || m_type == Tag, util::Exception, "");
|
||||
u256 combined = u256(data());
|
||||
size_t subId = size_t((combined >> 64) - 1);
|
||||
size_t tag = size_t(combined & 0xffffffffffffffffULL);
|
||||
size_t subId = static_cast<size_t>((combined >> 64) - 1);
|
||||
size_t tag = static_cast<size_t>(combined & 0xffffffffffffffffULL);
|
||||
return make_pair(subId, tag);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ void AssemblyItem::setPushTagSubIdAndTag(size_t _subId, size_t _tag)
|
||||
{
|
||||
assertThrow(m_type == PushTag || m_type == Tag, util::Exception, "");
|
||||
u256 data = _tag;
|
||||
if (_subId != size_t(-1))
|
||||
if (_subId != numeric_limits<size_t>::max())
|
||||
data |= (u256(_subId) + 1) << 64;
|
||||
setData(data);
|
||||
}
|
||||
@ -93,22 +93,22 @@ unsigned AssemblyItem::bytesRequired(unsigned _addressLength) const
|
||||
assertThrow(false, InvalidOpcode, "");
|
||||
}
|
||||
|
||||
int AssemblyItem::arguments() const
|
||||
size_t AssemblyItem::arguments() const
|
||||
{
|
||||
if (type() == Operation)
|
||||
return instructionInfo(instruction()).args;
|
||||
return static_cast<size_t>(instructionInfo(instruction()).args);
|
||||
else if (type() == AssignImmutable)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AssemblyItem::returnValues() const
|
||||
size_t AssemblyItem::returnValues() const
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case Operation:
|
||||
return instructionInfo(instruction()).ret;
|
||||
return static_cast<size_t>(instructionInfo(instruction()).ret);
|
||||
case Push:
|
||||
case PushString:
|
||||
case PushTag:
|
||||
@ -193,7 +193,7 @@ string AssemblyItem::toAssemblyText() const
|
||||
size_t sub{0};
|
||||
size_t tag{0};
|
||||
tie(sub, tag) = splitForeignPushTag();
|
||||
if (sub == size_t(-1))
|
||||
if (sub == numeric_limits<size_t>::max())
|
||||
text = string("tag_") + to_string(tag);
|
||||
else
|
||||
text = string("tag_") + to_string(sub) + "_" + to_string(tag);
|
||||
@ -201,16 +201,16 @@ string AssemblyItem::toAssemblyText() const
|
||||
}
|
||||
case Tag:
|
||||
assertThrow(data() < 0x10000, AssemblyException, "Declaration of sub-assembly tag.");
|
||||
text = string("tag_") + to_string(size_t(data())) + ":";
|
||||
text = string("tag_") + to_string(static_cast<size_t>(data())) + ":";
|
||||
break;
|
||||
case PushData:
|
||||
text = string("data_") + util::toHex(data());
|
||||
break;
|
||||
case PushSub:
|
||||
text = string("dataOffset(sub_") + to_string(size_t(data())) + ")";
|
||||
text = string("dataOffset(sub_") + to_string(static_cast<size_t>(data())) + ")";
|
||||
break;
|
||||
case PushSubSize:
|
||||
text = string("dataSize(sub_") + to_string(size_t(data())) + ")";
|
||||
text = string("dataSize(sub_") + to_string(static_cast<size_t>(data())) + ")";
|
||||
break;
|
||||
case PushProgramSize:
|
||||
text = string("bytecodeSize");
|
||||
@ -262,7 +262,7 @@ ostream& solidity::evmasm::operator<<(ostream& _out, AssemblyItem const& _item)
|
||||
case PushTag:
|
||||
{
|
||||
size_t subId = _item.splitForeignPushTag().first;
|
||||
if (subId == size_t(-1))
|
||||
if (subId == numeric_limits<size_t>::max())
|
||||
_out << " PushTag " << _item.splitForeignPushTag().second;
|
||||
else
|
||||
_out << " PushTag " << subId << ":" << _item.splitForeignPushTag().second;
|
||||
@ -272,13 +272,13 @@ ostream& solidity::evmasm::operator<<(ostream& _out, AssemblyItem const& _item)
|
||||
_out << " Tag " << _item.data();
|
||||
break;
|
||||
case PushData:
|
||||
_out << " PushData " << hex << (unsigned)_item.data() << dec;
|
||||
_out << " PushData " << hex << static_cast<unsigned>(_item.data()) << dec;
|
||||
break;
|
||||
case PushSub:
|
||||
_out << " PushSub " << hex << size_t(_item.data()) << dec;
|
||||
_out << " PushSub " << hex << static_cast<size_t>(_item.data()) << dec;
|
||||
break;
|
||||
case PushSubSize:
|
||||
_out << " PushSubSize " << hex << size_t(_item.data()) << dec;
|
||||
_out << " PushSubSize " << hex << static_cast<size_t>(_item.data()) << dec;
|
||||
break;
|
||||
case PushProgramSize:
|
||||
_out << " PushProgramSize";
|
||||
@ -317,7 +317,7 @@ std::string AssemblyItem::computeSourceMapping(
|
||||
int prevStart = -1;
|
||||
int prevLength = -1;
|
||||
int prevSourceIndex = -1;
|
||||
size_t prevModifierDepth = -1;
|
||||
int prevModifierDepth = -1;
|
||||
char prevJump = 0;
|
||||
for (auto const& item: _items)
|
||||
{
|
||||
@ -328,14 +328,14 @@ std::string AssemblyItem::computeSourceMapping(
|
||||
int length = location.start != -1 && location.end != -1 ? location.end - location.start : -1;
|
||||
int sourceIndex =
|
||||
location.source && _sourceIndicesMap.count(location.source->name()) ?
|
||||
_sourceIndicesMap.at(location.source->name()) :
|
||||
static_cast<int>(_sourceIndicesMap.at(location.source->name())) :
|
||||
-1;
|
||||
char jump = '-';
|
||||
if (item.getJumpType() == evmasm::AssemblyItem::JumpType::IntoFunction)
|
||||
jump = 'i';
|
||||
else if (item.getJumpType() == evmasm::AssemblyItem::JumpType::OutOfFunction)
|
||||
jump = 'o';
|
||||
size_t modifierDepth = item.m_modifierDepth;
|
||||
int modifierDepth = static_cast<int>(item.m_modifierDepth);
|
||||
|
||||
unsigned components = 5;
|
||||
if (modifierDepth == prevModifierDepth)
|
||||
|
@ -134,9 +134,9 @@ public:
|
||||
/// @returns an upper bound for the number of bytes required by this item, assuming that
|
||||
/// the value of a jump tag takes @a _addressLength bytes.
|
||||
unsigned bytesRequired(unsigned _addressLength) const;
|
||||
int arguments() const;
|
||||
int returnValues() const;
|
||||
int deposit() const { return returnValues() - arguments(); }
|
||||
size_t arguments() const;
|
||||
size_t returnValues() const;
|
||||
size_t deposit() const { return returnValues() - arguments(); }
|
||||
|
||||
/// @returns true if the assembly item can be used in a functional context.
|
||||
bool canBeFunctional() const;
|
||||
|
@ -63,8 +63,9 @@ bool BlockDeduplicator::deduplicate()
|
||||
if (_j < m_items.size() && m_items.at(_j).type() == Tag)
|
||||
pushSecondTag = m_items.at(_j).pushTag();
|
||||
|
||||
BlockIterator first{m_items.begin() + _i, m_items.end(), &pushFirstTag, &pushSelf};
|
||||
BlockIterator second{m_items.begin() + _j, m_items.end(), &pushSecondTag, &pushSelf};
|
||||
using diff_type = BlockIterator::difference_type;
|
||||
BlockIterator first{m_items.begin() + diff_type(_i), m_items.end(), &pushFirstTag, &pushSelf};
|
||||
BlockIterator second{m_items.begin() + diff_type(_j), m_items.end(), &pushSecondTag, &pushSelf};
|
||||
BlockIterator end{m_items.end(), m_items.end()};
|
||||
|
||||
if (first != end && (*first).type() == Tag)
|
||||
@ -120,7 +121,7 @@ bool BlockDeduplicator::applyTagReplacement(
|
||||
if (it != _replacements.end())
|
||||
{
|
||||
changed = true;
|
||||
item.setPushTagSubIdAndTag(subId, size_t(it->second));
|
||||
item.setPushTagSubIdAndTag(subId, static_cast<size_t>(it->second));
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
|
@ -386,7 +386,11 @@ void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
|
||||
"Opcodes with more than two arguments not implemented yet."
|
||||
);
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
assertThrow(m_stack[m_stackHeight - i] == arguments[i], OptimizerException, "Expected arguments not present." );
|
||||
assertThrow(
|
||||
m_stack[m_stackHeight - static_cast<int>(i)] == arguments[i],
|
||||
OptimizerException,
|
||||
"Expected arguments not present."
|
||||
);
|
||||
|
||||
while (SemanticInformation::isCommutativeOperation(*expr.item) &&
|
||||
!m_generatedItems.empty() &&
|
||||
@ -395,8 +399,8 @@ void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
|
||||
appendOrRemoveSwap(m_stackHeight - 1, itemLocation);
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
m_classPositions[m_stack[m_stackHeight - i]].erase(m_stackHeight - i);
|
||||
m_stack.erase(m_stackHeight - i);
|
||||
m_classPositions[m_stack[m_stackHeight - static_cast<int>(i)]].erase(m_stackHeight - static_cast<int>(i));
|
||||
m_stack.erase(m_stackHeight - static_cast<int>(i));
|
||||
}
|
||||
appendItem(*expr.item);
|
||||
if (expr.item->type() != Operation || instructionInfo(expr.item->instruction()).ret == 1)
|
||||
@ -467,7 +471,7 @@ void CSECodeGenerator::appendDup(int _fromPosition, SourceLocation const& _locat
|
||||
int instructionNum = 1 + m_stackHeight - _fromPosition;
|
||||
assertThrow(instructionNum <= 16, StackTooDeepException, "Stack too deep, try removing local variables.");
|
||||
assertThrow(1 <= instructionNum, OptimizerException, "Invalid stack access.");
|
||||
appendItem(AssemblyItem(dupInstruction(instructionNum), _location));
|
||||
appendItem(AssemblyItem(dupInstruction(static_cast<unsigned>(instructionNum)), _location));
|
||||
m_stack[m_stackHeight] = m_stack[_fromPosition];
|
||||
m_classPositions[m_stack[m_stackHeight]].insert(m_stackHeight);
|
||||
}
|
||||
@ -480,7 +484,7 @@ void CSECodeGenerator::appendOrRemoveSwap(int _fromPosition, SourceLocation cons
|
||||
int instructionNum = m_stackHeight - _fromPosition;
|
||||
assertThrow(instructionNum <= 16, StackTooDeepException, "Stack too deep, try removing local variables.");
|
||||
assertThrow(1 <= instructionNum, OptimizerException, "Invalid stack access.");
|
||||
appendItem(AssemblyItem(swapInstruction(instructionNum), _location));
|
||||
appendItem(AssemblyItem(swapInstruction(static_cast<unsigned>(instructionNum)), _location));
|
||||
|
||||
if (m_stack[m_stackHeight] != m_stack[_fromPosition])
|
||||
{
|
||||
@ -502,5 +506,5 @@ void CSECodeGenerator::appendOrRemoveSwap(int _fromPosition, SourceLocation cons
|
||||
void CSECodeGenerator::appendItem(AssemblyItem const& _item)
|
||||
{
|
||||
m_generatedItems.push_back(_item);
|
||||
m_stackHeight += _item.deposit();
|
||||
m_stackHeight += static_cast<int>(_item.deposit());
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ bool ComputeMethod::checkRepresentation(u256 const& _value, AssemblyItems const&
|
||||
{
|
||||
case Operation:
|
||||
{
|
||||
if (stack.size() < size_t(item.arguments()))
|
||||
if (stack.size() < item.arguments())
|
||||
return false;
|
||||
u256* sp = &stack.back();
|
||||
switch (item.instruction())
|
||||
@ -320,7 +320,7 @@ bool ComputeMethod::checkRepresentation(u256 const& _value, AssemblyItems const&
|
||||
|
||||
bigint ComputeMethod::gasNeeded(AssemblyItems const& _routine) const
|
||||
{
|
||||
size_t numExps = count(_routine.begin(), _routine.end(), Instruction::EXP);
|
||||
auto numExps = static_cast<size_t>(count(_routine.begin(), _routine.end(), Instruction::EXP));
|
||||
return combineGas(
|
||||
simpleRunGas(_routine) + numExps * (GasCosts::expGas + GasCosts::expByteGas(m_params.evmVersion)),
|
||||
// Data gas for routine: Some bytes are zero, but we ignore them.
|
||||
|
@ -45,8 +45,8 @@ public:
|
||||
BlockId() { *this = invalid(); }
|
||||
explicit BlockId(unsigned _id): m_id(_id) {}
|
||||
explicit BlockId(u256 const& _id);
|
||||
static BlockId initial() { return BlockId(-2); }
|
||||
static BlockId invalid() { return BlockId(-1); }
|
||||
static BlockId initial() { return BlockId(std::numeric_limits<unsigned>::max() - 1); }
|
||||
static BlockId invalid() { return BlockId(std::numeric_limits<unsigned>::max()); }
|
||||
|
||||
bool operator==(BlockId const& _other) const { return m_id == _other.m_id; }
|
||||
bool operator!=(BlockId const& _other) const { return m_id != _other.m_id; }
|
||||
|
@ -190,7 +190,7 @@ ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr)
|
||||
_expr.item->type() != Operation ||
|
||||
!SemanticInformation::isDeterministic(*_expr.item)
|
||||
)
|
||||
return -1;
|
||||
return numeric_limits<unsigned>::max();
|
||||
|
||||
if (auto match = rules.findFirstMatch(_expr, *this))
|
||||
{
|
||||
@ -208,7 +208,7 @@ ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr)
|
||||
return rebuildExpression(ExpressionTemplate(match->action(), _expr.item->location()));
|
||||
}
|
||||
|
||||
return -1;
|
||||
return numeric_limits<unsigned>::max();
|
||||
}
|
||||
|
||||
ExpressionClasses::Id ExpressionClasses::rebuildExpression(ExpressionTemplate const& _template)
|
||||
|
@ -330,8 +330,8 @@ void solidity::evmasm::eachInstruction(
|
||||
{
|
||||
for (auto it = _mem.begin(); it < _mem.end(); ++it)
|
||||
{
|
||||
Instruction instr = Instruction(*it);
|
||||
size_t additional = 0;
|
||||
auto instr = Instruction(*it);
|
||||
int additional = 0;
|
||||
if (isValidInstruction(instr))
|
||||
additional = instructionInfo(instr).additional;
|
||||
|
||||
@ -357,7 +357,7 @@ string solidity::evmasm::disassemble(bytes const& _mem)
|
||||
stringstream ret;
|
||||
eachInstruction(_mem, [&](Instruction _instr, u256 const& _data) {
|
||||
if (!isValidInstruction(_instr))
|
||||
ret << "0x" << std::uppercase << std::hex << int(_instr) << " ";
|
||||
ret << "0x" << std::uppercase << std::hex << static_cast<int>(_instr) << " ";
|
||||
else
|
||||
{
|
||||
InstructionInfo info = instructionInfo(_instr);
|
||||
|
@ -30,7 +30,7 @@ using namespace solidity::evmasm;
|
||||
|
||||
bool JumpdestRemover::optimise(set<size_t> const& _tagsReferencedFromOutside)
|
||||
{
|
||||
set<size_t> references{referencedTags(m_items, -1)};
|
||||
set<size_t> references{referencedTags(m_items, numeric_limits<size_t>::max())};
|
||||
references.insert(_tagsReferencedFromOutside.begin(), _tagsReferencedFromOutside.end());
|
||||
|
||||
size_t initialSize = m_items.size();
|
||||
@ -43,7 +43,7 @@ bool JumpdestRemover::optimise(set<size_t> const& _tagsReferencedFromOutside)
|
||||
if (_item.type() != Tag)
|
||||
return false;
|
||||
auto asmIdAndTag = _item.splitForeignPushTag();
|
||||
assertThrow(asmIdAndTag.first == size_t(-1), OptimizerException, "Sub-assembly tag used as label.");
|
||||
assertThrow(asmIdAndTag.first == numeric_limits<size_t>::max(), OptimizerException, "Sub-assembly tag used as label.");
|
||||
size_t tag = asmIdAndTag.second;
|
||||
return !references.count(tag);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ ostream& KnownState::stream(ostream& _out) const
|
||||
if (!expr.item)
|
||||
_out << " no item";
|
||||
else if (expr.item->type() == UndefinedItem)
|
||||
_out << " unknown " << int(expr.item->data());
|
||||
_out << " unknown " << static_cast<int>(expr.item->data());
|
||||
else
|
||||
_out << *expr.item;
|
||||
if (expr.sequenceNumber)
|
||||
@ -112,21 +112,21 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
|
||||
setStackElement(
|
||||
m_stackHeight + 1,
|
||||
stackElement(
|
||||
m_stackHeight - int(instruction) + int(Instruction::DUP1),
|
||||
m_stackHeight - static_cast<int>(instruction) + static_cast<int>(Instruction::DUP1),
|
||||
_item.location()
|
||||
)
|
||||
);
|
||||
else if (SemanticInformation::isSwapInstruction(_item))
|
||||
swapStackElements(
|
||||
m_stackHeight,
|
||||
m_stackHeight - 1 - int(instruction) + int(Instruction::SWAP1),
|
||||
m_stackHeight - 1 - static_cast<int>(instruction) + static_cast<int>(Instruction::SWAP1),
|
||||
_item.location()
|
||||
);
|
||||
else if (instruction != Instruction::POP)
|
||||
{
|
||||
vector<Id> arguments(info.args);
|
||||
for (int i = 0; i < info.args; ++i)
|
||||
arguments[i] = stackElement(m_stackHeight - i, _item.location());
|
||||
vector<Id> arguments(static_cast<size_t>(info.args));
|
||||
for (size_t i = 0; i < static_cast<size_t>(info.args); ++i)
|
||||
arguments[i] = stackElement(m_stackHeight - static_cast<int>(i), _item.location());
|
||||
switch (_item.instruction())
|
||||
{
|
||||
case Instruction::SSTORE:
|
||||
@ -134,7 +134,7 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
|
||||
break;
|
||||
case Instruction::SLOAD:
|
||||
setStackElement(
|
||||
m_stackHeight + _item.deposit(),
|
||||
m_stackHeight + static_cast<int>(_item.deposit()),
|
||||
loadFromStorage(arguments[0], _item.location())
|
||||
);
|
||||
break;
|
||||
@ -143,13 +143,13 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
|
||||
break;
|
||||
case Instruction::MLOAD:
|
||||
setStackElement(
|
||||
m_stackHeight + _item.deposit(),
|
||||
m_stackHeight + static_cast<int>(_item.deposit()),
|
||||
loadFromMemory(arguments[0], _item.location())
|
||||
);
|
||||
break;
|
||||
case Instruction::KECCAK256:
|
||||
setStackElement(
|
||||
m_stackHeight + _item.deposit(),
|
||||
m_stackHeight + static_cast<int>(_item.deposit()),
|
||||
applyKeccak256(arguments.at(0), arguments.at(1), _item.location())
|
||||
);
|
||||
break;
|
||||
@ -167,16 +167,16 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
|
||||
assertThrow(info.ret <= 1, InvalidDeposit, "");
|
||||
if (info.ret == 1)
|
||||
setStackElement(
|
||||
m_stackHeight + _item.deposit(),
|
||||
m_stackHeight + static_cast<int>(_item.deposit()),
|
||||
m_expressionClasses->find(_item, arguments, _copyItem)
|
||||
);
|
||||
}
|
||||
}
|
||||
m_stackElements.erase(
|
||||
m_stackElements.upper_bound(m_stackHeight + _item.deposit()),
|
||||
m_stackElements.upper_bound(m_stackHeight + static_cast<int>(_item.deposit())),
|
||||
m_stackElements.end()
|
||||
);
|
||||
m_stackHeight += _item.deposit();
|
||||
m_stackHeight += static_cast<int>(_item.deposit());
|
||||
}
|
||||
return op;
|
||||
}
|
||||
@ -388,7 +388,7 @@ KnownState::Id KnownState::applyKeccak256(
|
||||
bytes data;
|
||||
for (Id a: arguments)
|
||||
data += util::toBigEndian(*m_expressionClasses->knownConstant(a));
|
||||
data.resize(size_t(*l));
|
||||
data.resize(static_cast<size_t>(*l));
|
||||
v = m_expressionClasses->find(AssemblyItem(u256(util::keccak256(data)), _location));
|
||||
}
|
||||
else
|
||||
|
@ -40,7 +40,7 @@ void LinkerObject::link(map<string, h160> const& _libraryAddresses)
|
||||
std::map<size_t, std::string> remainingRefs;
|
||||
for (auto const& linkRef: linkReferences)
|
||||
if (h160 const* address = matchLibrary(linkRef.second, _libraryAddresses))
|
||||
copy(address->data(), address->data() + 20, bytecode.begin() + linkRef.first);
|
||||
copy(address->data(), address->data() + 20, bytecode.begin() + vector<uint8_t>::difference_type(linkRef.first));
|
||||
else
|
||||
remainingRefs.insert(linkRef);
|
||||
linkReferences.swap(remainingRefs);
|
||||
|
@ -84,7 +84,7 @@ struct SimplePeepholeOptimizerMethod
|
||||
{
|
||||
if (
|
||||
_state.i + WindowSize <= _state.items.size() &&
|
||||
ApplyRule<Method, WindowSize>::applyRule(_state.items.begin() + _state.i, _state.out)
|
||||
ApplyRule<Method, WindowSize>::applyRule(_state.items.begin() + static_cast<ptrdiff_t>(_state.i), _state.out)
|
||||
)
|
||||
{
|
||||
_state.i += WindowSize;
|
||||
@ -303,7 +303,7 @@ struct UnreachableCode
|
||||
{
|
||||
static bool apply(OptimiserState& _state)
|
||||
{
|
||||
auto it = _state.items.begin() + _state.i;
|
||||
auto it = _state.items.begin() + static_cast<ptrdiff_t>(_state.i);
|
||||
auto end = _state.items.end();
|
||||
if (it == end)
|
||||
return false;
|
||||
@ -317,13 +317,13 @@ struct UnreachableCode
|
||||
)
|
||||
return false;
|
||||
|
||||
size_t i = 1;
|
||||
ptrdiff_t i = 1;
|
||||
while (it + i != end && it[i].type() != Tag)
|
||||
i++;
|
||||
if (i > 1)
|
||||
{
|
||||
*_state.out = it[0];
|
||||
_state.i += i;
|
||||
_state.i += static_cast<size_t>(i);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -345,7 +345,7 @@ void applyMethods(OptimiserState& _state, Method, OtherMethods... _other)
|
||||
|
||||
size_t numberOfPops(AssemblyItems const& _items)
|
||||
{
|
||||
return std::count(_items.begin(), _items.end(), Instruction::POP);
|
||||
return static_cast<size_t>(std::count(_items.begin(), _items.end(), Instruction::POP));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
||||
// PushSubSize
|
||||
auto sub = _assembly.appendSubroutine(_subAsmPtr);
|
||||
// PushSub
|
||||
_assembly.pushSubroutineOffset(size_t(sub.data()));
|
||||
_assembly.pushSubroutineOffset(static_cast<size_t>(sub.data()));
|
||||
// PushDeployTimeAddress
|
||||
_assembly.append(PushDeployTimeAddress);
|
||||
// AssignImmutable.
|
||||
@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(immutable)
|
||||
_assembly.appendImmutableAssignment("someOtherImmutable");
|
||||
|
||||
auto sub = _assembly.appendSubroutine(_subAsmPtr);
|
||||
_assembly.pushSubroutineOffset(size_t(sub.data()));
|
||||
_assembly.pushSubroutineOffset(static_cast<size_t>(sub.data()));
|
||||
|
||||
checkCompilation(_assembly);
|
||||
|
||||
|
@ -1227,7 +1227,7 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies)
|
||||
sub->append(t4.pushTag());
|
||||
sub->append(Instruction::JUMP);
|
||||
|
||||
size_t subId = size_t(main.appendSubroutine(sub).data());
|
||||
size_t subId = static_cast<size_t>(main.appendSubroutine(sub).data());
|
||||
main.append(t1.toSubAssemblyTag(subId));
|
||||
main.append(t1.toSubAssemblyTag(subId));
|
||||
main.append(u256(8));
|
||||
@ -1281,10 +1281,10 @@ BOOST_AUTO_TEST_CASE(cse_remove_redundant_shift_masking)
|
||||
if (!solidity::test::CommonOptions::get().evmVersion().hasBitwiseShifting())
|
||||
return;
|
||||
|
||||
for (int i = 1; i < 256; i++)
|
||||
for (size_t i = 1; i < 256; i++)
|
||||
{
|
||||
checkCSE({
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
u256(boost::multiprecision::pow(u256(2), i) - 1),
|
||||
Instruction::CALLVALUE,
|
||||
u256(256-i),
|
||||
Instruction::SHR,
|
||||
@ -1309,10 +1309,10 @@ BOOST_AUTO_TEST_CASE(cse_remove_redundant_shift_masking)
|
||||
}
|
||||
|
||||
// Check that opt. does NOT trigger
|
||||
for (int i = 1; i < 255; i++)
|
||||
for (size_t i = 1; i < 255; i++)
|
||||
{
|
||||
checkCSE({
|
||||
u256(boost::multiprecision::pow(u256(2), i)-1),
|
||||
u256(boost::multiprecision::pow(u256(2), i) - 1),
|
||||
Instruction::CALLVALUE,
|
||||
u256(255-i),
|
||||
Instruction::SHR,
|
||||
|
Loading…
Reference in New Issue
Block a user