unreachable_fallthrough.carbon 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/unreachable_fallthrough.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if/unreachable_fallthrough.carbon
  10. fn If(b: bool) -> i32 {
  11. if (b) {
  12. return 1;
  13. } else {
  14. return 2;
  15. }
  16. // Missing return here is OK.
  17. }
  18. // CHECK:STDOUT: --- unreachable_fallthrough.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  22. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  23. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  24. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  25. // CHECK:STDOUT: %If.type: type = fn_type @If [concrete]
  26. // CHECK:STDOUT: %If: %If.type = struct_value () [concrete]
  27. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete]
  28. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  29. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  30. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete]
  31. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  32. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  33. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  34. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  35. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  36. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [concrete]
  37. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  38. // CHECK:STDOUT: %bound_method.9a1: <bound method> = bound_method %int_1.5b8, %Convert.specific_fn [concrete]
  39. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  40. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [concrete]
  41. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [concrete]
  42. // CHECK:STDOUT: %bound_method.b92: <bound method> = bound_method %int_2.ecc, %Convert.specific_fn [concrete]
  43. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  48. // CHECK:STDOUT: .Bool = %Core.Bool
  49. // CHECK:STDOUT: .Int = %Core.Int
  50. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .If = %If.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.import = import Core
  62. // CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [concrete = constants.%If] {
  63. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  64. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, call_param0
  65. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  66. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param1
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  69. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  70. // CHECK:STDOUT: %b.param: bool = value_param call_param0
  71. // CHECK:STDOUT: %.loc11_10.1: type = splice_block %.loc11_10.3 [concrete = bool] {
  72. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  73. // CHECK:STDOUT: %.loc11_10.2: type = value_of_initializer %bool.make_type [concrete = bool]
  74. // CHECK:STDOUT: %.loc11_10.3: type = converted %bool.make_type, %.loc11_10.2 [concrete = bool]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  77. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  78. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @If(%b.param: bool) -> %i32 {
  83. // CHECK:STDOUT: !entry:
  84. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  85. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !if.then:
  88. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
  89. // CHECK:STDOUT: %impl.elem0.loc13: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  90. // CHECK:STDOUT: %bound_method.loc13_13.1: <bound method> = bound_method %int_1, %impl.elem0.loc13 [concrete = constants.%Convert.bound.ab5]
  91. // CHECK:STDOUT: %specific_fn.loc13: <specific function> = specific_function %impl.elem0.loc13, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  92. // CHECK:STDOUT: %bound_method.loc13_13.2: <bound method> = bound_method %int_1, %specific_fn.loc13 [concrete = constants.%bound_method.9a1]
  93. // CHECK:STDOUT: %int.convert_checked.loc13: init %i32 = call %bound_method.loc13_13.2(%int_1) [concrete = constants.%int_1.5d2]
  94. // CHECK:STDOUT: %.loc13_13.1: %i32 = value_of_initializer %int.convert_checked.loc13 [concrete = constants.%int_1.5d2]
  95. // CHECK:STDOUT: %.loc13_13.2: %i32 = converted %int_1, %.loc13_13.1 [concrete = constants.%int_1.5d2]
  96. // CHECK:STDOUT: return %.loc13_13.2
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !if.else:
  99. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2.ecc]
  100. // CHECK:STDOUT: %impl.elem0.loc15: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  101. // CHECK:STDOUT: %bound_method.loc15_13.1: <bound method> = bound_method %int_2, %impl.elem0.loc15 [concrete = constants.%Convert.bound.ef9]
  102. // CHECK:STDOUT: %specific_fn.loc15: <specific function> = specific_function %impl.elem0.loc15, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  103. // CHECK:STDOUT: %bound_method.loc15_13.2: <bound method> = bound_method %int_2, %specific_fn.loc15 [concrete = constants.%bound_method.b92]
  104. // CHECK:STDOUT: %int.convert_checked.loc15: init %i32 = call %bound_method.loc15_13.2(%int_2) [concrete = constants.%int_2.ef8]
  105. // CHECK:STDOUT: %.loc15_13.1: %i32 = value_of_initializer %int.convert_checked.loc15 [concrete = constants.%int_2.ef8]
  106. // CHECK:STDOUT: %.loc15_13.2: %i32 = converted %int_2, %.loc15_13.1 [concrete = constants.%int_2.ef8]
  107. // CHECK:STDOUT: return %.loc15_13.2
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: