else.carbon 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/if/else.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if/else.carbon
  10. fn F() {}
  11. fn G() {}
  12. fn H() {}
  13. fn If(b: bool) {
  14. if (b) {
  15. F();
  16. } else {
  17. G();
  18. }
  19. H();
  20. }
  21. // CHECK:STDOUT: --- else.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  25. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  26. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  27. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  28. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  29. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  30. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  31. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  32. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  33. // CHECK:STDOUT: %If.type: type = fn_type @If [template]
  34. // CHECK:STDOUT: %If: %If.type = struct_value () [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: imports {
  38. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  39. // CHECK:STDOUT: .Bool = %Core.Bool
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/...
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .F = %F.decl
  49. // CHECK:STDOUT: .G = %G.decl
  50. // CHECK:STDOUT: .H = %H.decl
  51. // CHECK:STDOUT: .If = %If.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  55. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  56. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  57. // CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [template = constants.%If] {
  58. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  59. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, runtime_param0
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %b.param: bool = value_param runtime_param0
  62. // CHECK:STDOUT: %.loc15_10.1: type = splice_block %.loc15_10.3 [template = bool] {
  63. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  64. // CHECK:STDOUT: %.loc15_10.2: type = value_of_initializer %bool.make_type [template = bool]
  65. // CHECK:STDOUT: %.loc15_10.3: type = converted %bool.make_type, %.loc15_10.2 [template = bool]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @F() {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: return
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @G() {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: return
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @H() {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: return
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @If(%b.param_patt: bool) {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  89. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !if.then:
  92. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  93. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
  94. // CHECK:STDOUT: br !if.done
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: !if.else:
  97. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
  98. // CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.ref()
  99. // CHECK:STDOUT: br !if.done
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !if.done:
  102. // CHECK:STDOUT: %H.ref: %H.type = name_ref H, file.%H.decl [template = constants.%H]
  103. // CHECK:STDOUT: %H.call: init %empty_tuple.type = call %H.ref()
  104. // CHECK:STDOUT: return
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: