unused_variable_elimination.sol 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // RUN: --target polkadot --emit cfg
  2. contract c2 {
  3. int public cd;
  4. function sum(int32 a, int32 b) public pure returns (int32) {
  5. return a + b;
  6. }
  7. // BEGIN-CHECK: function::doSomething
  8. function doSomething() public returns (int, int) {
  9. cd = 2;
  10. // CHECK: store storage slot(uint256 0) ty:int256 =
  11. return (1, 2);
  12. }
  13. }
  14. contract c {
  15. int32 g;
  16. // BEGIN-CHECK: c::function::test
  17. function test() public returns (int32) {
  18. int32 x = 102;
  19. g = 3;
  20. return 5;
  21. // NOT-CHECK: ty:int32 %x = int32 102
  22. }
  23. // BEGIN-CHECK: c::function::test2
  24. function test2() public view returns (int32) {
  25. int32 x = 102;
  26. int32 y = 93;
  27. int32 t = 9;
  28. x = 102 + (t * y) / (t + 5 * y) + g;
  29. return 2;
  30. // NOT-CHECK: ty:int32 %x = int32 102
  31. // NOT-CHECK: ty:int32 %x = (int32 103 + %temp.6)
  32. }
  33. // BEGIN-CHECK: c::function::test3
  34. function test3() public view returns (int32) {
  35. int32 x;
  36. int32 y = 93;
  37. int32 t = 9;
  38. x = 102 + (t * y) / (t + 5 * y) + g;
  39. return 2;
  40. // NOT-CHECK: ty:int32 %x = (int32 103 + %temp.6)
  41. }
  42. // BEGIN-CHECK: c::function::test4
  43. function test4() public view returns (int32) {
  44. int32 x;
  45. int32 y = 93;
  46. int32 t = 9;
  47. x = 102 + (t * y) / (t + 5 * y) + g + test3();
  48. return 2;
  49. // NOT-CHECK: ty:int32 %x = (int32 103 + %temp.6)
  50. // CHECK: call c::c::function::test3
  51. }
  52. // BEGIN-CHECK: c::function::test5
  53. function test5() public returns (int32) {
  54. int32 x;
  55. int32[] vec;
  56. int32 y = 93;
  57. int32 t = 9;
  58. c2 ct = new c2();
  59. x =
  60. 102 +
  61. (t * y) /
  62. (t + 5 * y) +
  63. g +
  64. test3() -
  65. vec.push(2) +
  66. ct.sum(1, 2);
  67. return 2;
  68. // CHECK: push array ty:int32[] value:int32 2
  69. // CHECK: external call::regular address:%ct
  70. // CHECK: return int32 2
  71. }
  72. }
  73. contract c3 {
  74. // BEGIN-CHECK: c3::function::test6
  75. function test6() public returns (int32) {
  76. c2 ct = new c2();
  77. return 3;
  78. // CHECK: constructor(no: ) salt: value: gas:uint64 0 address: seeds: c2 encoded buffer: %abi_encoded.temp.120 accounts:
  79. }
  80. // BEGIN-CHECK: c3::function::test7
  81. function test7() public returns (int32) {
  82. c2 ct = new c2();
  83. // constructor salt: value: gas:uint64 0 address: seeds: c2 (encoded buffer: %abi_encoded.temp.123, buffer len: uint32 4)
  84. address ad = address(ct);
  85. (bool p, ) = ad.call(hex"ba");
  86. // CHECK: external call::regular address:%ad payload:(alloc bytes uint32 1 hex"ba") value:uint128 0 gas:uint64 0
  87. // NOT-CHECk: ty:bool %p = %success.temp
  88. return 3;
  89. }
  90. struct testStruct {
  91. int a;
  92. int b;
  93. }
  94. testStruct t1;
  95. int public it1;
  96. int private it2;
  97. // BEGIN-CHECK: c3::function::test8
  98. function test8() public returns (int) {
  99. testStruct storage t2 = t1;
  100. t2.a = 5;
  101. it1 = 2;
  102. testStruct memory t3 = testStruct(1, 2);
  103. int[] memory vec = new int[](5);
  104. vec[0] = 3;
  105. it2 = 1;
  106. return 2;
  107. // CHECK: store storage slot((overflowing %t2 + uint256 0)) ty:int256 =
  108. // CHECK: store storage slot(uint256 2) ty:int256 =
  109. // NOT-CHECK: ty:struct c1.testStruct %t3 = struct { int256 1, int256 2 }
  110. // NOT-CHECK: alloc int256[] len uint32 5
  111. // NOT-CHECK: store storage slot(uint256 3) ty:int256
  112. }
  113. // BEGIN-CHECK: c3::function::test9
  114. function test9() public view returns (int) {
  115. int f = 4;
  116. int c = 32 + 4 * (f = it1 + it2);
  117. //CHECK: ty:int256 %f =
  118. return f;
  119. }
  120. // BEGIN-CHECK: c3::function::test10
  121. function test10() public view returns (int) {
  122. int f = 4;
  123. int c = 32 + 4 * (f = it1 + it2);
  124. // CHECK: ty:int256 %c = (int256 32 + (sext int256 (int64 4 * (trunc int64 (%temp.130 + %temp.131)))))
  125. // NOT-CHECK: ty:int256 %f = (%temp.
  126. return c;
  127. }
  128. // BEGIN-CHECK: c3::function::test11
  129. function test11() public returns (int) {
  130. c2 ct = new c2();
  131. (int a, int b) = ct.doSomething();
  132. // CHECK: ty:int256 %b =
  133. // NOT-CHECK: ty:int256 %a =
  134. return b;
  135. }
  136. // BEGIN-CHECK: c3::function::test12
  137. function test12() public returns (int) {
  138. c2 ct = new c2();
  139. int a = 1;
  140. int b = 2;
  141. (a, b) = ct.doSomething();
  142. // CHECK: ty:int256 %a =
  143. // NOT-CHECK: ty:int256 %b =
  144. return a;
  145. }
  146. // BEGIN-CHECK: c3::function::test13
  147. function test13() public returns (int) {
  148. int[] memory vec = new int[](5);
  149. // CHECK: alloc int256[] len uint32 5
  150. vec[0] = 3;
  151. return vec[1];
  152. }
  153. int[] testArr;
  154. // BEGIN-CHECK: c3::function::test14
  155. function test14() public returns (int) {
  156. int[] storage ptrArr = testArr;
  157. // CHECK: store storage slot(%temp.154) ty:int256 storage = int256 3
  158. ptrArr.push(3);
  159. return ptrArr[0];
  160. }
  161. // BEGIN-CHECK: c3::function::test15
  162. function test15() public returns (int) {
  163. int[4] memory arr = [1, 2, 3, 4];
  164. // CHECK: ty:int256[4] %arr = [4] [ int256 1, int256 2, int256 3, int256 4 ]
  165. return arr[2];
  166. }
  167. // BEGIN-CHECK: c3::function::test16
  168. function test16() public returns (int) {
  169. int[4] memory arr = [1, 2, 3, 4];
  170. // NOT-CHECK: ty:int256[4] %arr = [4] [ int256 1, int256 2, int256 3, int256 4 ]
  171. return 2;
  172. }
  173. // BEGIN-CHECK: c3::function::test17
  174. function test17() public pure returns (int) {
  175. int x;
  176. // NOT-CHECK: ty:int256 %x
  177. int[] vec = new int[](2);
  178. x = 5 * vec.pop();
  179. return 0;
  180. // CHECK: pop array ty:int256[]
  181. }
  182. // BEGIN-CHECK: c3::function::test18
  183. function test18(address payable addr) public payable returns (bool) {
  184. bool p;
  185. p = false || addr.send(msg.value);
  186. // CHECK: value transfer address
  187. return true;
  188. }
  189. int[] arrt;
  190. // BEGIN-CHECK: c3::function::test19
  191. function test19() public returns (int) {
  192. int x;
  193. // NOT-CHECK: ty:int256 %x
  194. int y;
  195. x = y + arrt.pop();
  196. // NOT-CHECK: clear storage slot
  197. return 0;
  198. }
  199. bytes bar;
  200. // BEGIN-CHECK: c3::function::test20
  201. function test20() public {
  202. bytes1 x = bar.push();
  203. // NOT-CHECK: ty:bytes1 %x
  204. // CHECK: push storage ty:bytes1 slot
  205. }
  206. }