MCPcopy Create free account
hub / github.com/argotorg/solidity / findStackTooDeep

Function findStackTooDeep

libyul/backends/evm/StackLayoutGenerator.cpp:118–162  ·  view source on GitHub ↗

@returns all stack too deep errors that would occur when shuffling @a _source to @a _target.

Source from the content-addressed store, hash-verified

116{
117/// @returns all stack too deep errors that would occur when shuffling @a _source to @a _target.
118std::vector<StackLayoutGenerator::StackTooDeep> findStackTooDeep(
119 Stack const& _source,
120 Stack const& _target,
121 size_t _reachableStackDepth
122)
123{
124 Stack currentStack = _source;
125 std::vector<StackLayoutGenerator::StackTooDeep> stackTooDeepErrors;
126 auto getVariableChoices = [](auto&& _range) {
127 std::vector<YulName> result;
128 for (auto const& slot: _range)
129 if (auto const* variableSlot = std::get_if<VariableSlot>(&slot))
130 if (!util::contains(result, variableSlot->variable.get().name))
131 result.push_back(variableSlot->variable.get().name);
132 return result;
133 };
134 ::createStackLayout(
135 currentStack,
136 _target,
137 [&](unsigned _i)
138 {
139 if (_i > _reachableStackDepth)
140 stackTooDeepErrors.emplace_back(StackLayoutGenerator::StackTooDeep{
141 _i - _reachableStackDepth,
142 getVariableChoices(currentStack | ranges::views::take_last(_i + 1))
143 });
144 },
145 [&](StackSlot const& _slot)
146 {
147 if (canBeFreelyGenerated(_slot))
148 return;
149 if (
150 auto depth = util::findOffset(currentStack | ranges::views::reverse, _slot);
151 depth && *depth >= _reachableStackDepth
152 )
153 stackTooDeepErrors.emplace_back(StackLayoutGenerator::StackTooDeep{
154 *depth - (_reachableStackDepth - 1),
155 getVariableChoices(currentStack | ranges::views::take_last(*depth + 1))
156 });
157 },
158 [&]() {},
159 _reachableStackDepth
160 );
161 return stackTooDeepErrors;
162}
163
164/// @returns the ideal stack to have before executing an operation that outputs @a _operationOutput, s.t.
165/// shuffling to @a _post is cheap (excluding the input of the operation itself).

Callers 2

reportStackTooDeepMethod · 0.85

Calls 5

containsFunction · 0.85
createStackLayoutFunction · 0.85
canBeFreelyGeneratedFunction · 0.85
findOffsetFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected