index_not_literal.carbon 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/tuple/access/index_not_literal.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/access/index_not_literal.carbon
  10. var a: (i32, i32) = (12, 34);
  11. var b: i32 = a.({.index = 1}.index);
  12. // CHECK:STDOUT: --- index_not_literal.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  16. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  17. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  18. // CHECK:STDOUT: %.2: type = tuple_type (type, type) [template]
  19. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32) [template]
  20. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  21. // CHECK:STDOUT: %.5: i32 = int_value 12 [template]
  22. // CHECK:STDOUT: %.6: i32 = int_value 34 [template]
  23. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.5, %.6) [template]
  24. // CHECK:STDOUT: %.7: i32 = int_value 1 [template]
  25. // CHECK:STDOUT: %.8: type = struct_type {.index: i32} [template]
  26. // CHECK:STDOUT: %struct: %.8 = struct_value (%.7) [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: imports {
  30. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  31. // CHECK:STDOUT: .Int32 = %import_ref
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/...
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .a = %a
  42. // CHECK:STDOUT: .b = %b
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Core.import = import Core
  45. // CHECK:STDOUT: %int.make_type_32.loc11_9: init type = call constants.%Int32() [template = i32]
  46. // CHECK:STDOUT: %int.make_type_32.loc11_14: init type = call constants.%Int32() [template = i32]
  47. // CHECK:STDOUT: %.loc11_17.1: %.2 = tuple_literal (%int.make_type_32.loc11_9, %int.make_type_32.loc11_14)
  48. // CHECK:STDOUT: %.loc11_17.2: type = value_of_initializer %int.make_type_32.loc11_9 [template = i32]
  49. // CHECK:STDOUT: %.loc11_17.3: type = converted %int.make_type_32.loc11_9, %.loc11_17.2 [template = i32]
  50. // CHECK:STDOUT: %.loc11_17.4: type = value_of_initializer %int.make_type_32.loc11_14 [template = i32]
  51. // CHECK:STDOUT: %.loc11_17.5: type = converted %int.make_type_32.loc11_14, %.loc11_17.4 [template = i32]
  52. // CHECK:STDOUT: %.loc11_17.6: type = converted %.loc11_17.1, constants.%.3 [template = constants.%.3]
  53. // CHECK:STDOUT: %a.var: ref %.3 = var a
  54. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  55. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  56. // CHECK:STDOUT: %.loc12_8.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  57. // CHECK:STDOUT: %.loc12_8.2: type = converted %int.make_type_32.loc12, %.loc12_8.1 [template = i32]
  58. // CHECK:STDOUT: %b.var: ref i32 = var b
  59. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: fn @__global_init() {
  65. // CHECK:STDOUT: !entry:
  66. // CHECK:STDOUT: %.loc11_22: i32 = int_value 12 [template = constants.%.5]
  67. // CHECK:STDOUT: %.loc11_26: i32 = int_value 34 [template = constants.%.6]
  68. // CHECK:STDOUT: %.loc11_28.1: %.3 = tuple_literal (%.loc11_22, %.loc11_26)
  69. // CHECK:STDOUT: %.loc11_28.2: ref i32 = tuple_access file.%a.var, element0
  70. // CHECK:STDOUT: %.loc11_28.3: init i32 = initialize_from %.loc11_22 to %.loc11_28.2 [template = constants.%.5]
  71. // CHECK:STDOUT: %.loc11_28.4: ref i32 = tuple_access file.%a.var, element1
  72. // CHECK:STDOUT: %.loc11_28.5: init i32 = initialize_from %.loc11_26 to %.loc11_28.4 [template = constants.%.6]
  73. // CHECK:STDOUT: %.loc11_28.6: init %.3 = tuple_init (%.loc11_28.3, %.loc11_28.5) to file.%a.var [template = constants.%tuple]
  74. // CHECK:STDOUT: %.loc11_29: init %.3 = converted %.loc11_28.1, %.loc11_28.6 [template = constants.%tuple]
  75. // CHECK:STDOUT: assign file.%a.var, %.loc11_29
  76. // CHECK:STDOUT: %a.ref: ref %.3 = name_ref a, file.%a
  77. // CHECK:STDOUT: %.loc12_27: i32 = int_value 1 [template = constants.%.7]
  78. // CHECK:STDOUT: %.loc12_28.1: %.8 = struct_literal (%.loc12_27)
  79. // CHECK:STDOUT: %struct: %.8 = struct_value (%.loc12_27) [template = constants.%struct]
  80. // CHECK:STDOUT: %.loc12_28.2: %.8 = converted %.loc12_28.1, %struct [template = constants.%struct]
  81. // CHECK:STDOUT: %.loc12_29: i32 = struct_access %.loc12_28.2, element0 [template = constants.%.7]
  82. // CHECK:STDOUT: %.loc12_15.1: ref i32 = tuple_access %a.ref, element1
  83. // CHECK:STDOUT: %.loc12_15.2: i32 = bind_value %.loc12_15.1
  84. // CHECK:STDOUT: assign file.%b.var, %.loc12_15.2
  85. // CHECK:STDOUT: return
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: