struct.carbon 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/return/struct.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/return/struct.carbon
  10. fn Main() -> {.a: i32} {
  11. return {.a = 3};
  12. }
  13. // CHECK:STDOUT: --- struct.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  17. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  18. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  19. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  20. // CHECK:STDOUT: %.2: type = struct_type {.a: %i32} [template]
  21. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  22. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  23. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 3 [template]
  24. // CHECK:STDOUT: %.4: type = struct_type {.a: Core.IntLiteral} [template]
  25. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  26. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  27. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  28. // CHECK:STDOUT: %.28: <witness> = interface_witness (%Convert.14) [template]
  29. // CHECK:STDOUT: %.29: <bound method> = bound_method %.3, %Convert.14 [template]
  30. // CHECK:STDOUT: %.30: <specific function> = specific_function %.29, @Convert.2(%.1) [template]
  31. // CHECK:STDOUT: %.31: %i32 = int_value 3 [template]
  32. // CHECK:STDOUT: %struct: %.2 = struct_value (%.31) [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  37. // CHECK:STDOUT: .Int = %import_ref.1
  38. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  39. // CHECK:STDOUT: import Core//prelude
  40. // CHECK:STDOUT: import Core//prelude/...
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = imports.%Core
  47. // CHECK:STDOUT: .Main = %Main.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.import = import Core
  50. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {
  51. // CHECK:STDOUT: %return.patt: %.2 = return_slot_pattern
  52. // CHECK:STDOUT: %return.param_patt: %.2 = out_param_pattern %return.patt, runtime_param0
  53. // CHECK:STDOUT: } {
  54. // CHECK:STDOUT: %.loc11_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  55. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc11_19.1) [template = constants.%i32]
  56. // CHECK:STDOUT: %.loc11_19.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  57. // CHECK:STDOUT: %.loc11_19.3: type = converted %int.make_type_signed, %.loc11_19.2 [template = constants.%i32]
  58. // CHECK:STDOUT: %.loc11_22: type = struct_type {.a: %i32} [template = constants.%.2]
  59. // CHECK:STDOUT: %return.param: ref %.2 = out_param runtime_param0
  60. // CHECK:STDOUT: %return: ref %.2 = return_slot %return.param
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @Main() -> %.2 {
  65. // CHECK:STDOUT: !entry:
  66. // CHECK:STDOUT: %.loc12_16: Core.IntLiteral = int_value 3 [template = constants.%.3]
  67. // CHECK:STDOUT: %.loc12_17.1: %.4 = struct_literal (%.loc12_16)
  68. // CHECK:STDOUT: %.loc12_17.2: %Convert.type.2 = interface_witness_access constants.%.28, element0 [template = constants.%Convert.14]
  69. // CHECK:STDOUT: %.loc12_17.3: <bound method> = bound_method %.loc12_16, %.loc12_17.2 [template = constants.%.29]
  70. // CHECK:STDOUT: %.loc12_17.4: <specific function> = specific_function %.loc12_17.3, @Convert.2(constants.%.1) [template = constants.%.30]
  71. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc12_17.4(%.loc12_16) [template = constants.%.31]
  72. // CHECK:STDOUT: %.loc12_17.5: %i32 = value_of_initializer %int.convert_checked [template = constants.%.31]
  73. // CHECK:STDOUT: %.loc12_17.6: %i32 = converted %.loc12_16, %.loc12_17.5 [template = constants.%.31]
  74. // CHECK:STDOUT: %struct: %.2 = struct_value (%.loc12_17.6) [template = constants.%struct]
  75. // CHECK:STDOUT: %.loc12_18: %.2 = converted %.loc12_17.1, %struct [template = constants.%struct]
  76. // CHECK:STDOUT: return %.loc12_18
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: