left_shift.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/operators/overloaded/left_shift.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/left_shift.carbon
  10. // This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  11. package User;
  12. class C {};
  13. impl C as Core.LeftShift {
  14. fn Op[self: C](other: C) -> C {
  15. return {};
  16. }
  17. }
  18. impl C as Core.LeftShiftAssign {
  19. fn Op[addr self: C*](other: C) {}
  20. }
  21. fn TestOp(a: C, b: C) -> C {
  22. return a << b;
  23. }
  24. fn TestAssign(a: C*, b: C) {
  25. *a <<= b;
  26. }
  27. // CHECK:STDOUT: --- left_shift.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %C: type = class_type @C [template]
  31. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  32. // CHECK:STDOUT: %.2: type = interface_type @LeftShift [template]
  33. // CHECK:STDOUT: %Self.1: %.2 = bind_symbolic_name Self 0 [symbolic]
  34. // CHECK:STDOUT: %Op.type.1: type = fn_type @Op.1 [template]
  35. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  36. // CHECK:STDOUT: %Op.1: %Op.type.1 = struct_value () [template]
  37. // CHECK:STDOUT: %Op.type.2: type = fn_type @Op.2 [template]
  38. // CHECK:STDOUT: %Op.2: %Op.type.2 = struct_value () [template]
  39. // CHECK:STDOUT: %.4: <witness> = interface_witness (%Op.1) [template]
  40. // CHECK:STDOUT: %.5: type = ptr_type %.1 [template]
  41. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  42. // CHECK:STDOUT: %.6: type = interface_type @LeftShiftAssign [template]
  43. // CHECK:STDOUT: %Self.2: %.6 = bind_symbolic_name Self 0 [symbolic]
  44. // CHECK:STDOUT: %.7: type = ptr_type %C [template]
  45. // CHECK:STDOUT: %Op.type.3: type = fn_type @Op.3 [template]
  46. // CHECK:STDOUT: %Op.3: %Op.type.3 = struct_value () [template]
  47. // CHECK:STDOUT: %.8: type = ptr_type %Self.2 [symbolic]
  48. // CHECK:STDOUT: %Op.type.4: type = fn_type @Op.4 [template]
  49. // CHECK:STDOUT: %Op.4: %Op.type.4 = struct_value () [template]
  50. // CHECK:STDOUT: %.9: <witness> = interface_witness (%Op.3) [template]
  51. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [template]
  52. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [template]
  53. // CHECK:STDOUT: %.10: type = assoc_entity_type @LeftShift, %Op.type.2 [template]
  54. // CHECK:STDOUT: %.11: %.10 = assoc_entity element0, file.%import_ref.10 [template]
  55. // CHECK:STDOUT: %TestAssign.type: type = fn_type @TestAssign [template]
  56. // CHECK:STDOUT: %TestAssign: %TestAssign.type = struct_value () [template]
  57. // CHECK:STDOUT: %.12: type = assoc_entity_type @LeftShiftAssign, %Op.type.4 [template]
  58. // CHECK:STDOUT: %.13: %.12 = assoc_entity element0, file.%import_ref.12 [template]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: file {
  62. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  63. // CHECK:STDOUT: .Core = %Core
  64. // CHECK:STDOUT: .C = %C.decl
  65. // CHECK:STDOUT: .TestOp = %TestOp.decl
  66. // CHECK:STDOUT: .TestAssign = %TestAssign.decl
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  69. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  70. // CHECK:STDOUT: %import_ref.1: type = import_ref ir5, inst+162, loaded [template = constants.%.2]
  71. // CHECK:STDOUT: %import_ref.2 = import_ref ir5, inst+164, unloaded
  72. // CHECK:STDOUT: %import_ref.3: %.10 = import_ref ir5, inst+184, loaded [template = constants.%.11]
  73. // CHECK:STDOUT: %import_ref.4: %Op.type.2 = import_ref ir5, inst+180, loaded [template = constants.%Op.2]
  74. // CHECK:STDOUT: impl_decl @impl.1 {
  75. // CHECK:STDOUT: %C.ref.loc17: type = name_ref C, %C.decl [template = constants.%C]
  76. // CHECK:STDOUT: %Core.ref.loc17: <namespace> = name_ref Core, %Core [template = %Core]
  77. // CHECK:STDOUT: %LeftShift.ref: type = name_ref LeftShift, %import_ref.1 [template = constants.%.2]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %import_ref.5: type = import_ref ir5, inst+186, loaded [template = constants.%.6]
  80. // CHECK:STDOUT: %import_ref.6 = import_ref ir5, inst+188, unloaded
  81. // CHECK:STDOUT: %import_ref.7: %.12 = import_ref ir5, inst+207, loaded [template = constants.%.13]
  82. // CHECK:STDOUT: %import_ref.8: %Op.type.4 = import_ref ir5, inst+203, loaded [template = constants.%Op.4]
  83. // CHECK:STDOUT: impl_decl @impl.2 {
  84. // CHECK:STDOUT: %C.ref.loc22: type = name_ref C, %C.decl [template = constants.%C]
  85. // CHECK:STDOUT: %Core.ref.loc22: <namespace> = name_ref Core, %Core [template = %Core]
  86. // CHECK:STDOUT: %LeftShiftAssign.ref: type = name_ref LeftShiftAssign, %import_ref.5 [template = constants.%.6]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [template = constants.%TestOp] {
  89. // CHECK:STDOUT: %C.ref.loc26_14: type = name_ref C, %C.decl [template = constants.%C]
  90. // CHECK:STDOUT: %a.loc26_11.1: %C = param a
  91. // CHECK:STDOUT: @TestOp.%a: %C = bind_name a, %a.loc26_11.1
  92. // CHECK:STDOUT: %C.ref.loc26_20: type = name_ref C, %C.decl [template = constants.%C]
  93. // CHECK:STDOUT: %b.loc26_17.1: %C = param b
  94. // CHECK:STDOUT: @TestOp.%b: %C = bind_name b, %b.loc26_17.1
  95. // CHECK:STDOUT: %C.ref.loc26_26: type = name_ref C, %C.decl [template = constants.%C]
  96. // CHECK:STDOUT: @TestOp.%return: ref %C = var <return slot>
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %import_ref.9: type = import_ref ir5, inst+162, loaded [template = constants.%.2]
  99. // CHECK:STDOUT: %import_ref.10 = import_ref ir5, inst+180, unloaded
  100. // CHECK:STDOUT: %TestAssign.decl: %TestAssign.type = fn_decl @TestAssign [template = constants.%TestAssign] {
  101. // CHECK:STDOUT: %C.ref.loc30_18: type = name_ref C, %C.decl [template = constants.%C]
  102. // CHECK:STDOUT: %.loc30: type = ptr_type %C [template = constants.%.7]
  103. // CHECK:STDOUT: %a.loc30_15.1: %.7 = param a
  104. // CHECK:STDOUT: @TestAssign.%a: %.7 = bind_name a, %a.loc30_15.1
  105. // CHECK:STDOUT: %C.ref.loc30_25: type = name_ref C, %C.decl [template = constants.%C]
  106. // CHECK:STDOUT: %b.loc30_22.1: %C = param b
  107. // CHECK:STDOUT: @TestAssign.%b: %C = bind_name b, %b.loc30_22.1
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %import_ref.11: type = import_ref ir5, inst+186, loaded [template = constants.%.6]
  110. // CHECK:STDOUT: %import_ref.12 = import_ref ir5, inst+203, unloaded
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: interface @LeftShift {
  114. // CHECK:STDOUT: !members:
  115. // CHECK:STDOUT: .Self = file.%import_ref.2
  116. // CHECK:STDOUT: .Op = file.%import_ref.3
  117. // CHECK:STDOUT: witness = (file.%import_ref.4)
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: interface @LeftShiftAssign {
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Self = file.%import_ref.6
  123. // CHECK:STDOUT: .Op = file.%import_ref.7
  124. // CHECK:STDOUT: witness = (file.%import_ref.8)
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: impl @impl.1: %C as %.2 {
  128. // CHECK:STDOUT: %Op.decl: %Op.type.1 = fn_decl @Op.1 [template = constants.%Op.1] {
  129. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [template = constants.%C]
  130. // CHECK:STDOUT: %self.loc18_9.1: %C = param self
  131. // CHECK:STDOUT: %self.loc18_9.2: %C = bind_name self, %self.loc18_9.1
  132. // CHECK:STDOUT: %C.ref.loc18_25: type = name_ref C, file.%C.decl [template = constants.%C]
  133. // CHECK:STDOUT: %other.loc18_18.1: %C = param other
  134. // CHECK:STDOUT: %other.loc18_18.2: %C = bind_name other, %other.loc18_18.1
  135. // CHECK:STDOUT: %C.ref.loc18_31: type = name_ref C, file.%C.decl [template = constants.%C]
  136. // CHECK:STDOUT: %return.var: ref %C = var <return slot>
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.4]
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: !members:
  141. // CHECK:STDOUT: .Op = %Op.decl
  142. // CHECK:STDOUT: witness = %.1
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: impl @impl.2: %C as %.6 {
  146. // CHECK:STDOUT: %Op.decl: %Op.type.3 = fn_decl @Op.3 [template = constants.%Op.3] {
  147. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [template = constants.%C]
  148. // CHECK:STDOUT: %.loc23_21: type = ptr_type %C [template = constants.%.7]
  149. // CHECK:STDOUT: %self.loc23_14.1: %.7 = param self
  150. // CHECK:STDOUT: %self.loc23_14.3: %.7 = bind_name self, %self.loc23_14.1
  151. // CHECK:STDOUT: %.loc23_9: %.7 = addr_pattern %self.loc23_14.3
  152. // CHECK:STDOUT: %C.ref.loc23_31: type = name_ref C, file.%C.decl [template = constants.%C]
  153. // CHECK:STDOUT: %other.loc23_24.1: %C = param other
  154. // CHECK:STDOUT: %other.loc23_24.2: %C = bind_name other, %other.loc23_24.1
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.9]
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !members:
  159. // CHECK:STDOUT: .Op = %Op.decl
  160. // CHECK:STDOUT: witness = %.1
  161. // CHECK:STDOUT: }
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: class @C {
  164. // CHECK:STDOUT: !members:
  165. // CHECK:STDOUT: .Self = constants.%C
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @Op.1[@impl.1.%self.loc18_9.2: %C](@impl.1.%other.loc18_18.2: %C) -> @impl.1.%return.var: %C {
  169. // CHECK:STDOUT: !entry:
  170. // CHECK:STDOUT: %.loc19_13.1: %.1 = struct_literal ()
  171. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), @impl.1.%return.var [template = constants.%struct]
  172. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [template = constants.%struct]
  173. // CHECK:STDOUT: return %.loc19_14 to @impl.1.%return.var
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: fn @Op.2[%self: %Self.1](%other: %Self.1) -> %Self.1;
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: fn @Op.3[addr @impl.2.%self.loc23_14.3: %.7](@impl.2.%other.loc23_24.2: %C) {
  179. // CHECK:STDOUT: !entry:
  180. // CHECK:STDOUT: return
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: fn @Op.4[addr %self: %.8](%other: %Self.2);
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: fn @TestOp(%a: %C, %b: %C) -> %return: %C {
  186. // CHECK:STDOUT: !entry:
  187. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  188. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  189. // CHECK:STDOUT: %.1: %Op.type.2 = interface_witness_access @impl.1.%.1, element0 [template = constants.%Op.1]
  190. // CHECK:STDOUT: %.loc27: <bound method> = bound_method %a.ref, %.1
  191. // CHECK:STDOUT: %.loc26: ref %C = splice_block %return {}
  192. // CHECK:STDOUT: %Op.call: init %C = call %.loc27(%a.ref, %b.ref) to %.loc26
  193. // CHECK:STDOUT: return %Op.call to %return
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: fn @TestAssign(%a: %.7, %b: %C) {
  197. // CHECK:STDOUT: !entry:
  198. // CHECK:STDOUT: %a.ref: %.7 = name_ref a, %a
  199. // CHECK:STDOUT: %.loc31_3.1: ref %C = deref %a.ref
  200. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  201. // CHECK:STDOUT: %.1: %Op.type.4 = interface_witness_access @impl.2.%.1, element0 [template = constants.%Op.3]
  202. // CHECK:STDOUT: %.loc31_6: <bound method> = bound_method %.loc31_3.1, %.1
  203. // CHECK:STDOUT: %.loc31_3.2: %.7 = addr_of %.loc31_3.1
  204. // CHECK:STDOUT: %Op.call: init %.3 = call %.loc31_6(%.loc31_3.2, %b.ref)
  205. // CHECK:STDOUT: return
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT: