right_shift.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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/right_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/right_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.RightShift {
  14. fn Op[self: C](other: C) -> C {
  15. return {};
  16. }
  17. }
  18. impl C as Core.RightShiftAssign {
  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: --- right_shift.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  31. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  32. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  33. // CHECK:STDOUT: %RightShift.type: type = facet_type <@RightShift> [concrete]
  34. // CHECK:STDOUT: %Op.type.4f4: type = fn_type @Op.1 [concrete]
  35. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  36. // CHECK:STDOUT: %RightShift.impl_witness: <witness> = impl_witness file.%RightShift.impl_witness_table [concrete]
  37. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  38. // CHECK:STDOUT: %Op.type.092: type = fn_type @Op.2 [concrete]
  39. // CHECK:STDOUT: %Op.79a: %Op.type.092 = struct_value () [concrete]
  40. // CHECK:STDOUT: %RightShift.facet: %RightShift.type = facet_value %C, (%RightShift.impl_witness) [concrete]
  41. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  42. // CHECK:STDOUT: %RightShiftAssign.type: type = facet_type <@RightShiftAssign> [concrete]
  43. // CHECK:STDOUT: %Op.type.6f6: type = fn_type @Op.3 [concrete]
  44. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  45. // CHECK:STDOUT: %RightShiftAssign.impl_witness: <witness> = impl_witness file.%RightShiftAssign.impl_witness_table [concrete]
  46. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
  47. // CHECK:STDOUT: %pattern_type.44a: type = pattern_type %ptr.019 [concrete]
  48. // CHECK:STDOUT: %Op.type.aab: type = fn_type @Op.4 [concrete]
  49. // CHECK:STDOUT: %Op.7b2: %Op.type.aab = struct_value () [concrete]
  50. // CHECK:STDOUT: %RightShiftAssign.facet: %RightShiftAssign.type = facet_value %C, (%RightShiftAssign.impl_witness) [concrete]
  51. // CHECK:STDOUT: %TestOp.type: type = fn_type @TestOp [concrete]
  52. // CHECK:STDOUT: %TestOp: %TestOp.type = struct_value () [concrete]
  53. // CHECK:STDOUT: %.17b: type = fn_type_with_self_type %Op.type.4f4, %RightShift.facet [concrete]
  54. // CHECK:STDOUT: %TestAssign.type: type = fn_type @TestAssign [concrete]
  55. // CHECK:STDOUT: %TestAssign: %TestAssign.type = struct_value () [concrete]
  56. // CHECK:STDOUT: %.285: type = fn_type_with_self_type %Op.type.6f6, %RightShiftAssign.facet [concrete]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: imports {
  60. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  61. // CHECK:STDOUT: .RightShift = %Core.RightShift
  62. // CHECK:STDOUT: .RightShiftAssign = %Core.RightShiftAssign
  63. // CHECK:STDOUT: import Core//prelude
  64. // CHECK:STDOUT: import Core//prelude/...
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %Core.RightShift: type = import_ref Core//prelude/operators/bitwise, RightShift, loaded [concrete = constants.%RightShift.type]
  67. // CHECK:STDOUT: %Core.RightShiftAssign: type = import_ref Core//prelude/operators/bitwise, RightShiftAssign, loaded [concrete = constants.%RightShiftAssign.type]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  72. // CHECK:STDOUT: .Core = imports.%Core
  73. // CHECK:STDOUT: .C = %C.decl
  74. // CHECK:STDOUT: .TestOp = %TestOp.decl
  75. // CHECK:STDOUT: .TestAssign = %TestAssign.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Core.import = import Core
  78. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  79. // CHECK:STDOUT: impl_decl @impl.3c1 [concrete] {} {
  80. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  81. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  82. // CHECK:STDOUT: %RightShift.ref: type = name_ref RightShift, imports.%Core.RightShift [concrete = constants.%RightShift.type]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %RightShift.impl_witness_table = impl_witness_table (@impl.3c1.%Op.decl), @impl.3c1 [concrete]
  85. // CHECK:STDOUT: %RightShift.impl_witness: <witness> = impl_witness %RightShift.impl_witness_table [concrete = constants.%RightShift.impl_witness]
  86. // CHECK:STDOUT: impl_decl @impl.4f0 [concrete] {} {
  87. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  88. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
  89. // CHECK:STDOUT: %RightShiftAssign.ref: type = name_ref RightShiftAssign, imports.%Core.RightShiftAssign [concrete = constants.%RightShiftAssign.type]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %RightShiftAssign.impl_witness_table = impl_witness_table (@impl.4f0.%Op.decl), @impl.4f0 [concrete]
  92. // CHECK:STDOUT: %RightShiftAssign.impl_witness: <witness> = impl_witness %RightShiftAssign.impl_witness_table [concrete = constants.%RightShiftAssign.impl_witness]
  93. // CHECK:STDOUT: %TestOp.decl: %TestOp.type = fn_decl @TestOp [concrete = constants.%TestOp] {
  94. // CHECK:STDOUT: %a.patt: %pattern_type.c48 = binding_pattern a [concrete]
  95. // CHECK:STDOUT: %a.param_patt: %pattern_type.c48 = value_param_pattern %a.patt, call_param0 [concrete]
  96. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  97. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  98. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  99. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param2 [concrete]
  100. // CHECK:STDOUT: } {
  101. // CHECK:STDOUT: %C.ref.loc26_26: type = name_ref C, file.%C.decl [concrete = constants.%C]
  102. // CHECK:STDOUT: %a.param: %C = value_param call_param0
  103. // CHECK:STDOUT: %C.ref.loc26_14: type = name_ref C, file.%C.decl [concrete = constants.%C]
  104. // CHECK:STDOUT: %a: %C = bind_name a, %a.param
  105. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  106. // CHECK:STDOUT: %C.ref.loc26_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
  107. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  108. // CHECK:STDOUT: %return.param: ref %C = out_param call_param2
  109. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %TestAssign.decl: %TestAssign.type = fn_decl @TestAssign [concrete = constants.%TestAssign] {
  112. // CHECK:STDOUT: %a.patt: %pattern_type.44a = binding_pattern a [concrete]
  113. // CHECK:STDOUT: %a.param_patt: %pattern_type.44a = value_param_pattern %a.patt, call_param0 [concrete]
  114. // CHECK:STDOUT: %b.patt: %pattern_type.c48 = binding_pattern b [concrete]
  115. // CHECK:STDOUT: %b.param_patt: %pattern_type.c48 = value_param_pattern %b.patt, call_param1 [concrete]
  116. // CHECK:STDOUT: } {
  117. // CHECK:STDOUT: %a.param: %ptr.019 = value_param call_param0
  118. // CHECK:STDOUT: %.loc30: type = splice_block %ptr [concrete = constants.%ptr.019] {
  119. // CHECK:STDOUT: %C.ref.loc30_18: type = name_ref C, file.%C.decl [concrete = constants.%C]
  120. // CHECK:STDOUT: %ptr: type = ptr_type %C.ref.loc30_18 [concrete = constants.%ptr.019]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %a: %ptr.019 = bind_name a, %a.param
  123. // CHECK:STDOUT: %b.param: %C = value_param call_param1
  124. // CHECK:STDOUT: %C.ref.loc30_25: type = name_ref C, file.%C.decl [concrete = constants.%C]
  125. // CHECK:STDOUT: %b: %C = bind_name b, %b.param
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: impl @impl.3c1: %C.ref as %RightShift.ref {
  130. // CHECK:STDOUT: %Op.decl: %Op.type.092 = fn_decl @Op.2 [concrete = constants.%Op.79a] {
  131. // CHECK:STDOUT: %self.patt: %pattern_type.c48 = binding_pattern self [concrete]
  132. // CHECK:STDOUT: %self.param_patt: %pattern_type.c48 = value_param_pattern %self.patt, call_param0 [concrete]
  133. // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
  134. // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
  135. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  136. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param2 [concrete]
  137. // CHECK:STDOUT: } {
  138. // CHECK:STDOUT: %C.ref.loc18_31: type = name_ref C, file.%C.decl [concrete = constants.%C]
  139. // CHECK:STDOUT: %self.param: %C = value_param call_param0
  140. // CHECK:STDOUT: %C.ref.loc18_15: type = name_ref C, file.%C.decl [concrete = constants.%C]
  141. // CHECK:STDOUT: %self: %C = bind_name self, %self.param
  142. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  143. // CHECK:STDOUT: %C.ref.loc18_25: type = name_ref C, file.%C.decl [concrete = constants.%C]
  144. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  145. // CHECK:STDOUT: %return.param: ref %C = out_param call_param2
  146. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: !members:
  150. // CHECK:STDOUT: .C = <poisoned>
  151. // CHECK:STDOUT: .Op = %Op.decl
  152. // CHECK:STDOUT: witness = file.%RightShift.impl_witness
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: impl @impl.4f0: %C.ref as %RightShiftAssign.ref {
  156. // CHECK:STDOUT: %Op.decl: %Op.type.aab = fn_decl @Op.4 [concrete = constants.%Op.7b2] {
  157. // CHECK:STDOUT: %self.patt: %pattern_type.44a = binding_pattern self [concrete]
  158. // CHECK:STDOUT: %self.param_patt: %pattern_type.44a = value_param_pattern %self.patt, call_param0 [concrete]
  159. // CHECK:STDOUT: %.loc23_9: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  160. // CHECK:STDOUT: %other.patt: %pattern_type.c48 = binding_pattern other [concrete]
  161. // CHECK:STDOUT: %other.param_patt: %pattern_type.c48 = value_param_pattern %other.patt, call_param1 [concrete]
  162. // CHECK:STDOUT: } {
  163. // CHECK:STDOUT: %self.param: %ptr.019 = value_param call_param0
  164. // CHECK:STDOUT: %.loc23_21: type = splice_block %ptr [concrete = constants.%ptr.019] {
  165. // CHECK:STDOUT: %C.ref.loc23_20: type = name_ref C, file.%C.decl [concrete = constants.%C]
  166. // CHECK:STDOUT: %ptr: type = ptr_type %C.ref.loc23_20 [concrete = constants.%ptr.019]
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
  169. // CHECK:STDOUT: %other.param: %C = value_param call_param1
  170. // CHECK:STDOUT: %C.ref.loc23_31: type = name_ref C, file.%C.decl [concrete = constants.%C]
  171. // CHECK:STDOUT: %other: %C = bind_name other, %other.param
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: !members:
  175. // CHECK:STDOUT: .C = <poisoned>
  176. // CHECK:STDOUT: .Op = %Op.decl
  177. // CHECK:STDOUT: witness = file.%RightShiftAssign.impl_witness
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: class @C {
  181. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  182. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  183. // CHECK:STDOUT: complete_type_witness = %complete_type
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: !members:
  186. // CHECK:STDOUT: .Self = constants.%C
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: fn @Op.2(%self.param: %C, %other.param: %C) -> %return.param: %C {
  190. // CHECK:STDOUT: !entry:
  191. // CHECK:STDOUT: %.loc19_13.1: %empty_struct_type = struct_literal ()
  192. // CHECK:STDOUT: %.loc19_13.2: init %C = class_init (), %return [concrete = constants.%C.val]
  193. // CHECK:STDOUT: %.loc19_14: init %C = converted %.loc19_13.1, %.loc19_13.2 [concrete = constants.%C.val]
  194. // CHECK:STDOUT: return %.loc19_14 to %return
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: fn @Op.4(%self.param: %ptr.019, %other.param: %C) {
  198. // CHECK:STDOUT: !entry:
  199. // CHECK:STDOUT: return
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: fn @TestOp(%a.param: %C, %b.param: %C) -> %return.param: %C {
  203. // CHECK:STDOUT: !entry:
  204. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  205. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  206. // CHECK:STDOUT: %impl.elem0: %.17b = impl_witness_access constants.%RightShift.impl_witness, element0 [concrete = constants.%Op.79a]
  207. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %a.ref, %impl.elem0
  208. // CHECK:STDOUT: %.loc26: ref %C = splice_block %return {}
  209. // CHECK:STDOUT: %Op.call: init %C = call %bound_method(%a.ref, %b.ref) to %.loc26
  210. // CHECK:STDOUT: return %Op.call to %return
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: fn @TestAssign(%a.param: %ptr.019, %b.param: %C) {
  214. // CHECK:STDOUT: !entry:
  215. // CHECK:STDOUT: %a.ref: %ptr.019 = name_ref a, %a
  216. // CHECK:STDOUT: %.loc31: ref %C = deref %a.ref
  217. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  218. // CHECK:STDOUT: %impl.elem0: %.285 = impl_witness_access constants.%RightShiftAssign.impl_witness, element0 [concrete = constants.%Op.7b2]
  219. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc31, %impl.elem0
  220. // CHECK:STDOUT: %addr: %ptr.019 = addr_of %.loc31
  221. // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%addr, %b.ref)
  222. // CHECK:STDOUT: return
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT: