nested.carbon 5.8 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_expr/nested.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if_expr/nested.carbon
  10. fn F(a: bool, b: bool, c: bool) -> i32 {
  11. return if a then if b then 1 else 2 else if c then 3 else 4;
  12. }
  13. // CHECK:STDOUT: --- nested.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  17. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  18. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  19. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  22. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  24. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  25. // CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
  26. // CHECK:STDOUT: %.5: i32 = int_literal 4 [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  31. // CHECK:STDOUT: .Core = %Core
  32. // CHECK:STDOUT: .F = %F.decl
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  35. // CHECK:STDOUT: %import_ref.1: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  36. // CHECK:STDOUT: %import_ref.2: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  37. // CHECK:STDOUT: %import_ref.3: %Bool.type = import_ref ir7, inst+2, loaded [template = constants.%Bool]
  38. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  39. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  40. // CHECK:STDOUT: %bool.make_type.loc11_9: init type = call constants.%Bool() [template = bool]
  41. // CHECK:STDOUT: %.loc11_9.1: type = value_of_initializer %bool.make_type.loc11_9 [template = bool]
  42. // CHECK:STDOUT: %.loc11_9.2: type = converted %bool.make_type.loc11_9, %.loc11_9.1 [template = bool]
  43. // CHECK:STDOUT: %a.loc11_6.1: bool = param a
  44. // CHECK:STDOUT: @F.%a: bool = bind_name a, %a.loc11_6.1
  45. // CHECK:STDOUT: %bool.make_type.loc11_18: init type = call constants.%Bool() [template = bool]
  46. // CHECK:STDOUT: %.loc11_18.1: type = value_of_initializer %bool.make_type.loc11_18 [template = bool]
  47. // CHECK:STDOUT: %.loc11_18.2: type = converted %bool.make_type.loc11_18, %.loc11_18.1 [template = bool]
  48. // CHECK:STDOUT: %b.loc11_15.1: bool = param b
  49. // CHECK:STDOUT: @F.%b: bool = bind_name b, %b.loc11_15.1
  50. // CHECK:STDOUT: %bool.make_type.loc11_27: init type = call constants.%Bool() [template = bool]
  51. // CHECK:STDOUT: %.loc11_27.1: type = value_of_initializer %bool.make_type.loc11_27 [template = bool]
  52. // CHECK:STDOUT: %.loc11_27.2: type = converted %bool.make_type.loc11_27, %.loc11_27.1 [template = bool]
  53. // CHECK:STDOUT: %c.loc11_24.1: bool = param c
  54. // CHECK:STDOUT: @F.%c: bool = bind_name c, %c.loc11_24.1
  55. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %.loc11_36.1: type = value_of_initializer %int.make_type_32 [template = i32]
  57. // CHECK:STDOUT: %.loc11_36.2: type = converted %int.make_type_32, %.loc11_36.1 [template = i32]
  58. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @F(%a: bool, %b: bool, %c: bool) -> i32 {
  67. // CHECK:STDOUT: !entry:
  68. // CHECK:STDOUT: %a.ref: bool = name_ref a, %a
  69. // CHECK:STDOUT: if %a.ref br !if.expr.then.loc12_10 else br !if.expr.else.loc12_10
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !if.expr.then.loc12_10:
  72. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  73. // CHECK:STDOUT: if %b.ref br !if.expr.then.loc12_20 else br !if.expr.else.loc12_20
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !if.expr.then.loc12_20:
  76. // CHECK:STDOUT: %.loc12_30: i32 = int_literal 1 [template = constants.%.2]
  77. // CHECK:STDOUT: br !if.expr.result.loc12_20(%.loc12_30)
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !if.expr.else.loc12_20:
  80. // CHECK:STDOUT: %.loc12_37: i32 = int_literal 2 [template = constants.%.3]
  81. // CHECK:STDOUT: br !if.expr.result.loc12_20(%.loc12_37)
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !if.expr.result.loc12_20:
  84. // CHECK:STDOUT: %.loc12_20: i32 = block_arg !if.expr.result.loc12_20
  85. // CHECK:STDOUT: br !if.expr.result.loc12_10(%.loc12_20)
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !if.expr.else.loc12_10:
  88. // CHECK:STDOUT: %c.ref: bool = name_ref c, %c
  89. // CHECK:STDOUT: if %c.ref br !if.expr.then.loc12_44 else br !if.expr.else.loc12_44
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !if.expr.then.loc12_44:
  92. // CHECK:STDOUT: %.loc12_54: i32 = int_literal 3 [template = constants.%.4]
  93. // CHECK:STDOUT: br !if.expr.result.loc12_44(%.loc12_54)
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !if.expr.else.loc12_44:
  96. // CHECK:STDOUT: %.loc12_61: i32 = int_literal 4 [template = constants.%.5]
  97. // CHECK:STDOUT: br !if.expr.result.loc12_44(%.loc12_61)
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: !if.expr.result.loc12_44:
  100. // CHECK:STDOUT: %.loc12_44: i32 = block_arg !if.expr.result.loc12_44
  101. // CHECK:STDOUT: br !if.expr.result.loc12_10(%.loc12_44)
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !if.expr.result.loc12_10:
  104. // CHECK:STDOUT: %.loc12_10: i32 = block_arg !if.expr.result.loc12_10
  105. // CHECK:STDOUT: return %.loc12_10
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: