function_param.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 F(arr: [i32; 3], i: i32) -> i32 {
  7. return arr[i];
  8. }
  9. fn G() -> i32 {
  10. return F((1, 2, 3), 1);
  11. }
  12. // CHECK:STDOUT: --- function_param.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
  16. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  17. // CHECK:STDOUT: %struct.1: Int32 = struct_value () [template]
  18. // CHECK:STDOUT: %.2: i32 = int_literal 3 [template]
  19. // CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
  20. // CHECK:STDOUT: %F: type = fn_type @F [template]
  21. // CHECK:STDOUT: %struct.2: F = struct_value () [template]
  22. // CHECK:STDOUT: %.4: type = ptr_type [i32; 3] [template]
  23. // CHECK:STDOUT: %G: type = fn_type @G [template]
  24. // CHECK:STDOUT: %struct.3: G = struct_value () [template]
  25. // CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
  26. // CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
  27. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
  28. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  29. // CHECK:STDOUT: %array: [i32; 3] = 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: .F = %F.decl
  36. // CHECK:STDOUT: .G = %G.decl
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  39. // CHECK:STDOUT: %import_ref.1: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  40. // CHECK:STDOUT: %import_ref.2: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  41. // CHECK:STDOUT: %import_ref.3: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  42. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.2] {
  43. // CHECK:STDOUT: %int.make_type_32.loc7_12: init type = call constants.%struct.1() [template = i32]
  44. // CHECK:STDOUT: %.loc7_17: i32 = int_literal 3 [template = constants.%.2]
  45. // CHECK:STDOUT: %.loc7_12.1: type = value_of_initializer %int.make_type_32.loc7_12 [template = i32]
  46. // CHECK:STDOUT: %.loc7_12.2: type = converted %int.make_type_32.loc7_12, %.loc7_12.1 [template = i32]
  47. // CHECK:STDOUT: %.loc7_18: type = array_type %.loc7_17, i32 [template = constants.%.3]
  48. // CHECK:STDOUT: %arr.loc7_6.1: [i32; 3] = param arr
  49. // CHECK:STDOUT: @F.%arr: [i32; 3] = bind_name arr, %arr.loc7_6.1
  50. // CHECK:STDOUT: %int.make_type_32.loc7_24: init type = call constants.%struct.1() [template = i32]
  51. // CHECK:STDOUT: %.loc7_24.1: type = value_of_initializer %int.make_type_32.loc7_24 [template = i32]
  52. // CHECK:STDOUT: %.loc7_24.2: type = converted %int.make_type_32.loc7_24, %.loc7_24.1 [template = i32]
  53. // CHECK:STDOUT: %i.loc7_21.1: i32 = param i
  54. // CHECK:STDOUT: @F.%i: i32 = bind_name i, %i.loc7_21.1
  55. // CHECK:STDOUT: %int.make_type_32.loc7_32: init type = call constants.%struct.1() [template = i32]
  56. // CHECK:STDOUT: %.loc7_32.1: type = value_of_initializer %int.make_type_32.loc7_32 [template = i32]
  57. // CHECK:STDOUT: %.loc7_32.2: type = converted %int.make_type_32.loc7_32, %.loc7_32.1 [template = i32]
  58. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %import_ref.4: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  61. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.3] {
  62. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%struct.1() [template = i32]
  63. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  64. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32.loc11, %.loc11_11.1 [template = i32]
  65. // CHECK:STDOUT: @G.%return: ref i32 = var <return slot>
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @F(%arr: [i32; 3], %i: i32) -> i32 {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %arr.ref: [i32; 3] = name_ref arr, %arr
  74. // CHECK:STDOUT: %i.ref: i32 = name_ref i, %i
  75. // CHECK:STDOUT: %.loc8_15.1: ref [i32; 3] = value_as_ref %arr.ref
  76. // CHECK:STDOUT: %.loc8_15.2: ref i32 = array_index %.loc8_15.1, %i.ref
  77. // CHECK:STDOUT: %.loc8_15.3: i32 = bind_value %.loc8_15.2
  78. // CHECK:STDOUT: return %.loc8_15.3
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @G() -> i32 {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %F.ref: F = name_ref F, file.%F.decl [template = constants.%struct.2]
  84. // CHECK:STDOUT: %.loc12_13: i32 = int_literal 1 [template = constants.%.5]
  85. // CHECK:STDOUT: %.loc12_16: i32 = int_literal 2 [template = constants.%.6]
  86. // CHECK:STDOUT: %.loc12_19: i32 = int_literal 3 [template = constants.%.2]
  87. // CHECK:STDOUT: %.loc12_20.1: (i32, i32, i32) = tuple_literal (%.loc12_13, %.loc12_16, %.loc12_19)
  88. // CHECK:STDOUT: %.loc12_23: i32 = int_literal 1 [template = constants.%.5]
  89. // CHECK:STDOUT: %.loc12_20.2: ref [i32; 3] = temporary_storage
  90. // CHECK:STDOUT: %.loc12_20.3: i32 = int_literal 0 [template = constants.%.8]
  91. // CHECK:STDOUT: %.loc12_20.4: ref i32 = array_index %.loc12_20.2, %.loc12_20.3
  92. // CHECK:STDOUT: %.loc12_20.5: init i32 = initialize_from %.loc12_13 to %.loc12_20.4 [template = constants.%.5]
  93. // CHECK:STDOUT: %.loc12_20.6: i32 = int_literal 1 [template = constants.%.5]
  94. // CHECK:STDOUT: %.loc12_20.7: ref i32 = array_index %.loc12_20.2, %.loc12_20.6
  95. // CHECK:STDOUT: %.loc12_20.8: init i32 = initialize_from %.loc12_16 to %.loc12_20.7 [template = constants.%.6]
  96. // CHECK:STDOUT: %.loc12_20.9: i32 = int_literal 2 [template = constants.%.6]
  97. // CHECK:STDOUT: %.loc12_20.10: ref i32 = array_index %.loc12_20.2, %.loc12_20.9
  98. // CHECK:STDOUT: %.loc12_20.11: init i32 = initialize_from %.loc12_19 to %.loc12_20.10 [template = constants.%.2]
  99. // CHECK:STDOUT: %.loc12_20.12: init [i32; 3] = array_init (%.loc12_20.5, %.loc12_20.8, %.loc12_20.11) to %.loc12_20.2 [template = constants.%array]
  100. // CHECK:STDOUT: %.loc12_11.1: init [i32; 3] = converted %.loc12_20.1, %.loc12_20.12 [template = constants.%array]
  101. // CHECK:STDOUT: %.loc12_11.2: ref [i32; 3] = temporary %.loc12_20.2, %.loc12_11.1
  102. // CHECK:STDOUT: %.loc12_11.3: [i32; 3] = bind_value %.loc12_11.2
  103. // CHECK:STDOUT: %F.call: init i32 = call %F.ref(%.loc12_11.3, %.loc12_23)
  104. // CHECK:STDOUT: %.loc12_25.1: i32 = value_of_initializer %F.call
  105. // CHECK:STDOUT: %.loc12_25.2: i32 = converted %F.call, %.loc12_25.1
  106. // CHECK:STDOUT: return %.loc12_25.2
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: