mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
commit
560471c972
@ -322,7 +322,8 @@ Assembly& Assembly::optimise(bool _enable, bool _isCreation, size_t _runs)
|
||||
count++;
|
||||
|
||||
{
|
||||
ControlFlowGraph cfg(m_items);
|
||||
// Control flow graph that resets knowledge at path joins.
|
||||
ControlFlowGraph cfg(m_items, false);
|
||||
AssemblyItems optimisedItems;
|
||||
for (BasicBlock const& block: cfg.optimisedBlocks())
|
||||
{
|
||||
|
@ -250,7 +250,10 @@ void ControlFlowGraph::gatherKnowledge()
|
||||
KnownStatePointer state = item.state;
|
||||
if (block.startState)
|
||||
{
|
||||
if (m_joinKnowledge)
|
||||
state->reduceToCommonKnowledge(*block.startState, !item.blocksSeen.count(item.blockId));
|
||||
else
|
||||
state->reset();
|
||||
if (*state == *block.startState)
|
||||
continue;
|
||||
}
|
||||
|
@ -94,7 +94,11 @@ class ControlFlowGraph
|
||||
public:
|
||||
/// Initializes the control flow graph.
|
||||
/// @a _items has to persist across the usage of this class.
|
||||
ControlFlowGraph(AssemblyItems const& _items): m_items(_items) {}
|
||||
/// @a _joinKnowledge if true, reduces state knowledge to common base at the join of two paths
|
||||
explicit ControlFlowGraph(AssemblyItems const& _items, bool _joinKnowledge = true):
|
||||
m_items(_items),
|
||||
m_joinKnowledge(_joinKnowledge)
|
||||
{}
|
||||
/// @returns vector of basic blocks in the order they should be used in the final code.
|
||||
/// Should be called only once.
|
||||
BasicBlocks optimisedBlocks();
|
||||
@ -112,6 +116,7 @@ private:
|
||||
|
||||
unsigned m_lastUsedId = 0;
|
||||
AssemblyItems const& m_items;
|
||||
bool m_joinKnowledge;
|
||||
std::map<BlockId, BasicBlock> m_blocks;
|
||||
};
|
||||
|
||||
|
@ -1177,6 +1177,64 @@ BOOST_AUTO_TEST_CASE(computing_constants)
|
||||
) == optimizedBytecode.cend());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inconsistency)
|
||||
{
|
||||
// This is a test of a bug in the optimizer.
|
||||
char const* sourceCode = R"(
|
||||
contract Inconsistency {
|
||||
struct Value {
|
||||
uint badnum;
|
||||
uint number;
|
||||
}
|
||||
|
||||
struct Container {
|
||||
uint[] valueIndices;
|
||||
Value[] values;
|
||||
}
|
||||
|
||||
Container[] containers;
|
||||
uint[] valueIndices;
|
||||
uint INDEX_ZERO = 0;
|
||||
uint debug;
|
||||
|
||||
// Called with params: containerIndex=0, valueIndex=0
|
||||
function levelIII(uint containerIndex, uint valueIndex) private {
|
||||
Container container = containers[containerIndex];
|
||||
Value value = container.values[valueIndex];
|
||||
debug = container.valueIndices[value.number];
|
||||
}
|
||||
function levelII() private {
|
||||
for (uint i = 0; i < valueIndices.length; i++) {
|
||||
levelIII(INDEX_ZERO, valueIndices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function trigger() public returns (uint) {
|
||||
containers.length++;
|
||||
Container container = containers[0];
|
||||
|
||||
container.values.push(Value({
|
||||
badnum: 9000,
|
||||
number: 0
|
||||
}));
|
||||
|
||||
container.valueIndices.length++;
|
||||
valueIndices.length++;
|
||||
|
||||
levelII();
|
||||
return debug;
|
||||
}
|
||||
|
||||
function DoNotCallButDoNotDelete() public {
|
||||
levelII();
|
||||
levelIII(1, 2);
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileBothVersions(sourceCode);
|
||||
compareVersions("trigger()");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user