From d7db1f097ae7ade6338032207b4898d97994253f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 23 Mar 2023 11:37:46 +0100 Subject: [PATCH] Extra test for operator cleanup --- ...meter_and_return_cleanup_between_calls.sol | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/libsolidity/semanticTests/operators/userDefined/operator_parameter_and_return_cleanup_between_calls.sol diff --git a/test/libsolidity/semanticTests/operators/userDefined/operator_parameter_and_return_cleanup_between_calls.sol b/test/libsolidity/semanticTests/operators/userDefined/operator_parameter_and_return_cleanup_between_calls.sol new file mode 100644 index 000000000..b51ad8dad --- /dev/null +++ b/test/libsolidity/semanticTests/operators/userDefined/operator_parameter_and_return_cleanup_between_calls.sol @@ -0,0 +1,22 @@ +type U8 is uint8; +using {yoloAdd as +, yoloDiv as /} for U8 global; + +function yoloAdd(U8 x, U8 y) pure returns (U8 z) { + assembly { + z := add(x, y) // Wrong! No cleanup. + } +} + +function yoloDiv(U8 x, U8 y) pure returns (U8 z) { + assembly { + z := div(x, y) // Wrong! No cleanup. + } +} + +contract C { + function divAddNoOverflow(U8 a, U8 b, U8 c) external pure returns (U8) { + return a / (b + c); + } +} +// ---- +// divAddNoOverflow(uint8,uint8,uint8): 4, 0xff, 3 -> 0