unreachable_fallthrough.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 [template]
  22. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  23. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  24. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  25. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  26. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  27. // CHECK:STDOUT: %If.type: type = fn_type @If [template]
  28. // CHECK:STDOUT: %If: %If.type = struct_value () [template]
  29. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 1 [template]
  30. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  31. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  32. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  33. // CHECK:STDOUT: %.22: <witness> = interface_witness (%Convert.14) [template]
  34. // CHECK:STDOUT: %.23: <bound method> = bound_method %.2, %Convert.14 [template]
  35. // CHECK:STDOUT: %.24: <specific function> = specific_function %.23, @Convert.2(%.1) [template]
  36. // CHECK:STDOUT: %.25: %i32 = int_value 1 [template]
  37. // CHECK:STDOUT: %.26: Core.IntLiteral = int_value 2 [template]
  38. // CHECK:STDOUT: %.27: <bound method> = bound_method %.26, %Convert.14 [template]
  39. // CHECK:STDOUT: %.28: <specific function> = specific_function %.27, @Convert.2(%.1) [template]
  40. // CHECK:STDOUT: %.29: %i32 = int_value 2 [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  45. // CHECK:STDOUT: .Bool = %import_ref.1
  46. // CHECK:STDOUT: .Int = %import_ref.2
  47. // CHECK:STDOUT: .ImplicitAs = %import_ref.3
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .If = %If.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [template = constants.%If] {
  60. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  61. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, runtime_param0
  62. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  63. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  66. // CHECK:STDOUT: %.loc11_10.1: type = value_of_initializer %bool.make_type [template = bool]
  67. // CHECK:STDOUT: %.loc11_10.2: type = converted %bool.make_type, %.loc11_10.1 [template = bool]
  68. // CHECK:STDOUT: %.loc11_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  69. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc11_19.1) [template = constants.%i32]
  70. // CHECK:STDOUT: %.loc11_19.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  71. // CHECK:STDOUT: %.loc11_19.3: type = converted %int.make_type_signed, %.loc11_19.2 [template = constants.%i32]
  72. // CHECK:STDOUT: %b.param: bool = value_param runtime_param0
  73. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  74. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  75. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @If(%b.param_patt: bool) -> %i32 {
  80. // CHECK:STDOUT: !entry:
  81. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  82. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !if.then:
  85. // CHECK:STDOUT: %.loc13_12: Core.IntLiteral = int_value 1 [template = constants.%.2]
  86. // CHECK:STDOUT: %.loc13_13.1: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  87. // CHECK:STDOUT: %.loc13_13.2: <bound method> = bound_method %.loc13_12, %.loc13_13.1 [template = constants.%.23]
  88. // CHECK:STDOUT: %.loc13_13.3: <specific function> = specific_function %.loc13_13.2, @Convert.2(constants.%.1) [template = constants.%.24]
  89. // CHECK:STDOUT: %int.convert_checked.loc13: init %i32 = call %.loc13_13.3(%.loc13_12) [template = constants.%.25]
  90. // CHECK:STDOUT: %.loc13_13.4: %i32 = value_of_initializer %int.convert_checked.loc13 [template = constants.%.25]
  91. // CHECK:STDOUT: %.loc13_13.5: %i32 = converted %.loc13_12, %.loc13_13.4 [template = constants.%.25]
  92. // CHECK:STDOUT: return %.loc13_13.5
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !if.else:
  95. // CHECK:STDOUT: %.loc15_12: Core.IntLiteral = int_value 2 [template = constants.%.26]
  96. // CHECK:STDOUT: %.loc15_13.1: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  97. // CHECK:STDOUT: %.loc15_13.2: <bound method> = bound_method %.loc15_12, %.loc15_13.1 [template = constants.%.27]
  98. // CHECK:STDOUT: %.loc15_13.3: <specific function> = specific_function %.loc15_13.2, @Convert.2(constants.%.1) [template = constants.%.28]
  99. // CHECK:STDOUT: %int.convert_checked.loc15: init %i32 = call %.loc15_13.3(%.loc15_12) [template = constants.%.29]
  100. // CHECK:STDOUT: %.loc15_13.4: %i32 = value_of_initializer %int.convert_checked.loc15 [template = constants.%.29]
  101. // CHECK:STDOUT: %.loc15_13.5: %i32 = converted %.loc15_12, %.loc15_13.4 [template = constants.%.29]
  102. // CHECK:STDOUT: return %.loc15_13.5
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: