array_elimination.sol 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // RUN: --target solana --emit cfg
  2. contract TestCase {
  3. int128[] st;
  4. // BEGIN-CHECK: TestCase::TestCase::function::myFuncStorage__uint32
  5. function myFuncStorage(uint32[] storage arr) private {
  6. // CHECK: pop storage ty:uint32 slot(%arr)
  7. arr.pop();
  8. }
  9. // BEGIN-CHECK: TestCase::TestCase::function::myFuncStorage2__uint32
  10. function myFuncStorage2(uint32[] storage arr) private {
  11. // CHECK: push storage ty:uint32 slot:%arr = uint32 5
  12. arr.push(5);
  13. }
  14. // BEGIN-CHECK: TestCase::TestCase::function::myPush__int128
  15. function myPush(int128 val) public {
  16. // CHECK: push storage ty:int128 slot:uint32 16 = (arg #0)
  17. st.push(val);
  18. }
  19. // BEGIN-CHECK: TestCase::TestCase::function::myPop
  20. function myPop() public {
  21. // CHECK: pop storage ty:int128 slot(uint32 16)
  22. st.pop();
  23. }
  24. // BEGIN-CHECK: TestCase::TestCase::function::myFuncPointer__int256
  25. function myFuncPointer(int256[] memory arr) pure private {
  26. // CHECK: push array ty:int256[] value:int256 256
  27. arr.push(256);
  28. int256[] memory myArr = arr;
  29. myArr.push(5);
  30. }
  31. // BEGIN-CHECK: TestCase::TestCase::function::myFuncPointer2__int256
  32. function myFuncPointer2(int256[] arr) pure private {
  33. // CHECK: pop array ty:int256[]
  34. arr.pop();
  35. }
  36. // BEGIN-CHECK: TestCase::TestCase::function::foo
  37. function foo() public pure returns (bytes memory) {
  38. bytes b1 = hex"41";
  39. // NOT-CHECK: ty:bytes %b2
  40. bytes b2 = hex"41";
  41. // NOT-CHECK: ty:bytes %b3
  42. bytes b3 = hex"caffee";
  43. bytes b4 = hex"77ea";
  44. // NOT-CHECK: push array ty:bytes value:bytes1 65
  45. b2.push(0x41);
  46. // NOT-CHECK: pop array ty:bytes
  47. b3.pop();
  48. // NOT-CHECK: builtin ArrayLength (%b4)
  49. uint32 c = b4.length;
  50. return (b1);
  51. }
  52. // BEGIN-CHECK: TestCase::TestCase::function::refPop__uint32
  53. function refPop(uint32[] memory arrMem) public {
  54. int128[] storage str_ref = st;
  55. // CHECK: push storage ty:int128 slot:%str_ref = int128 3
  56. str_ref.push(3);
  57. uint32[] memory ptr = arrMem;
  58. // CHECK: push array ty:uint32[] value:uint32 54
  59. ptr.push(54);
  60. }
  61. // BEGIN-CHECK: TestCase::TestCase::function::ohterTest
  62. function ohterTest() public pure returns (int24[] memory) {
  63. int24[] memory a1;
  64. int24[] memory ptr = a1;
  65. // CHECK: pop array ty:int24[]
  66. ptr.pop();
  67. return a1;
  68. }
  69. }