left_shift.carbon 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/overloaded/left_shift.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/left_shift.carbon
  14. // This file was generated from binary_op.carbon.tmpl. Run make_tests.sh to regenerate.
  15. package User;
  16. class C {};
  17. impl C as Core.LeftShiftWith(C) where .Result = C {
  18. fn Op[self: C](other: C) -> C {
  19. return {};
  20. }
  21. }
  22. impl C as Core.LeftShiftAssignWith(C) {
  23. fn Op[addr self: C*](other: C) {}
  24. }
  25. fn TestOp(a: C, b: C) -> C {
  26. //@dump-sem-ir-begin
  27. return a << b;
  28. //@dump-sem-ir-end
  29. }
  30. fn TestAssign(a: C*, b: C) {
  31. //@dump-sem-ir-begin
  32. *a <<= b;
  33. //@dump-sem-ir-end
  34. }
  35. // CHECK:STDOUT: --- left_shift.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  39. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  40. // CHECK:STDOUT: %LeftShiftWith.type.f92: type = facet_type <@LeftShiftWith, @LeftShiftWith(%C)> [concrete]
  41. // CHECK:STDOUT: %Op.type.097: type = fn_type @Op.1, @LeftShiftWith(%C) [concrete]
  42. // CHECK:STDOUT: %LeftShiftWith.impl_witness: <witness> = impl_witness file.%LeftShiftWith.impl_witness_table [concrete]
  43. // CHECK:STDOUT: %Op.type.be6: type = fn_type @Op.loc22 [concrete]
  44. // CHECK:STDOUT: %Op.4d9: %Op.type.be6 = struct_value () [concrete]
  45. // CHECK:STDOUT: %LeftShiftWith.facet.662: %LeftShiftWith.type.f92 = facet_value %C, (%LeftShiftWith.impl_witness) [concrete]
  46. // CHECK:STDOUT: %LeftShiftAssignWith.type.56d: type = facet_type <@LeftShiftAssignWith, @LeftShiftAssignWith(%C)> [concrete]
  47. // CHECK:STDOUT: %Op.type.30f: type = fn_type @Op.6, @LeftShiftAssignWith(%C) [concrete]
  48. // CHECK:STDOUT: %LeftShiftAssignWith.impl_witness: <witness> = impl_witness file.%LeftShiftAssignWith.impl_witness_table [concrete]
  49. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
  50. // CHECK:STDOUT: %Op.type.b1b6: type = fn_type @Op.loc27 [concrete]
  51. // CHECK:STDOUT: %Op.07c: %Op.type.b1b6 = struct_value () [concrete]
  52. // CHECK:STDOUT: %LeftShiftAssignWith.facet: %LeftShiftAssignWith.type.56d = facet_value %C, (%LeftShiftAssignWith.impl_witness) [concrete]
  53. // CHECK:STDOUT: %.cd9: type = fn_type_with_self_type %Op.type.097, %LeftShiftWith.facet.662 [concrete]
  54. // CHECK:STDOUT: %.97b: type = fn_type_with_self_type %Op.type.30f, %LeftShiftAssignWith.facet [concrete]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: imports {
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @TestOp(%a.param: %C, %b.param: %C) -> %return.param: %C {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %a.ref: %C = name_ref a, %a
  63. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  64. // CHECK:STDOUT: %impl.elem1: %.cd9 = impl_witness_access constants.%LeftShiftWith.impl_witness, element1 [concrete = constants.%Op.4d9]
  65. // CHECK:STDOUT: %bound_method.loc32: <bound method> = bound_method %a.ref, %impl.elem1
  66. // CHECK:STDOUT: <elided>
  67. // CHECK:STDOUT: %Op.call: init %C = call %bound_method.loc32(%a.ref, %b.ref) to %.loc30
  68. // CHECK:STDOUT: <elided>
  69. // CHECK:STDOUT: return %Op.call to %return
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @TestAssign(%a.param: %ptr.019, %b.param: %C) {
  73. // CHECK:STDOUT: !entry:
  74. // CHECK:STDOUT: %a.ref: %ptr.019 = name_ref a, %a
  75. // CHECK:STDOUT: %.loc38: ref %C = deref %a.ref
  76. // CHECK:STDOUT: %b.ref: %C = name_ref b, %b
  77. // CHECK:STDOUT: %impl.elem0: %.97b = impl_witness_access constants.%LeftShiftAssignWith.impl_witness, element0 [concrete = constants.%Op.07c]
  78. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc38, %impl.elem0
  79. // CHECK:STDOUT: %addr: %ptr.019 = addr_of %.loc38
  80. // CHECK:STDOUT: %Op.call: init %empty_tuple.type = call %bound_method(%addr, %b.ref)
  81. // CHECK:STDOUT: <elided>
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: