unused_variable_elimination.sol 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // RUN: --target substrate --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 = 102 + t*y/(t+5*y) + g + test3() - vec.push(2) + ct.sum(1, 2);
  60. return 2;
  61. // CHECK: push array ty:int32[] value:int32 2
  62. // CHECK: _ = external call::regular address:%ct payload:%abi_encoded.temp.75 value:uint128 0 gas:uint64 0 accounts: seeds:
  63. }
  64. }
  65. contract c3 {
  66. // BEGIN-CHECK: c3::function::test6
  67. function test6() public returns (int32) {
  68. c2 ct = new c2();
  69. return 3;
  70. // CHECK: constructor salt: value: gas:uint64 0 address: seeds: c2 (encoded buffer: %abi_encoded.temp.80, buffer len: uint32 4)
  71. }
  72. // BEGIN-CHECK: c3::function::test7
  73. function test7() public returns (int32) {
  74. c2 ct = new c2();
  75. // constructor salt: value: gas:uint64 0 address: seeds: c2 (encoded buffer: %abi_encoded.temp.82, buffer len: uint32 4)
  76. address ad = address(ct);
  77. (bool p, ) = ad.call(hex'ba');
  78. // CHECK: external call::regular address:%ad payload:(alloc bytes uint32 1 hex"ba") value:uint128 0 gas:uint64 0
  79. // NOT-CHECk: ty:bool %p = %success.temp.30
  80. return 3;
  81. }
  82. struct testStruct {
  83. int a;
  84. int b;
  85. }
  86. testStruct t1;
  87. int public it1;
  88. int private it2;
  89. // BEGIN-CHECK: c3::function::test8
  90. function test8() public returns (int){
  91. testStruct storage t2 = t1;
  92. t2.a = 5;
  93. it1 = 2;
  94. testStruct memory t3 = testStruct(1, 2);
  95. int[] memory vec = new int[](5);
  96. vec[0] = 3;
  97. it2 = 1;
  98. return 2;
  99. // CHECK: store storage slot((unchecked %t2 + uint256 0)) ty:int256 =
  100. // CHECK: store storage slot(uint256 2) ty:int256 =
  101. // NOT-CHECK: ty:struct c1.testStruct %t3 = struct { int256 1, int256 2 }
  102. // NOT-CHECK: alloc int256[] len uint32 5
  103. // NOT-CHECK: store storage slot(uint256 3) ty:int256
  104. }
  105. // BEGIN-CHECK: c3::function::test9
  106. function test9() public view returns (int) {
  107. int f = 4;
  108. int c = 32 +4 *(f = it1+it2);
  109. //CHECK: ty:int256 %f =
  110. return f;
  111. }
  112. // BEGIN-CHECK: c3::function::test10
  113. function test10() public view returns (int) {
  114. int f = 4;
  115. int c = 32 +4 *(f = it1+it2);
  116. // CHECK: ty:int256 %c = (int256 32 + (sext int256 (int64 4 * (trunc int64 (%temp.89 + %temp.90)))))
  117. // NOT-CHECK: ty:int256 %f = (%temp.10 + %temp.11)
  118. return c;
  119. }
  120. // BEGIN-CHECK: c3::function::test11
  121. function test11() public returns (int) {
  122. c2 ct = new c2();
  123. (int a, int b) = ct.doSomething();
  124. // CHECK: ty:int256 %b =
  125. // NOT-CHECK: ty:int256 %a =
  126. return b;
  127. }
  128. // BEGIN-CHECK: c3::function::test12
  129. function test12() public returns (int) {
  130. c2 ct = new c2();
  131. int a = 1;
  132. int b = 2;
  133. (a, b) = ct.doSomething();
  134. // CHECK: ty:int256 %a =
  135. // NOT-CHECK: ty:int256 %b =
  136. return a;
  137. }
  138. // BEGIN-CHECK: c3::function::test13
  139. function test13() public returns (int){
  140. int[] memory vec = new int[](5);
  141. // CHECK: alloc int256[] len uint32 5
  142. vec[0] = 3;
  143. return vec[1];
  144. }
  145. int[] testArr;
  146. // BEGIN-CHECK: c3::function::test14
  147. function test14() public returns (int) {
  148. int[] storage ptrArr = testArr;
  149. // CHECK: store storage slot(%temp.109) ty:int256 storage = int256 3
  150. ptrArr.push(3);
  151. return ptrArr[0];
  152. }
  153. // BEGIN-CHECK: c3::function::test15
  154. function test15() public returns (int) {
  155. int[4] memory arr = [1, 2, 3, 4];
  156. // CHECK: ty:int256[4] %arr = [4] [ int256 1, int256 2, int256 3, int256 4 ]
  157. return arr[2];
  158. }
  159. // BEGIN-CHECK: c3::function::test16
  160. function test16() public returns (int) {
  161. int[4] memory arr = [1, 2, 3, 4];
  162. // NOT-CHECK: ty:int256[4] %arr = [4] [ int256 1, int256 2, int256 3, int256 4 ]
  163. return 2;
  164. }
  165. // BEGIN-CHECK: c3::function::test17
  166. function test17() public pure returns (int) {
  167. int x;
  168. // NOT-CHECK: ty:int256 %x
  169. int[] vec = new int[](2);
  170. x = 5*vec.pop();
  171. return 0;
  172. // CHECK: pop array ty:int256[]
  173. }
  174. // BEGIN-CHECK: c3::function::test18
  175. function test18(address payable addr) public returns (bool) {
  176. bool p;
  177. p = false || addr.send(msg.value);
  178. // CHECK: value transfer address
  179. return true;
  180. }
  181. int[] arrt;
  182. // BEGIN-CHECK: c3::function::test19
  183. function test19() public returns (int) {
  184. int x;
  185. // NOT-CHECK: ty:int256 %x
  186. int y;
  187. x = y + arrt.pop();
  188. // NOT-CHECK: clear storage slot
  189. return 0;
  190. }
  191. bytes bar;
  192. // BEGIN-CHECK: c3::function::test20
  193. function test20() public {
  194. bytes1 x = bar.push();
  195. // NOT-CHECK: ty:bytes1 %x
  196. // CHECK: push storage ty:bytes1 slot
  197. }
  198. }