slice1.sol 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // RUN: --target polkadot --emit cfg
  2. contract c {
  3. // BEGIN-CHECK: c::function::test1
  4. function test1() public pure{
  5. bytes x = "foo1";
  6. // x is not being used, so it can be a slice bytes1
  7. // CHECK: alloc slice bytes1 uint32 4 "foo1"
  8. bytes y = x;
  9. }
  10. // BEGIN-CHECK: c::function::test2
  11. function test2() public pure returns (bytes) {
  12. bytes x = "foo2";
  13. x[1] = 0;
  14. return x;
  15. // x is being modified, so it must be a vector
  16. // CHECK: alloc bytes uint32 4 "foo2"
  17. }
  18. function foo(bytes x) pure internal {
  19. }
  20. // BEGIN-CHECK: c::function::test3
  21. function test3() public pure {
  22. bytes x = "foo3";
  23. foo(x);
  24. // no slices for function arguments yet, so it must be a vector
  25. // CHECK: alloc bytes uint32 4 "foo3"
  26. }
  27. // BEGIN-CHECK: c::function::test4
  28. function test4() public pure {
  29. string x = "foo4";
  30. // a bunch of stuff that does not need a vector
  31. if (x == "bar") {
  32. bool y = true;
  33. }
  34. string y = x + "if";
  35. print(x);
  36. // CHECK: alloc slice bytes1 uint32 4 "foo4"
  37. }
  38. // BEGIN-CHECK: c::function::test5
  39. function test5() public pure returns (bytes) {
  40. bytes x = "foo5";
  41. x.push(0);
  42. return x;
  43. // push modifies vectotr
  44. // CHECK: alloc bytes uint32 4 "foo5"
  45. }
  46. // BEGIN-CHECK: c::function::test6
  47. function test6() public pure returns (bytes) {
  48. bytes x = "foo6";
  49. x.pop();
  50. return x;
  51. // pop modifies vectotr
  52. // CHECK: alloc bytes uint32 4 "foo6"
  53. }
  54. // BEGIN-CHECK: c::function::test7
  55. function test7() public pure returns (bytes) {
  56. bytes x = "foo7";
  57. bytes y = x;
  58. y[1] = 0;
  59. return y;
  60. // x modified via y
  61. // CHECK: alloc bytes uint32 4 "foo7"
  62. }
  63. // BEGIN-CHECK: c::function::test8
  64. function test8() public pure returns (bytes) {
  65. string x = "foo8";
  66. bytes y = bytes(x);
  67. y[1] = 0;
  68. return y;
  69. // x modified via y
  70. // CHECK: alloc string uint32 4 "foo8"
  71. }
  72. }