tuple_element_access.carbon 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/index/tuple_element_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/index/tuple_element_access.carbon
  10. var a: (i32,) = (12,);
  11. var b: (i32,) = a;
  12. var c: i32 = b[0];
  13. // CHECK:STDOUT: --- tuple_element_access.carbon
  14. // CHECK:STDOUT:
  15. // CHECK:STDOUT: constants {
  16. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  17. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  18. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  19. // CHECK:STDOUT: %.2: type = tuple_type (type) [template]
  20. // CHECK:STDOUT: %.3: type = tuple_type (i32) [template]
  21. // CHECK:STDOUT: %.4: i32 = int_literal 12 [template]
  22. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.4) [template]
  23. // CHECK:STDOUT: %.5: i32 = int_literal 0 [template]
  24. // CHECK:STDOUT: }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: file {
  27. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  28. // CHECK:STDOUT: .Core = %Core
  29. // CHECK:STDOUT: .a = %a
  30. // CHECK:STDOUT: .b = %b
  31. // CHECK:STDOUT: .c = %c
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  34. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  35. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  36. // CHECK:STDOUT: %.loc11_13.1: %.2 = tuple_literal (%int.make_type_32.loc11)
  37. // CHECK:STDOUT: %.loc11_13.2: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  38. // CHECK:STDOUT: %.loc11_13.3: type = converted %int.make_type_32.loc11, %.loc11_13.2 [template = i32]
  39. // CHECK:STDOUT: %.loc11_13.4: type = converted %.loc11_13.1, constants.%.3 [template = constants.%.3]
  40. // CHECK:STDOUT: %a.var: ref %.3 = var a
  41. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  42. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  43. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  44. // CHECK:STDOUT: %.loc12_13.1: %.2 = tuple_literal (%int.make_type_32.loc12)
  45. // CHECK:STDOUT: %.loc12_13.2: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  46. // CHECK:STDOUT: %.loc12_13.3: type = converted %int.make_type_32.loc12, %.loc12_13.2 [template = i32]
  47. // CHECK:STDOUT: %.loc12_13.4: type = converted %.loc12_13.1, constants.%.3 [template = constants.%.3]
  48. // CHECK:STDOUT: %b.var: ref %.3 = var b
  49. // CHECK:STDOUT: %b: ref %.3 = bind_name b, %b.var
  50. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  51. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  52. // CHECK:STDOUT: %.loc13_8.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  53. // CHECK:STDOUT: %.loc13_8.2: type = converted %int.make_type_32.loc13, %.loc13_8.1 [template = i32]
  54. // CHECK:STDOUT: %c.var: ref i32 = var c
  55. // CHECK:STDOUT: %c: ref i32 = bind_name c, %c.var
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @__global_init() {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %.loc11_18: i32 = int_literal 12 [template = constants.%.4]
  63. // CHECK:STDOUT: %.loc11_21.1: %.3 = tuple_literal (%.loc11_18)
  64. // CHECK:STDOUT: %.loc11_21.2: init %.3 = tuple_init (%.loc11_18) to file.%a.var [template = constants.%tuple]
  65. // CHECK:STDOUT: %.loc11_22: init %.3 = converted %.loc11_21.1, %.loc11_21.2 [template = constants.%tuple]
  66. // CHECK:STDOUT: assign file.%a.var, %.loc11_22
  67. // CHECK:STDOUT: %a.ref: ref %.3 = name_ref a, file.%a
  68. // CHECK:STDOUT: %.loc12_17.1: ref i32 = tuple_access %a.ref, element0
  69. // CHECK:STDOUT: %.loc12_17.2: i32 = bind_value %.loc12_17.1
  70. // CHECK:STDOUT: %.loc12_17.3: init %.3 = tuple_init (%.loc12_17.2) to file.%b.var
  71. // CHECK:STDOUT: %.loc12_18: init %.3 = converted %a.ref, %.loc12_17.3
  72. // CHECK:STDOUT: assign file.%b.var, %.loc12_18
  73. // CHECK:STDOUT: %b.ref: ref %.3 = name_ref b, file.%b
  74. // CHECK:STDOUT: %.loc13_16: i32 = int_literal 0 [template = constants.%.5]
  75. // CHECK:STDOUT: %.loc13_17.1: ref i32 = tuple_index %b.ref, %.loc13_16
  76. // CHECK:STDOUT: %.loc13_17.2: i32 = bind_value %.loc13_17.1
  77. // CHECK:STDOUT: assign file.%c.var, %.loc13_17.2
  78. // CHECK:STDOUT: return
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: