two_entries.carbon 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/struct/two_entries.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/two_entries.carbon
  10. let v: {.a: i32, .b: i32} = {.a = 1, .b = 2};
  11. let w: {.a: i32, .b: i32} = v;
  12. var x: {.a: i32, .b: i32} = {.a = 1, .b = 2};
  13. var y: {.a: i32, .b: i32} = x;
  14. // CHECK:STDOUT: --- two_entries.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  19. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  20. // CHECK:STDOUT: %.2: type = struct_type {.a: i32, .b: i32} [template]
  21. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  22. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  23. // CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
  24. // CHECK:STDOUT: %struct: %.2 = struct_value (%.4, %.5) [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: file {
  28. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  29. // CHECK:STDOUT: .Core = %Core
  30. // CHECK:STDOUT: .v = @__global_init.%v
  31. // CHECK:STDOUT: .w = @__global_init.%w
  32. // CHECK:STDOUT: .x = %x
  33. // CHECK:STDOUT: .y = %y
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  36. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  37. // CHECK:STDOUT: %int.make_type_32.loc11_13: init type = call constants.%Int32() [template = i32]
  38. // CHECK:STDOUT: %.loc11_13.1: type = value_of_initializer %int.make_type_32.loc11_13 [template = i32]
  39. // CHECK:STDOUT: %.loc11_13.2: type = converted %int.make_type_32.loc11_13, %.loc11_13.1 [template = i32]
  40. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  41. // CHECK:STDOUT: %int.make_type_32.loc11_22: init type = call constants.%Int32() [template = i32]
  42. // CHECK:STDOUT: %.loc11_22.1: type = value_of_initializer %int.make_type_32.loc11_22 [template = i32]
  43. // CHECK:STDOUT: %.loc11_22.2: type = converted %int.make_type_32.loc11_22, %.loc11_22.1 [template = i32]
  44. // CHECK:STDOUT: %.loc11_25: type = struct_type {.a: i32, .b: i32} [template = constants.%.2]
  45. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  46. // CHECK:STDOUT: %int.make_type_32.loc12_13: init type = call constants.%Int32() [template = i32]
  47. // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32.loc12_13 [template = i32]
  48. // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32.loc12_13, %.loc12_13.1 [template = i32]
  49. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %int.make_type_32.loc12_22: init type = call constants.%Int32() [template = i32]
  51. // CHECK:STDOUT: %.loc12_22.1: type = value_of_initializer %int.make_type_32.loc12_22 [template = i32]
  52. // CHECK:STDOUT: %.loc12_22.2: type = converted %int.make_type_32.loc12_22, %.loc12_22.1 [template = i32]
  53. // CHECK:STDOUT: %.loc12_25: type = struct_type {.a: i32, .b: i32} [template = constants.%.2]
  54. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  55. // CHECK:STDOUT: %int.make_type_32.loc14_13: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %.loc14_13.1: type = value_of_initializer %int.make_type_32.loc14_13 [template = i32]
  57. // CHECK:STDOUT: %.loc14_13.2: type = converted %int.make_type_32.loc14_13, %.loc14_13.1 [template = i32]
  58. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  59. // CHECK:STDOUT: %int.make_type_32.loc14_22: init type = call constants.%Int32() [template = i32]
  60. // CHECK:STDOUT: %.loc14_22.1: type = value_of_initializer %int.make_type_32.loc14_22 [template = i32]
  61. // CHECK:STDOUT: %.loc14_22.2: type = converted %int.make_type_32.loc14_22, %.loc14_22.1 [template = i32]
  62. // CHECK:STDOUT: %.loc14_25: type = struct_type {.a: i32, .b: i32} [template = constants.%.2]
  63. // CHECK:STDOUT: %x.var: ref %.2 = var x
  64. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  65. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  66. // CHECK:STDOUT: %int.make_type_32.loc15_13: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc15_13.1: type = value_of_initializer %int.make_type_32.loc15_13 [template = i32]
  68. // CHECK:STDOUT: %.loc15_13.2: type = converted %int.make_type_32.loc15_13, %.loc15_13.1 [template = i32]
  69. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  70. // CHECK:STDOUT: %int.make_type_32.loc15_22: init type = call constants.%Int32() [template = i32]
  71. // CHECK:STDOUT: %.loc15_22.1: type = value_of_initializer %int.make_type_32.loc15_22 [template = i32]
  72. // CHECK:STDOUT: %.loc15_22.2: type = converted %int.make_type_32.loc15_22, %.loc15_22.1 [template = i32]
  73. // CHECK:STDOUT: %.loc15_25: type = struct_type {.a: i32, .b: i32} [template = constants.%.2]
  74. // CHECK:STDOUT: %y.var: ref %.2 = var y
  75. // CHECK:STDOUT: %y: ref %.2 = bind_name y, %y.var
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @__global_init() {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %.loc11_35: i32 = int_literal 1 [template = constants.%.4]
  83. // CHECK:STDOUT: %.loc11_43: i32 = int_literal 2 [template = constants.%.5]
  84. // CHECK:STDOUT: %.loc11_44: %.2 = struct_literal (%.loc11_35, %.loc11_43)
  85. // CHECK:STDOUT: %struct: %.2 = struct_value (%.loc11_35, %.loc11_43) [template = constants.%struct]
  86. // CHECK:STDOUT: %.loc11_45: %.2 = converted %.loc11_44, %struct [template = constants.%struct]
  87. // CHECK:STDOUT: %v: %.2 = bind_name v, %.loc11_45
  88. // CHECK:STDOUT: %v.ref: %.2 = name_ref v, %v
  89. // CHECK:STDOUT: %w: %.2 = bind_name w, %v.ref
  90. // CHECK:STDOUT: %.loc14_35: i32 = int_literal 1 [template = constants.%.4]
  91. // CHECK:STDOUT: %.loc14_43: i32 = int_literal 2 [template = constants.%.5]
  92. // CHECK:STDOUT: %.loc14_44.1: %.2 = struct_literal (%.loc14_35, %.loc14_43)
  93. // CHECK:STDOUT: %.loc14_44.2: ref i32 = struct_access file.%x.var, element0
  94. // CHECK:STDOUT: %.loc14_44.3: init i32 = initialize_from %.loc14_35 to %.loc14_44.2 [template = constants.%.4]
  95. // CHECK:STDOUT: %.loc14_44.4: ref i32 = struct_access file.%x.var, element1
  96. // CHECK:STDOUT: %.loc14_44.5: init i32 = initialize_from %.loc14_43 to %.loc14_44.4 [template = constants.%.5]
  97. // CHECK:STDOUT: %.loc14_44.6: init %.2 = struct_init (%.loc14_44.3, %.loc14_44.5) to file.%x.var [template = constants.%struct]
  98. // CHECK:STDOUT: %.loc14_45: init %.2 = converted %.loc14_44.1, %.loc14_44.6 [template = constants.%struct]
  99. // CHECK:STDOUT: assign file.%x.var, %.loc14_45
  100. // CHECK:STDOUT: %x.ref: ref %.2 = name_ref x, file.%x
  101. // CHECK:STDOUT: %.loc15_29.1: ref i32 = struct_access %x.ref, element0
  102. // CHECK:STDOUT: %.loc15_29.2: i32 = bind_value %.loc15_29.1
  103. // CHECK:STDOUT: %.loc15_29.3: ref i32 = struct_access file.%y.var, element0
  104. // CHECK:STDOUT: %.loc15_29.4: init i32 = initialize_from %.loc15_29.2 to %.loc15_29.3
  105. // CHECK:STDOUT: %.loc15_29.5: ref i32 = struct_access %x.ref, element1
  106. // CHECK:STDOUT: %.loc15_29.6: i32 = bind_value %.loc15_29.5
  107. // CHECK:STDOUT: %.loc15_29.7: ref i32 = struct_access file.%y.var, element1
  108. // CHECK:STDOUT: %.loc15_29.8: init i32 = initialize_from %.loc15_29.6 to %.loc15_29.7
  109. // CHECK:STDOUT: %.loc15_29.9: init %.2 = struct_init (%.loc15_29.4, %.loc15_29.8) to file.%y.var
  110. // CHECK:STDOUT: %.loc15_30: init %.2 = converted %x.ref, %.loc15_29.9
  111. // CHECK:STDOUT: assign file.%y.var, %.loc15_30
  112. // CHECK:STDOUT: return
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: