bit_xor.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. // This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  7. package User;
  8. class C {};
  9. impl C as Core.BitXor {
  10. fn Op[self: C](other: C) -> C {
  11. return {};
  12. }
  13. }
  14. impl C as Core.BitXorAssign {
  15. fn Op[addr self: C*](other: C) {}
  16. }
  17. fn TestOp(a: C, b: C) -> C {
  18. return a ^ b;
  19. }
  20. fn TestAssign(a: C*, b: C) {
  21. *a ^= b;
  22. }
  23. // CHECK:STDOUT: --- bit_xor.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %C: type = class_type @C [template]
  27. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  28. // CHECK:STDOUT: %.2: type = interface_type @BitXor [template]
  29. // CHECK:STDOUT: %Self.1: BitXor = bind_symbolic_name Self 0 [symbolic]
  30. // CHECK:STDOUT: %Op.1: type = fn_type @Op.1 [template]
  31. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  32. // CHECK:STDOUT: %struct.1: Op = struct_value () [template]
  33. // CHECK:STDOUT: %Op.2: type = fn_type @Op.2 [template]
  34. // CHECK:STDOUT: %struct.2: Op = struct_value () [template]
  35. // CHECK:STDOUT: %.4: <witness> = interface_witness (%struct.1) [template]
  36. // CHECK:STDOUT: %.5: type = ptr_type {} [template]
  37. // CHECK:STDOUT: %struct.3: C = struct_value () [template]
  38. // CHECK:STDOUT: %.6: type = interface_type @BitXorAssign [template]
  39. // CHECK:STDOUT: %Self.2: BitXorAssign = bind_symbolic_name Self 0 [symbolic]
  40. // CHECK:STDOUT: %.7: type = ptr_type C [template]
  41. // CHECK:STDOUT: %Op.3: type = fn_type @Op.3 [template]
  42. // CHECK:STDOUT: %struct.4: Op = struct_value () [template]
  43. // CHECK:STDOUT: %.8: type = ptr_type Self [symbolic]
  44. // CHECK:STDOUT: %Op.4: type = fn_type @Op.4 [template]
  45. // CHECK:STDOUT: %struct.5: Op = struct_value () [template]
  46. // CHECK:STDOUT: %.9: <witness> = interface_witness (%struct.4) [template]
  47. // CHECK:STDOUT: %TestOp: type = fn_type @TestOp [template]
  48. // CHECK:STDOUT: %struct.6: TestOp = struct_value () [template]
  49. // CHECK:STDOUT: %.10: type = assoc_entity_type @BitXor, Op [template]
  50. // CHECK:STDOUT: %.11: <associated Op in BitXor> = assoc_entity element0, file.%import_ref.10 [template]
  51. // CHECK:STDOUT: %TestAssign: type = fn_type @TestAssign [template]
  52. // CHECK:STDOUT: %struct.7: TestAssign = struct_value () [template]
  53. // CHECK:STDOUT: %.12: type = assoc_entity_type @BitXorAssign, Op [template]
  54. // CHECK:STDOUT: %.13: <associated Op in BitXorAssign> = assoc_entity element0, file.%import_ref.12 [template]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  59. // CHECK:STDOUT: .Core = %Core
  60. // CHECK:STDOUT: .C = %C.decl
  61. // CHECK:STDOUT: .TestOp = %TestOp.decl
  62. // CHECK:STDOUT: .TestAssign = %TestAssign.decl
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  65. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  66. // CHECK:STDOUT: %import_ref.1: type = import_ref ir5, inst+115, loaded [template = constants.%.2]
  67. // CHECK:STDOUT: %import_ref.2 = import_ref ir5, inst+117, unloaded
  68. // CHECK:STDOUT: %import_ref.3: <associated Op in BitXor> = import_ref ir5, inst+137, loaded [template = constants.%.11]
  69. // CHECK:STDOUT: %import_ref.4: Op = import_ref ir5, inst+133, loaded [template = constants.%struct.2]
  70. // CHECK:STDOUT: impl_decl @impl.1 {
  71. // CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
  72. // CHECK:STDOUT: %Core.ref.loc13: <namespace> = name_ref Core, %Core [template = %Core]
  73. // CHECK:STDOUT: %BitXor.ref: type = name_ref BitXor, %import_ref.1 [template = constants.%.2]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %import_ref.5: type = import_ref ir5, inst+139, loaded [template = constants.%.6]
  76. // CHECK:STDOUT: %import_ref.6 = import_ref ir5, inst+141, unloaded
  77. // CHECK:STDOUT: %import_ref.7: <associated Op in BitXorAssign> = import_ref ir5, inst+160, loaded [template = constants.%.13]
  78. // CHECK:STDOUT: %import_ref.8: Op = import_ref ir5, inst+156, loaded [template = constants.%struct.5]
  79. // CHECK:STDOUT: impl_decl @impl.2 {
  80. // CHECK:STDOUT: %C.ref.loc18: type = name_ref C, %C.decl [template = constants.%C]
  81. // CHECK:STDOUT: %Core.ref.loc18: <namespace> = name_ref Core, %Core [template = %Core]
  82. // CHECK:STDOUT: %BitXorAssign.ref: type = name_ref BitXorAssign, %import_ref.5 [template = constants.%.6]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %TestOp.decl: TestOp = fn_decl @TestOp [template = constants.%struct.6] {
  85. // CHECK:STDOUT: %C.ref.loc22_14: type = name_ref C, %C.decl [template = constants.%C]
  86. // CHECK:STDOUT: %a.loc22_11.1: C = param a
  87. // CHECK:STDOUT: @TestOp.%a: C = bind_name a, %a.loc22_11.1
  88. // CHECK:STDOUT: %C.ref.loc22_20: type = name_ref C, %C.decl [template = constants.%C]
  89. // CHECK:STDOUT: %b.loc22_17.1: C = param b
  90. // CHECK:STDOUT: @TestOp.%b: C = bind_name b, %b.loc22_17.1
  91. // CHECK:STDOUT: %C.ref.loc22_26: type = name_ref C, %C.decl [template = constants.%C]
  92. // CHECK:STDOUT: @TestOp.%return: ref C = var <return slot>
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %import_ref.9: type = import_ref ir5, inst+115, loaded [template = constants.%.2]
  95. // CHECK:STDOUT: %import_ref.10 = import_ref ir5, inst+133, unloaded
  96. // CHECK:STDOUT: %TestAssign.decl: TestAssign = fn_decl @TestAssign [template = constants.%struct.7] {
  97. // CHECK:STDOUT: %C.ref.loc26_18: type = name_ref C, %C.decl [template = constants.%C]
  98. // CHECK:STDOUT: %.loc26: type = ptr_type C [template = constants.%.7]
  99. // CHECK:STDOUT: %a.loc26_15.1: C* = param a
  100. // CHECK:STDOUT: @TestAssign.%a: C* = bind_name a, %a.loc26_15.1
  101. // CHECK:STDOUT: %C.ref.loc26_25: type = name_ref C, %C.decl [template = constants.%C]
  102. // CHECK:STDOUT: %b.loc26_22.1: C = param b
  103. // CHECK:STDOUT: @TestAssign.%b: C = bind_name b, %b.loc26_22.1
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %import_ref.11: type = import_ref ir5, inst+139, loaded [template = constants.%.6]
  106. // CHECK:STDOUT: %import_ref.12 = import_ref ir5, inst+156, unloaded
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: interface @BitXor {
  110. // CHECK:STDOUT: !members:
  111. // CHECK:STDOUT: .Self = file.%import_ref.2
  112. // CHECK:STDOUT: .Op = file.%import_ref.3
  113. // CHECK:STDOUT: witness = (file.%import_ref.4)
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: interface @BitXorAssign {
  117. // CHECK:STDOUT: !members:
  118. // CHECK:STDOUT: .Self = file.%import_ref.6
  119. // CHECK:STDOUT: .Op = file.%import_ref.7
  120. // CHECK:STDOUT: witness = (file.%import_ref.8)
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: impl @impl.1: C as BitXor {
  124. // CHECK:STDOUT: %Op.decl: Op = fn_decl @Op.1 [template = constants.%struct.1] {
  125. // CHECK:STDOUT: %C.ref.loc14_15: type = name_ref C, file.%C.decl [template = constants.%C]
  126. // CHECK:STDOUT: %self.loc14_9.1: C = param self
  127. // CHECK:STDOUT: %self.loc14_9.2: C = bind_name self, %self.loc14_9.1
  128. // CHECK:STDOUT: %C.ref.loc14_25: type = name_ref C, file.%C.decl [template = constants.%C]
  129. // CHECK:STDOUT: %other.loc14_18.1: C = param other
  130. // CHECK:STDOUT: %other.loc14_18.2: C = bind_name other, %other.loc14_18.1
  131. // CHECK:STDOUT: %C.ref.loc14_31: type = name_ref C, file.%C.decl [template = constants.%C]
  132. // CHECK:STDOUT: %return.var: ref C = var <return slot>
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.4]
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: !members:
  137. // CHECK:STDOUT: .Op = %Op.decl
  138. // CHECK:STDOUT: witness = %.1
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: impl @impl.2: C as BitXorAssign {
  142. // CHECK:STDOUT: %Op.decl: Op = fn_decl @Op.3 [template = constants.%struct.4] {
  143. // CHECK:STDOUT: %C.ref.loc19_20: type = name_ref C, file.%C.decl [template = constants.%C]
  144. // CHECK:STDOUT: %.loc19_21: type = ptr_type C [template = constants.%.7]
  145. // CHECK:STDOUT: %self.loc19_14.1: C* = param self
  146. // CHECK:STDOUT: %self.loc19_14.3: C* = bind_name self, %self.loc19_14.1
  147. // CHECK:STDOUT: %.loc19_9: C* = addr_pattern %self.loc19_14.3
  148. // CHECK:STDOUT: %C.ref.loc19_31: type = name_ref C, file.%C.decl [template = constants.%C]
  149. // CHECK:STDOUT: %other.loc19_24.1: C = param other
  150. // CHECK:STDOUT: %other.loc19_24.2: C = bind_name other, %other.loc19_24.1
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Op.decl) [template = constants.%.9]
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: !members:
  155. // CHECK:STDOUT: .Op = %Op.decl
  156. // CHECK:STDOUT: witness = %.1
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: class @C {
  160. // CHECK:STDOUT: !members:
  161. // CHECK:STDOUT: .Self = constants.%C
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: fn @Op.1[@impl.1.%self.loc14_9.2: C](@impl.1.%other.loc14_18.2: C) -> @impl.1.%return.var: C {
  165. // CHECK:STDOUT: !entry:
  166. // CHECK:STDOUT: %.loc15_13.1: {} = struct_literal ()
  167. // CHECK:STDOUT: %.loc15_13.2: init C = class_init (), @impl.1.%return.var [template = constants.%struct.3]
  168. // CHECK:STDOUT: %.loc15_14: init C = converted %.loc15_13.1, %.loc15_13.2 [template = constants.%struct.3]
  169. // CHECK:STDOUT: return %.loc15_14 to @impl.1.%return.var
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: fn @Op.2[%self: Self](%other: Self) -> Self;
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: fn @Op.3[addr @impl.2.%self.loc19_14.3: C*](@impl.2.%other.loc19_24.2: C) {
  175. // CHECK:STDOUT: !entry:
  176. // CHECK:STDOUT: return
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn @Op.4[addr %self: Self*](%other: Self);
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: fn @TestOp(%a: C, %b: C) -> %return: C {
  182. // CHECK:STDOUT: !entry:
  183. // CHECK:STDOUT: %a.ref: C = name_ref a, %a
  184. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  185. // CHECK:STDOUT: %.1: Op = interface_witness_access @impl.1.%.1, element0 [template = constants.%struct.1]
  186. // CHECK:STDOUT: %.loc23: <bound method> = bound_method %a.ref, %.1
  187. // CHECK:STDOUT: %.loc22: ref C = splice_block %return {}
  188. // CHECK:STDOUT: %Op.call: init C = call %.loc23(%a.ref, %b.ref) to %.loc22
  189. // CHECK:STDOUT: return %Op.call to %return
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: fn @TestAssign(%a: C*, %b: C) {
  193. // CHECK:STDOUT: !entry:
  194. // CHECK:STDOUT: %a.ref: C* = name_ref a, %a
  195. // CHECK:STDOUT: %.loc27_3.1: ref C = deref %a.ref
  196. // CHECK:STDOUT: %b.ref: C = name_ref b, %b
  197. // CHECK:STDOUT: %.1: Op = interface_witness_access @impl.2.%.1, element0 [template = constants.%struct.4]
  198. // CHECK:STDOUT: %.loc27_6: <bound method> = bound_method %.loc27_3.1, %.1
  199. // CHECK:STDOUT: %.loc27_3.2: C* = addr_of %.loc27_3.1
  200. // CHECK:STDOUT: %Op.call: init () = call %.loc27_6(%.loc27_3.2, %b.ref)
  201. // CHECK:STDOUT: return
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT: