unreachable_fallthrough.carbon 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: %.1: type = tuple_type () [template]
  23. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  24. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  25. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  26. // CHECK:STDOUT: %If.type: type = fn_type @If [template]
  27. // CHECK:STDOUT: %If: %If.type = struct_value () [template]
  28. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  29. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  34. // CHECK:STDOUT: .Bool = %import_ref.1
  35. // CHECK:STDOUT: .Int32 = %import_ref.2
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %import_ref.1: %Bool.type = import_ref Core//prelude/types/bool, inst+5, loaded [template = constants.%Bool]
  40. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .If = %If.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [template = constants.%If] {
  50. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  51. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, runtime_param0
  52. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  53. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param1
  54. // CHECK:STDOUT: } {
  55. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  56. // CHECK:STDOUT: %.loc11_10.1: type = value_of_initializer %bool.make_type [template = bool]
  57. // CHECK:STDOUT: %.loc11_10.2: type = converted %bool.make_type, %.loc11_10.1 [template = bool]
  58. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc11_19.1: type = value_of_initializer %int.make_type_32 [template = i32]
  60. // CHECK:STDOUT: %.loc11_19.2: type = converted %int.make_type_32, %.loc11_19.1 [template = i32]
  61. // CHECK:STDOUT: %b.param: bool = value_param runtime_param0
  62. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  63. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param1
  64. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @If(%b.param_patt: bool) -> i32 {
  73. // CHECK:STDOUT: !entry:
  74. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  75. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !if.then:
  78. // CHECK:STDOUT: %.loc13: i32 = int_literal 1 [template = constants.%.2]
  79. // CHECK:STDOUT: return %.loc13
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !if.else:
  82. // CHECK:STDOUT: %.loc15: i32 = int_literal 2 [template = constants.%.3]
  83. // CHECK:STDOUT: return %.loc15
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: