and.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/builtins/int/and.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/and.carbon
  10. // --- int_and.carbon
  11. fn And(a: i32, b: i32) -> i32 = "int.and";
  12. var arr: [i32; And(12, 10)];
  13. let arr_p: [i32; 8]* = &arr;
  14. fn RuntimeCall(a: i32, b: i32) -> i32 {
  15. return And(a, b);
  16. }
  17. // CHECK:STDOUT: --- int_and.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %And.type: type = fn_type @And [template]
  24. // CHECK:STDOUT: %And: %And.type = struct_value () [template]
  25. // CHECK:STDOUT: %.2: i32 = int_literal 12 [template]
  26. // CHECK:STDOUT: %.3: i32 = int_literal 10 [template]
  27. // CHECK:STDOUT: %.4: i32 = int_literal 8 [template]
  28. // CHECK:STDOUT: %.5: type = array_type %.4, i32 [template]
  29. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  30. // CHECK:STDOUT: %RuntimeCall.type: type = fn_type @RuntimeCall [template]
  31. // CHECK:STDOUT: %RuntimeCall: %RuntimeCall.type = struct_value () [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  36. // CHECK:STDOUT: .Int32 = %import_ref
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .And = %And.decl
  47. // CHECK:STDOUT: .arr = %arr
  48. // CHECK:STDOUT: .arr_p = @__global_init.%arr_p
  49. // CHECK:STDOUT: .RuntimeCall = %RuntimeCall.decl
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core.import = import Core
  52. // CHECK:STDOUT: %And.decl: %And.type = fn_decl @And [template = constants.%And] {
  53. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  54. // CHECK:STDOUT: %a.param_patt: i32 = value_param_pattern %a.patt, runtime_param0
  55. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  56. // CHECK:STDOUT: %b.param_patt: i32 = value_param_pattern %b.patt, runtime_param1
  57. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  58. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param2
  59. // CHECK:STDOUT: } {
  60. // CHECK:STDOUT: %int.make_type_32.loc2_11: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc2_11.1: type = value_of_initializer %int.make_type_32.loc2_11 [template = i32]
  62. // CHECK:STDOUT: %.loc2_11.2: type = converted %int.make_type_32.loc2_11, %.loc2_11.1 [template = i32]
  63. // CHECK:STDOUT: %int.make_type_32.loc2_19: init type = call constants.%Int32() [template = i32]
  64. // CHECK:STDOUT: %.loc2_19.1: type = value_of_initializer %int.make_type_32.loc2_19 [template = i32]
  65. // CHECK:STDOUT: %.loc2_19.2: type = converted %int.make_type_32.loc2_19, %.loc2_19.1 [template = i32]
  66. // CHECK:STDOUT: %int.make_type_32.loc2_27: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc2_27.1: type = value_of_initializer %int.make_type_32.loc2_27 [template = i32]
  68. // CHECK:STDOUT: %.loc2_27.2: type = converted %int.make_type_32.loc2_27, %.loc2_27.1 [template = i32]
  69. // CHECK:STDOUT: %a.param: i32 = value_param runtime_param0
  70. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  71. // CHECK:STDOUT: %b.param: i32 = value_param runtime_param1
  72. // CHECK:STDOUT: %b: i32 = bind_name b, %b.param
  73. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param2
  74. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %int.make_type_32.loc4: init type = call constants.%Int32() [template = i32]
  77. // CHECK:STDOUT: %And.ref: %And.type = name_ref And, %And.decl [template = constants.%And]
  78. // CHECK:STDOUT: %.loc4_20: i32 = int_literal 12 [template = constants.%.2]
  79. // CHECK:STDOUT: %.loc4_24: i32 = int_literal 10 [template = constants.%.3]
  80. // CHECK:STDOUT: %int.and: init i32 = call %And.ref(%.loc4_20, %.loc4_24) [template = constants.%.4]
  81. // CHECK:STDOUT: %.loc4_11.1: type = value_of_initializer %int.make_type_32.loc4 [template = i32]
  82. // CHECK:STDOUT: %.loc4_11.2: type = converted %int.make_type_32.loc4, %.loc4_11.1 [template = i32]
  83. // CHECK:STDOUT: %.loc4_27: type = array_type %int.and, i32 [template = constants.%.5]
  84. // CHECK:STDOUT: %arr.var: ref %.5 = var arr
  85. // CHECK:STDOUT: %arr: ref %.5 = bind_name arr, %arr.var
  86. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  87. // CHECK:STDOUT: %.loc5_18: i32 = int_literal 8 [template = constants.%.4]
  88. // CHECK:STDOUT: %.loc5_13.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  89. // CHECK:STDOUT: %.loc5_13.2: type = converted %int.make_type_32.loc5, %.loc5_13.1 [template = i32]
  90. // CHECK:STDOUT: %.loc5_19: type = array_type %.loc5_18, i32 [template = constants.%.5]
  91. // CHECK:STDOUT: %.loc5_20: type = ptr_type %.5 [template = constants.%.6]
  92. // CHECK:STDOUT: %RuntimeCall.decl: %RuntimeCall.type = fn_decl @RuntimeCall [template = constants.%RuntimeCall] {
  93. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  94. // CHECK:STDOUT: %a.param_patt: i32 = value_param_pattern %a.patt, runtime_param0
  95. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  96. // CHECK:STDOUT: %b.param_patt: i32 = value_param_pattern %b.patt, runtime_param1
  97. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  98. // CHECK:STDOUT: %return.param_patt: i32 = out_param_pattern %return.patt, runtime_param2
  99. // CHECK:STDOUT: } {
  100. // CHECK:STDOUT: %int.make_type_32.loc7_19: init type = call constants.%Int32() [template = i32]
  101. // CHECK:STDOUT: %.loc7_19.1: type = value_of_initializer %int.make_type_32.loc7_19 [template = i32]
  102. // CHECK:STDOUT: %.loc7_19.2: type = converted %int.make_type_32.loc7_19, %.loc7_19.1 [template = i32]
  103. // CHECK:STDOUT: %int.make_type_32.loc7_27: init type = call constants.%Int32() [template = i32]
  104. // CHECK:STDOUT: %.loc7_27.1: type = value_of_initializer %int.make_type_32.loc7_27 [template = i32]
  105. // CHECK:STDOUT: %.loc7_27.2: type = converted %int.make_type_32.loc7_27, %.loc7_27.1 [template = i32]
  106. // CHECK:STDOUT: %int.make_type_32.loc7_35: init type = call constants.%Int32() [template = i32]
  107. // CHECK:STDOUT: %.loc7_35.1: type = value_of_initializer %int.make_type_32.loc7_35 [template = i32]
  108. // CHECK:STDOUT: %.loc7_35.2: type = converted %int.make_type_32.loc7_35, %.loc7_35.1 [template = i32]
  109. // CHECK:STDOUT: %a.param: i32 = value_param runtime_param0
  110. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  111. // CHECK:STDOUT: %b.param: i32 = value_param runtime_param1
  112. // CHECK:STDOUT: %b: i32 = bind_name b, %b.param
  113. // CHECK:STDOUT: %return.param: ref i32 = out_param runtime_param2
  114. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @And(%a.param_patt: i32, %b.param_patt: i32) -> i32 = "int.and";
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: fn @RuntimeCall(%a.param_patt: i32, %b.param_patt: i32) -> i32 {
  123. // CHECK:STDOUT: !entry:
  124. // CHECK:STDOUT: %And.ref: %And.type = name_ref And, file.%And.decl [template = constants.%And]
  125. // CHECK:STDOUT: %a.ref: i32 = name_ref a, %a
  126. // CHECK:STDOUT: %b.ref: i32 = name_ref b, %b
  127. // CHECK:STDOUT: %int.and: init i32 = call %And.ref(%a.ref, %b.ref)
  128. // CHECK:STDOUT: %.loc8_19.1: i32 = value_of_initializer %int.and
  129. // CHECK:STDOUT: %.loc8_19.2: i32 = converted %int.and, %.loc8_19.1
  130. // CHECK:STDOUT: return %.loc8_19.2
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @__global_init() {
  134. // CHECK:STDOUT: !entry:
  135. // CHECK:STDOUT: %arr.ref: ref %.5 = name_ref arr, file.%arr
  136. // CHECK:STDOUT: %.loc5: %.6 = addr_of %arr.ref
  137. // CHECK:STDOUT: %arr_p: %.6 = bind_name arr_p, %.loc5
  138. // CHECK:STDOUT: return
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: