| 848 | } |
| 849 | |
| 850 | std::string YulUtilFunctions::overflowCheckedIntDivFunction(IntegerType const& _type) |
| 851 | { |
| 852 | std::string functionName = "checked_div_" + _type.identifier(); |
| 853 | return m_functionCollector.createFunction(functionName, [&]() { |
| 854 | return |
| 855 | Whiskers(R"( |
| 856 | function <functionName>(x, y) -> r { |
| 857 | x := <cleanupFunction>(x) |
| 858 | y := <cleanupFunction>(y) |
| 859 | if iszero(y) { <panicDivZero>() } |
| 860 | <?signed> |
| 861 | // overflow for minVal / -1 |
| 862 | if and( |
| 863 | eq(x, <minVal>), |
| 864 | eq(y, sub(0, 1)) |
| 865 | ) { <panicOverflow>() } |
| 866 | </signed> |
| 867 | r := <?signed>s</signed>div(x, y) |
| 868 | } |
| 869 | )") |
| 870 | ("functionName", functionName) |
| 871 | ("signed", _type.isSigned()) |
| 872 | ("minVal", toCompactHexWithPrefix(u256(_type.minValue()))) |
| 873 | ("cleanupFunction", cleanupFunction(_type)) |
| 874 | ("panicDivZero", panicFunction(PanicCode::DivisionByZero)) |
| 875 | ("panicOverflow", panicFunction(PanicCode::UnderOverflow)) |
| 876 | .render(); |
| 877 | }); |
| 878 | } |
| 879 | |
| 880 | std::string YulUtilFunctions::wrappingIntDivFunction(IntegerType const& _type) |
| 881 | { |
no test coverage detected