else.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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: %.1: 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: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .Core = %Core
  40. // CHECK:STDOUT: .F = %F.decl
  41. // CHECK:STDOUT: .G = %G.decl
  42. // CHECK:STDOUT: .H = %H.decl
  43. // CHECK:STDOUT: .If = %If.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  46. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  47. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {}
  48. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {}
  49. // CHECK:STDOUT: %import_ref: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  50. // CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [template = constants.%If] {
  51. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  52. // CHECK:STDOUT: %.loc15_10.1: type = value_of_initializer %bool.make_type [template = bool]
  53. // CHECK:STDOUT: %.loc15_10.2: type = converted %bool.make_type, %.loc15_10.1 [template = bool]
  54. // CHECK:STDOUT: %b.loc15_7.1: bool = param b
  55. // CHECK:STDOUT: @If.%b: bool = bind_name b, %b.loc15_7.1
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @F() {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: return
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @G() {
  65. // CHECK:STDOUT: !entry:
  66. // CHECK:STDOUT: return
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @H() {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: return
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @If(%b: bool) {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  79. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !if.then:
  82. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  83. // CHECK:STDOUT: %F.call: init %.1 = call %F.ref()
  84. // CHECK:STDOUT: br !if.done
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !if.else:
  87. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
  88. // CHECK:STDOUT: %G.call: init %.1 = call %G.ref()
  89. // CHECK:STDOUT: br !if.done
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !if.done:
  92. // CHECK:STDOUT: %H.ref: %H.type = name_ref H, file.%H.decl [template = constants.%H]
  93. // CHECK:STDOUT: %H.call: init %.1 = call %H.ref()
  94. // CHECK:STDOUT: return
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: