From 58f1e78e186d4fdffa84e6204bb744ad943bedec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 23 Mar 2023 11:36:08 +0100 Subject: [PATCH] Suffix cleanup test --- .../suffix_return_parameter_cleanup.sol | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/libsolidity/semanticTests/literalSuffixes/suffix_return_parameter_cleanup.sol diff --git a/test/libsolidity/semanticTests/literalSuffixes/suffix_return_parameter_cleanup.sol b/test/libsolidity/semanticTests/literalSuffixes/suffix_return_parameter_cleanup.sol new file mode 100644 index 000000000..1e6798d9c --- /dev/null +++ b/test/libsolidity/semanticTests/literalSuffixes/suffix_return_parameter_cleanup.sol @@ -0,0 +1,29 @@ +function suffix(uint8) pure suffix returns (uint8 z) { + assembly { + // Return a value with dirty bytes outside of uint8 + z := 0xffff + } +} + +contract C { + function test() external pure returns (uint, uint) { + uint8 a; + + // The exact literal used does not matter + uint8 suffixResult = 1 suffix; + uint8 functionResult = suffix(1); + + // Get the whole slot, including bytes outside of uint8 + uint suffixResultFull; + uint functionResultFull; + assembly { + suffixResultFull := suffixResult + functionResultFull := functionResult + } + + // If the result is not 0xff, no cleanup was performed. + return (suffixResultFull, functionResultFull); + } +} +// ---- +// test() -> 0xffff, 0xffff