empty_struct.carbon 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/call/empty_struct.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/empty_struct.carbon
  14. fn Echo(a: {}) -> {} {
  15. return a;
  16. }
  17. fn Main() {
  18. Echo({});
  19. }
  20. // CHECK:STDOUT: --- empty_struct.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  24. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  25. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_struct_type [concrete]
  26. // CHECK:STDOUT: %.305: Core.Form = init_form %empty_struct_type, call_param1 [concrete]
  27. // CHECK:STDOUT: %Echo.type: type = fn_type @Echo [concrete]
  28. // CHECK:STDOUT: %Echo: %Echo.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  30. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: file {
  34. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  35. // CHECK:STDOUT: .Echo = %Echo.decl
  36. // CHECK:STDOUT: .Main = %Main.decl
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Echo.decl: %Echo.type = fn_decl @Echo [concrete = constants.%Echo] {
  39. // CHECK:STDOUT: %a.patt: %pattern_type = value_binding_pattern a [concrete]
  40. // CHECK:STDOUT: %a.param_patt: %pattern_type = value_param_pattern %a.patt, call_param0 [concrete]
  41. // CHECK:STDOUT: %return.patt: %pattern_type = return_slot_pattern [concrete]
  42. // CHECK:STDOUT: %return.param_patt: %pattern_type = out_param_pattern %return.patt, call_param1 [concrete]
  43. // CHECK:STDOUT: } {
  44. // CHECK:STDOUT: %.loc15_20.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  45. // CHECK:STDOUT: %.loc15_20.2: type = converted %.loc15_20.1, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  46. // CHECK:STDOUT: %.loc15_20.3: Core.Form = init_form %.loc15_20.2, call_param1 [concrete = constants.%.305]
  47. // CHECK:STDOUT: %a.param: %empty_struct_type = value_param call_param0
  48. // CHECK:STDOUT: %.loc15_13.1: type = splice_block %.loc15_13.3 [concrete = constants.%empty_struct_type] {
  49. // CHECK:STDOUT: %.loc15_13.2: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  50. // CHECK:STDOUT: %.loc15_13.3: type = converted %.loc15_13.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %a: %empty_struct_type = value_binding a, %a.param
  53. // CHECK:STDOUT: %return.param: ref %empty_struct_type = out_param call_param1
  54. // CHECK:STDOUT: %return: ref %empty_struct_type = return_slot %return.param
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @Echo(%a.param: %empty_struct_type) -> out %return.param: %empty_struct_type {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: %a.ref: %empty_struct_type = name_ref a, %a
  62. // CHECK:STDOUT: %.loc16_10: init %empty_struct_type = struct_init () [concrete = constants.%empty_struct]
  63. // CHECK:STDOUT: %.loc16_11: init %empty_struct_type = converted %a.ref, %.loc16_10 [concrete = constants.%empty_struct]
  64. // CHECK:STDOUT: return %.loc16_11
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: fn @Main() {
  68. // CHECK:STDOUT: !entry:
  69. // CHECK:STDOUT: %Echo.ref: %Echo.type = name_ref Echo, file.%Echo.decl [concrete = constants.%Echo]
  70. // CHECK:STDOUT: %.loc20_9.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  71. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  72. // CHECK:STDOUT: %.loc20_9.2: %empty_struct_type = converted %.loc20_9.1, %empty_struct [concrete = constants.%empty_struct]
  73. // CHECK:STDOUT: %Echo.call: init %empty_struct_type = call %Echo.ref(%.loc20_9.2)
  74. // CHECK:STDOUT: return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: