array_vs_tuple.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. fn G() {
  7. // These should have two different constant values.
  8. var a: [i32; 3] = (1, 2, 3);
  9. var b: (i32, i32, i32) = (1, 2, 3);
  10. }
  11. // CHECK:STDOUT: --- array_vs_tuple.carbon
  12. // CHECK:STDOUT:
  13. // CHECK:STDOUT: constants {
  14. // CHECK:STDOUT: %G: type = fn_type @G [template]
  15. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  16. // CHECK:STDOUT: %struct.1: G = struct_value () [template]
  17. // CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %struct.2: Int32 = struct_value () [template]
  19. // CHECK:STDOUT: %.2: i32 = int_literal 3 [template]
  20. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  21. // CHECK:STDOUT: %.4: type = ptr_type [i32; 3] [template]
  22. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  23. // CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
  24. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
  25. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  26. // CHECK:STDOUT: %array: [i32; 3] = tuple_value (%.5, %.6, %.2) [template]
  27. // CHECK:STDOUT: %.9: type = tuple_type (type, type, type) [template]
  28. // CHECK:STDOUT: %.10: type = ptr_type (i32, i32, i32) [template]
  29. // CHECK:STDOUT: %tuple: (i32, i32, i32) = tuple_value (%.5, %.6, %.2) [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: file {
  33. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  34. // CHECK:STDOUT: .Core = %Core
  35. // CHECK:STDOUT: .G = %G.decl
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  38. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.1] {}
  39. // CHECK:STDOUT: %import_ref.1: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.2]
  40. // CHECK:STDOUT: %import_ref.2: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.2]
  41. // CHECK:STDOUT: %import_ref.3: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.2]
  42. // CHECK:STDOUT: %import_ref.4: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.2]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: fn @G() {
  46. // CHECK:STDOUT: !entry:
  47. // CHECK:STDOUT: %int.make_type_32.loc9: init type = call constants.%struct.2() [template = i32]
  48. // CHECK:STDOUT: %.loc9_16: i32 = int_literal 3 [template = constants.%.2]
  49. // CHECK:STDOUT: %.loc9_11.1: type = value_of_initializer %int.make_type_32.loc9 [template = i32]
  50. // CHECK:STDOUT: %.loc9_11.2: type = converted %int.make_type_32.loc9, %.loc9_11.1 [template = i32]
  51. // CHECK:STDOUT: %.loc9_17: type = array_type %.loc9_16, i32 [template = constants.%.3]
  52. // CHECK:STDOUT: %a.var: ref [i32; 3] = var a
  53. // CHECK:STDOUT: %a: ref [i32; 3] = bind_name a, %a.var
  54. // CHECK:STDOUT: %.loc9_22: i32 = int_literal 1 [template = constants.%.5]
  55. // CHECK:STDOUT: %.loc9_25: i32 = int_literal 2 [template = constants.%.6]
  56. // CHECK:STDOUT: %.loc9_28: i32 = int_literal 3 [template = constants.%.2]
  57. // CHECK:STDOUT: %.loc9_29.1: (i32, i32, i32) = tuple_literal (%.loc9_22, %.loc9_25, %.loc9_28)
  58. // CHECK:STDOUT: %.loc9_29.2: i32 = int_literal 0 [template = constants.%.8]
  59. // CHECK:STDOUT: %.loc9_29.3: ref i32 = array_index %a.var, %.loc9_29.2
  60. // CHECK:STDOUT: %.loc9_29.4: init i32 = initialize_from %.loc9_22 to %.loc9_29.3 [template = constants.%.5]
  61. // CHECK:STDOUT: %.loc9_29.5: i32 = int_literal 1 [template = constants.%.5]
  62. // CHECK:STDOUT: %.loc9_29.6: ref i32 = array_index %a.var, %.loc9_29.5
  63. // CHECK:STDOUT: %.loc9_29.7: init i32 = initialize_from %.loc9_25 to %.loc9_29.6 [template = constants.%.6]
  64. // CHECK:STDOUT: %.loc9_29.8: i32 = int_literal 2 [template = constants.%.6]
  65. // CHECK:STDOUT: %.loc9_29.9: ref i32 = array_index %a.var, %.loc9_29.8
  66. // CHECK:STDOUT: %.loc9_29.10: init i32 = initialize_from %.loc9_28 to %.loc9_29.9 [template = constants.%.2]
  67. // CHECK:STDOUT: %.loc9_29.11: init [i32; 3] = array_init (%.loc9_29.4, %.loc9_29.7, %.loc9_29.10) to %a.var [template = constants.%array]
  68. // CHECK:STDOUT: %.loc9_30: init [i32; 3] = converted %.loc9_29.1, %.loc9_29.11 [template = constants.%array]
  69. // CHECK:STDOUT: assign %a.var, %.loc9_30
  70. // CHECK:STDOUT: %int.make_type_32.loc10_11: init type = call constants.%struct.2() [template = i32]
  71. // CHECK:STDOUT: %int.make_type_32.loc10_16: init type = call constants.%struct.2() [template = i32]
  72. // CHECK:STDOUT: %int.make_type_32.loc10_21: init type = call constants.%struct.2() [template = i32]
  73. // CHECK:STDOUT: %.loc10_24.1: (type, type, type) = tuple_literal (%int.make_type_32.loc10_11, %int.make_type_32.loc10_16, %int.make_type_32.loc10_21)
  74. // CHECK:STDOUT: %.loc10_24.2: type = value_of_initializer %int.make_type_32.loc10_11 [template = i32]
  75. // CHECK:STDOUT: %.loc10_24.3: type = converted %int.make_type_32.loc10_11, %.loc10_24.2 [template = i32]
  76. // CHECK:STDOUT: %.loc10_24.4: type = value_of_initializer %int.make_type_32.loc10_16 [template = i32]
  77. // CHECK:STDOUT: %.loc10_24.5: type = converted %int.make_type_32.loc10_16, %.loc10_24.4 [template = i32]
  78. // CHECK:STDOUT: %.loc10_24.6: type = value_of_initializer %int.make_type_32.loc10_21 [template = i32]
  79. // CHECK:STDOUT: %.loc10_24.7: type = converted %int.make_type_32.loc10_21, %.loc10_24.6 [template = i32]
  80. // CHECK:STDOUT: %.loc10_24.8: type = converted %.loc10_24.1, constants.%.7 [template = constants.%.7]
  81. // CHECK:STDOUT: %b.var: ref (i32, i32, i32) = var b
  82. // CHECK:STDOUT: %b: ref (i32, i32, i32) = bind_name b, %b.var
  83. // CHECK:STDOUT: %.loc10_29: i32 = int_literal 1 [template = constants.%.5]
  84. // CHECK:STDOUT: %.loc10_32: i32 = int_literal 2 [template = constants.%.6]
  85. // CHECK:STDOUT: %.loc10_35: i32 = int_literal 3 [template = constants.%.2]
  86. // CHECK:STDOUT: %.loc10_36.1: (i32, i32, i32) = tuple_literal (%.loc10_29, %.loc10_32, %.loc10_35)
  87. // CHECK:STDOUT: %.loc10_36.2: ref i32 = tuple_access %b.var, element0
  88. // CHECK:STDOUT: %.loc10_36.3: init i32 = initialize_from %.loc10_29 to %.loc10_36.2 [template = constants.%.5]
  89. // CHECK:STDOUT: %.loc10_36.4: ref i32 = tuple_access %b.var, element1
  90. // CHECK:STDOUT: %.loc10_36.5: init i32 = initialize_from %.loc10_32 to %.loc10_36.4 [template = constants.%.6]
  91. // CHECK:STDOUT: %.loc10_36.6: ref i32 = tuple_access %b.var, element2
  92. // CHECK:STDOUT: %.loc10_36.7: init i32 = initialize_from %.loc10_35 to %.loc10_36.6 [template = constants.%.2]
  93. // CHECK:STDOUT: %.loc10_36.8: init (i32, i32, i32) = tuple_init (%.loc10_36.3, %.loc10_36.5, %.loc10_36.7) to %b.var [template = constants.%tuple]
  94. // CHECK:STDOUT: %.loc10_37: init (i32, i32, i32) = converted %.loc10_36.1, %.loc10_36.8 [template = constants.%tuple]
  95. // CHECK:STDOUT: assign %b.var, %.loc10_37
  96. // CHECK:STDOUT: return
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  100. // CHECK:STDOUT: