switch_simplify.sol 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // RUN: --target solana --emit cfg
  2. contract test {
  3. // BEGIN-CHECK: test::test::function::test_1
  4. function test_1() public pure returns (int) {
  5. int gg = 56;
  6. int res = 0;
  7. assembly {
  8. // NOT-CHECK: switch
  9. // CHECK: branch block3
  10. switch add(gg, 4)
  11. case 5 {
  12. res := 90
  13. }
  14. case 60 {
  15. // CHECK: block3: # case_1
  16. // CHECK: ty:int256 %res = int256 4
  17. res := 4
  18. }
  19. default {
  20. res := 7
  21. }
  22. }
  23. return res;
  24. }
  25. // BEGIN-CHECK: test::test::function::test_2
  26. function test_2() public pure returns (int) {
  27. int gg = 56;
  28. int res = 0;
  29. assembly {
  30. // NOT-CHECK: switch
  31. // CHECK: branch block4
  32. switch add(gg, 4)
  33. case 5 {
  34. res := 90
  35. }
  36. case 6 {
  37. res := 4
  38. }
  39. default {
  40. // CHECK: block4: # default
  41. // CHECK: ty:int256 %res = int256 7
  42. res := 7
  43. }
  44. }
  45. return res;
  46. }
  47. // BEGIN-CHECK: test::test::function::test_3
  48. function test_3() public pure returns (int) {
  49. int gg = 56;
  50. int res = 0;
  51. assembly {
  52. // NOT-CHECK: switch
  53. // CHECK: branch block1
  54. switch add(gg, 4)
  55. case 5 {
  56. res := 90
  57. }
  58. case 6 {
  59. res := 4
  60. }
  61. }
  62. // CHECK: block1: # end_switch
  63. // CHECK: return %res
  64. return res;
  65. }
  66. }