fail_memaccess_category.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_memaccess_category.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_memaccess_category.carbon
  13. class A {
  14. fn F[addr self: A*]();
  15. }
  16. class B {
  17. var a: A;
  18. }
  19. fn F(s: {.a: A}, b: B) {
  20. // `s` has only a value representation, so this must be invalid.
  21. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE+7]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
  22. // CHECK:STDERR: s.a.F();
  23. // CHECK:STDERR: ^~~
  24. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE-12]]:8: note: initializing function parameter [InCallToFunctionParam]
  25. // CHECK:STDERR: fn F[addr self: A*]();
  26. // CHECK:STDERR: ^~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. s.a.F();
  29. // `b` has an object representation for `A`, but this is still invalid for
  30. // consistency.
  31. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE+7]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
  32. // CHECK:STDERR: b.a.F();
  33. // CHECK:STDERR: ^~~
  34. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE-23]]:8: note: initializing function parameter [InCallToFunctionParam]
  35. // CHECK:STDERR: fn F[addr self: A*]();
  36. // CHECK:STDERR: ^~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. b.a.F();
  39. }
  40. // CHECK:STDOUT: --- fail_memaccess_category.carbon
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: constants {
  43. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  44. // CHECK:STDOUT: %ptr.6db: type = ptr_type %A [concrete]
  45. // CHECK:STDOUT: %pattern_type.5f8: type = pattern_type %ptr.6db [concrete]
  46. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  47. // CHECK:STDOUT: %F.type.649: type = fn_type @F.1 [concrete]
  48. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  49. // CHECK:STDOUT: %F.485: %F.type.649 = struct_value () [concrete]
  50. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  51. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  52. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  53. // CHECK:STDOUT: %B.elem: type = unbound_element_type %B, %A [concrete]
  54. // CHECK:STDOUT: %struct_type.a.72c: type = struct_type {.a: %A} [concrete]
  55. // CHECK:STDOUT: %complete_type.2b9: <witness> = complete_type_witness %struct_type.a.72c [concrete]
  56. // CHECK:STDOUT: %pattern_type.c19: type = pattern_type %struct_type.a.72c [concrete]
  57. // CHECK:STDOUT: %pattern_type.049: type = pattern_type %B [concrete]
  58. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.2 [concrete]
  59. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  64. // CHECK:STDOUT: import Core//prelude
  65. // CHECK:STDOUT: import Core//prelude/...
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: file {
  70. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  71. // CHECK:STDOUT: .Core = imports.%Core
  72. // CHECK:STDOUT: .A = %A.decl
  73. // CHECK:STDOUT: .B = %B.decl
  74. // CHECK:STDOUT: .F = %F.decl
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.import = import Core
  77. // CHECK:STDOUT: %A.decl: type = class_decl @A [concrete = constants.%A] {} {}
  78. // CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
  79. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.2 [concrete = constants.%F.c41] {
  80. // CHECK:STDOUT: %s.patt: %pattern_type.c19 = binding_pattern s [concrete]
  81. // CHECK:STDOUT: %s.param_patt: %pattern_type.c19 = value_param_pattern %s.patt, call_param0 [concrete]
  82. // CHECK:STDOUT: %b.patt: %pattern_type.049 = binding_pattern b [concrete]
  83. // CHECK:STDOUT: %b.param_patt: %pattern_type.049 = value_param_pattern %b.patt, call_param1 [concrete]
  84. // CHECK:STDOUT: } {
  85. // CHECK:STDOUT: %s.param: %struct_type.a.72c = value_param call_param0
  86. // CHECK:STDOUT: %.loc22: type = splice_block %struct_type.a [concrete = constants.%struct_type.a.72c] {
  87. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  88. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %A} [concrete = constants.%struct_type.a.72c]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %s: %struct_type.a.72c = bind_name s, %s.param
  91. // CHECK:STDOUT: %b.param: %B = value_param call_param1
  92. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  93. // CHECK:STDOUT: %b: %B = bind_name b, %b.param
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: class @A {
  98. // CHECK:STDOUT: %F.decl: %F.type.649 = fn_decl @F.1 [concrete = constants.%F.485] {
  99. // CHECK:STDOUT: %self.patt: %pattern_type.5f8 = binding_pattern self [concrete]
  100. // CHECK:STDOUT: %self.param_patt: %pattern_type.5f8 = value_param_pattern %self.patt, call_param0 [concrete]
  101. // CHECK:STDOUT: %.loc15_8: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  102. // CHECK:STDOUT: } {
  103. // CHECK:STDOUT: %self.param: %ptr.6db = value_param call_param0
  104. // CHECK:STDOUT: %.loc15_20: type = splice_block %ptr [concrete = constants.%ptr.6db] {
  105. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  106. // CHECK:STDOUT: %ptr: type = ptr_type %A.ref [concrete = constants.%ptr.6db]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %self: %ptr.6db = bind_name self, %self.param
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  111. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  112. // CHECK:STDOUT: complete_type_witness = %complete_type
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: !members:
  115. // CHECK:STDOUT: .Self = constants.%A
  116. // CHECK:STDOUT: .A = <poisoned>
  117. // CHECK:STDOUT: .F = %F.decl
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: class @B {
  121. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
  122. // CHECK:STDOUT: %.loc19: %B.elem = field_decl a, element0 [concrete]
  123. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %A} [concrete = constants.%struct_type.a.72c]
  124. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [concrete = constants.%complete_type.2b9]
  125. // CHECK:STDOUT: complete_type_witness = %complete_type
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = constants.%B
  129. // CHECK:STDOUT: .A = <poisoned>
  130. // CHECK:STDOUT: .a = %.loc19
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: fn @F.1(%self.param: %ptr.6db);
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: fn @F.2(%s.param: %struct_type.a.72c, %b.param: %B) {
  136. // CHECK:STDOUT: !entry:
  137. // CHECK:STDOUT: %s.ref: %struct_type.a.72c = name_ref s, %s
  138. // CHECK:STDOUT: %.loc31_4.1: %A = struct_access %s.ref, element0
  139. // CHECK:STDOUT: %F.ref.loc31: %F.type.649 = name_ref F, @A.%F.decl [concrete = constants.%F.485]
  140. // CHECK:STDOUT: %F.bound.loc31: <bound method> = bound_method %.loc31_4.1, %F.ref.loc31
  141. // CHECK:STDOUT: %.loc31_4.2: ref %A = temporary_storage
  142. // CHECK:STDOUT: %addr.loc31: %ptr.6db = addr_of %.loc31_4.2
  143. // CHECK:STDOUT: %F.call.loc31: init %empty_tuple.type = call %F.bound.loc31(%addr.loc31)
  144. // CHECK:STDOUT: %b.ref: %B = name_ref b, %b
  145. // CHECK:STDOUT: %a.ref: %B.elem = name_ref a, @B.%.loc19 [concrete = @B.%.loc19]
  146. // CHECK:STDOUT: %.loc42_4.1: ref %A = class_element_access %b.ref, element0
  147. // CHECK:STDOUT: %.loc42_4.2: %A = bind_value %.loc42_4.1
  148. // CHECK:STDOUT: %F.ref.loc42: %F.type.649 = name_ref F, @A.%F.decl [concrete = constants.%F.485]
  149. // CHECK:STDOUT: %F.bound.loc42: <bound method> = bound_method %.loc42_4.2, %F.ref.loc42
  150. // CHECK:STDOUT: %.loc42_4.3: ref %A = temporary_storage
  151. // CHECK:STDOUT: %addr.loc42: %ptr.6db = addr_of %.loc42_4.3
  152. // CHECK:STDOUT: %F.call.loc42: init %empty_tuple.type = call %F.bound.loc42(%addr.loc42)
  153. // CHECK:STDOUT: return
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: