slice1.sol 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // RUN: --target substrate --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 bytes1 slice
  7. // CHECK: alloc bytes1 slice 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 bytes1 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 bytes1 slice 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 {
  48. bytes x = "foo6";
  49. x.pop();
  50. // pop modifies vectotr
  51. // CHECK: alloc bytes uint32 4 "foo6"
  52. }
  53. // BEGIN-CHECK: c::function::test7
  54. function test7() public pure returns (bytes) {
  55. bytes x = "foo7";
  56. bytes y = x;
  57. y[1] = 0;
  58. return y;
  59. // x modified via y
  60. // CHECK: alloc bytes uint32 4 "foo7"
  61. }
  62. // BEGIN-CHECK: c::function::test8
  63. function test8() public pure returns (bytes) {
  64. string x = "foo8";
  65. bytes y = bytes(x);
  66. y[1] = 0;
  67. return y;
  68. // x modified via y
  69. // CHECK: alloc string uint32 4 "foo8"
  70. }
  71. }