destroy.carbon 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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/convert.carbon
  6. // EXTRA-ARGS: --clang-arg=--std=c++20
  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/interop/cpp/impls/destroy.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/impls/destroy.carbon
  13. // --- types.h
  14. class PublicDestructor {
  15. public:
  16. ~PublicDestructor();
  17. };
  18. class TrivialDestructor {
  19. public:
  20. ~TrivialDestructor() = default;
  21. };
  22. template<int N = 0>
  23. class AmbiguousDestructorT {
  24. public:
  25. ~AmbiguousDestructorT() requires (N != 1);
  26. ~AmbiguousDestructorT() requires (N != 2);
  27. };
  28. using AmbiguousDestructor = AmbiguousDestructorT<>;
  29. class DeletedDestructor {
  30. public:
  31. ~DeletedDestructor() = delete;
  32. };
  33. class PrivateDestructor {
  34. private:
  35. ~PrivateDestructor();
  36. };
  37. class ProtectedDestructor {
  38. protected:
  39. ~ProtectedDestructor();
  40. };
  41. // --- destroy_destroyable.carbon
  42. library "[[@TEST_NAME]]";
  43. import Cpp library "types.h";
  44. // Dump the whole file so we can see that the trivial destructor maps to a
  45. // "no_op" builtin.
  46. //@include-in-dumps
  47. fn PublicDestroy() {
  48. var unused a: Cpp.PublicDestructor = {};
  49. }
  50. fn TrivialDestroy() {
  51. var unused a: Cpp.TrivialDestructor = {};
  52. }
  53. // --- destroy_protected_base_destructor.carbon
  54. library "[[@TEST_NAME]]";
  55. import Cpp library "types.h";
  56. class Derived {
  57. extend base: Cpp.ProtectedDestructor;
  58. }
  59. fn DestroyClassWithProtectedBaseDestructor() {
  60. //@dump-sem-ir-begin
  61. var unused a: Derived = {.base = {}};
  62. //@dump-sem-ir-end
  63. }
  64. // --- todo_fail_destroy_private_base_destructor.carbon
  65. library "[[@TEST_NAME]]";
  66. import Cpp library "types.h";
  67. class Derived {
  68. extend base: Cpp.PrivateDestructor;
  69. }
  70. fn DestroyClassWithPrivateBaseDestructor() {
  71. //@dump-sem-ir-begin
  72. // TODO: We should not allow this, as the destructor of the base class is private.
  73. var unused a: Derived = {.base = {}};
  74. //@dump-sem-ir-end
  75. }
  76. // --- fail_destroy_nondestroyable.carbon
  77. library "[[@TEST_NAME]]";
  78. import Cpp library "types.h";
  79. fn AmbiguousDestroy() {
  80. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE+20]]:17: error: binding pattern has incomplete type `AmbiguousDestructor` in name binding declaration [IncompleteTypeInBindingDecl]
  81. // CHECK:STDERR: var unused a: Cpp.AmbiguousDestructor = {};
  82. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
  83. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-6]]:10: in file included here [InCppInclude]
  84. // CHECK:STDERR: ./types.h:13:7: note: destructor of class 'AmbiguousDestructorT<>' is ambiguous [CppInteropParseError]
  85. // CHECK:STDERR: 13 | class AmbiguousDestructorT {
  86. // CHECK:STDERR: | ^
  87. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-10]]:10: in file included here [InCppInclude]
  88. // CHECK:STDERR: ./types.h:13:7: note: in instantiation of template class 'AmbiguousDestructorT<>' requested here [CppInteropParseNote]
  89. // CHECK:STDERR: 13 | class AmbiguousDestructorT {
  90. // CHECK:STDERR: | ^
  91. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-14]]:10: in file included here [InCppInclude]
  92. // CHECK:STDERR: ./types.h:15:3: note: candidate function [CppInteropParseNote]
  93. // CHECK:STDERR: 15 | ~AmbiguousDestructorT() requires (N != 1);
  94. // CHECK:STDERR: | ^
  95. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-18]]:10: in file included here [InCppInclude]
  96. // CHECK:STDERR: ./types.h:16:3: note: candidate function [CppInteropParseNote]
  97. // CHECK:STDERR: 16 | ~AmbiguousDestructorT() requires (N != 2);
  98. // CHECK:STDERR: | ^
  99. // CHECK:STDERR:
  100. var unused a: Cpp.AmbiguousDestructor = {};
  101. }
  102. fn DeletedDestroy() {
  103. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE+8]]:3: error: attempt to use a deleted function [CppInteropParseError]
  104. // CHECK:STDERR: 39 | var unused a: Cpp.DeletedDestructor = {};
  105. // CHECK:STDERR: | ^
  106. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-30]]:10: in file included here [InCppInclude]
  107. // CHECK:STDERR: ./types.h:23:3: note: '~DeletedDestructor' has been explicitly marked deleted here [CppInteropParseNote]
  108. // CHECK:STDERR: 23 | ~DeletedDestructor() = delete;
  109. // CHECK:STDERR: | ^
  110. // CHECK:STDERR:
  111. var unused a: Cpp.DeletedDestructor = {};
  112. }
  113. fn PrivateDestroy() {
  114. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE+8]]:3: error: cannot access private member `<C++ destructor>` of type `Cpp.PrivateDestructor` [ClassInvalidMemberAccess]
  115. // CHECK:STDERR: var unused a: Cpp.PrivateDestructor = {};
  116. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-42]]:10: in file included here [InCppInclude]
  118. // CHECK:STDERR: ./types.h:28:3: note: declared here [ClassMemberDeclaration]
  119. // CHECK:STDERR: ~PrivateDestructor();
  120. // CHECK:STDERR: ^
  121. // CHECK:STDERR:
  122. var unused a: Cpp.PrivateDestructor = {};
  123. }
  124. fn ProtectedDestroy() {
  125. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE+8]]:3: error: cannot access protected member `<C++ destructor>` of type `Cpp.ProtectedDestructor` [ClassInvalidMemberAccess]
  126. // CHECK:STDERR: var unused a: Cpp.ProtectedDestructor = {};
  127. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128. // CHECK:STDERR: fail_destroy_nondestroyable.carbon:[[@LINE-54]]:10: in file included here [InCppInclude]
  129. // CHECK:STDERR: ./types.h:33:3: note: declared here [ClassMemberDeclaration]
  130. // CHECK:STDERR: ~ProtectedDestructor();
  131. // CHECK:STDERR: ^
  132. // CHECK:STDERR:
  133. var unused a: Cpp.ProtectedDestructor = {};
  134. }
  135. // --- destroy_generically.carbon
  136. library "[[@TEST_NAME]]";
  137. import Cpp library "types.h";
  138. fn Destroy[T:! Core.Copy & Core.Destroy](c: T) {
  139. var unused d: T = c;
  140. }
  141. fn DoDestroy() {
  142. Destroy({} as Cpp.PublicDestructor);
  143. }
  144. class Wrap(T:! Core.Destroy) {}
  145. fn EqualWitnesses(p: Wrap(Cpp.PublicDestructor)*) -> Wrap(Cpp.PublicDestructor)* {
  146. return p;
  147. }
  148. // CHECK:STDOUT: --- destroy_destroyable.carbon
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: constants {
  151. // CHECK:STDOUT: %PublicDestroy.type: type = fn_type @PublicDestroy [concrete]
  152. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  153. // CHECK:STDOUT: %PublicDestroy: %PublicDestroy.type = struct_value () [concrete]
  154. // CHECK:STDOUT: %PublicDestructor: type = class_type @PublicDestructor [concrete]
  155. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  156. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  157. // CHECK:STDOUT: %pattern_type.27d: type = pattern_type %PublicDestructor [concrete]
  158. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  159. // CHECK:STDOUT: %PublicDestructor.val: %PublicDestructor = struct_value () [concrete]
  160. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  161. // CHECK:STDOUT: %PublicDestructor.cpp_destructor.type: type = fn_type @PublicDestructor.cpp_destructor [concrete]
  162. // CHECK:STDOUT: %PublicDestructor.cpp_destructor: %PublicDestructor.cpp_destructor.type = struct_value () [concrete]
  163. // CHECK:STDOUT: %TrivialDestroy.type: type = fn_type @TrivialDestroy [concrete]
  164. // CHECK:STDOUT: %TrivialDestroy: %TrivialDestroy.type = struct_value () [concrete]
  165. // CHECK:STDOUT: %TrivialDestructor: type = class_type @TrivialDestructor [concrete]
  166. // CHECK:STDOUT: %pattern_type.1b8: type = pattern_type %TrivialDestructor [concrete]
  167. // CHECK:STDOUT: %TrivialDestructor.val: %TrivialDestructor = struct_value () [concrete]
  168. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor.type: type = fn_type @TrivialDestructor.cpp_destructor [concrete]
  169. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor: %TrivialDestructor.cpp_destructor.type = struct_value () [concrete]
  170. // CHECK:STDOUT: %TrivialDestructor.Op.type: type = fn_type @TrivialDestructor.Op [concrete]
  171. // CHECK:STDOUT: %TrivialDestructor.Op: %TrivialDestructor.Op.type = struct_value () [concrete]
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: imports {
  175. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  176. // CHECK:STDOUT: .Destroy = %Core.Destroy
  177. // CHECK:STDOUT: import Core//prelude
  178. // CHECK:STDOUT: import Core//prelude/...
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  181. // CHECK:STDOUT: .PublicDestructor = %PublicDestructor.decl
  182. // CHECK:STDOUT: .TrivialDestructor = %TrivialDestructor.decl
  183. // CHECK:STDOUT: import Cpp//...
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT: %PublicDestructor.decl: type = class_decl @PublicDestructor [concrete = constants.%PublicDestructor] {} {}
  186. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  187. // CHECK:STDOUT: %TrivialDestructor.decl: type = class_decl @TrivialDestructor [concrete = constants.%TrivialDestructor] {} {}
  188. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor.decl: %TrivialDestructor.cpp_destructor.type = fn_decl @TrivialDestructor.cpp_destructor [concrete = constants.%TrivialDestructor.cpp_destructor] {
  189. // CHECK:STDOUT: %self.patt: %pattern_type.1b8 = ref_binding_pattern self [concrete]
  190. // CHECK:STDOUT: %self.param_patt: %pattern_type.1b8 = ref_param_pattern %self.patt [concrete]
  191. // CHECK:STDOUT: } {
  192. // CHECK:STDOUT: %self.param: ref %TrivialDestructor = ref_param call_param0
  193. // CHECK:STDOUT: %self: ref %TrivialDestructor = ref_binding self, %self.param
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: file {
  198. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  199. // CHECK:STDOUT: .Core = imports.%Core
  200. // CHECK:STDOUT: .Cpp = imports.%Cpp
  201. // CHECK:STDOUT: .PublicDestroy = %PublicDestroy.decl
  202. // CHECK:STDOUT: .TrivialDestroy = %TrivialDestroy.decl
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT: %Core.import = import Core
  205. // CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
  206. // CHECK:STDOUT: import Cpp "types.h"
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT: %PublicDestroy.decl: %PublicDestroy.type = fn_decl @PublicDestroy [concrete = constants.%PublicDestroy] {} {}
  209. // CHECK:STDOUT: %TrivialDestroy.decl: %TrivialDestroy.type = fn_decl @TrivialDestroy [concrete = constants.%TrivialDestroy] {} {}
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: class @PublicDestructor {
  213. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  214. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  215. // CHECK:STDOUT: complete_type_witness = %complete_type
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: !members:
  218. // CHECK:STDOUT: import Cpp//...
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: class @TrivialDestructor {
  222. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  223. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  224. // CHECK:STDOUT: complete_type_witness = %complete_type
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: !members:
  227. // CHECK:STDOUT: import Cpp//...
  228. // CHECK:STDOUT: }
  229. // CHECK:STDOUT:
  230. // CHECK:STDOUT: fn @PublicDestroy() {
  231. // CHECK:STDOUT: !entry:
  232. // CHECK:STDOUT: name_binding_decl {
  233. // CHECK:STDOUT: %a.patt: %pattern_type.27d = ref_binding_pattern a [concrete]
  234. // CHECK:STDOUT: %a.var_patt: %pattern_type.27d = var_pattern %a.patt [concrete]
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT: %a.var: ref %PublicDestructor = var %a.var_patt
  237. // CHECK:STDOUT: %.loc11_41.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  238. // CHECK:STDOUT: %.loc11_41.2: init %PublicDestructor to %a.var = class_init () [concrete = constants.%PublicDestructor.val]
  239. // CHECK:STDOUT: %.loc11_3: init %PublicDestructor = converted %.loc11_41.1, %.loc11_41.2 [concrete = constants.%PublicDestructor.val]
  240. // CHECK:STDOUT: assign %a.var, %.loc11_3
  241. // CHECK:STDOUT: %.loc11_20: type = splice_block %PublicDestructor.ref [concrete = constants.%PublicDestructor] {
  242. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  243. // CHECK:STDOUT: %PublicDestructor.ref: type = name_ref PublicDestructor, imports.%PublicDestructor.decl [concrete = constants.%PublicDestructor]
  244. // CHECK:STDOUT: }
  245. // CHECK:STDOUT: %a: ref %PublicDestructor = ref_binding a, %a.var
  246. // CHECK:STDOUT: %PublicDestructor.cpp_destructor.bound: <bound method> = bound_method %a.var, constants.%PublicDestructor.cpp_destructor
  247. // CHECK:STDOUT: %PublicDestructor.cpp_destructor.call: init %empty_tuple.type = call %PublicDestructor.cpp_destructor.bound(%a.var)
  248. // CHECK:STDOUT: return
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: fn @PublicDestructor.cpp_destructor(%self.param: ref %PublicDestructor);
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: fn @TrivialDestroy() {
  254. // CHECK:STDOUT: !entry:
  255. // CHECK:STDOUT: name_binding_decl {
  256. // CHECK:STDOUT: %a.patt: %pattern_type.1b8 = ref_binding_pattern a [concrete]
  257. // CHECK:STDOUT: %a.var_patt: %pattern_type.1b8 = var_pattern %a.patt [concrete]
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT: %a.var: ref %TrivialDestructor = var %a.var_patt
  260. // CHECK:STDOUT: %.loc15_42.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  261. // CHECK:STDOUT: %.loc15_42.2: init %TrivialDestructor to %a.var = class_init () [concrete = constants.%TrivialDestructor.val]
  262. // CHECK:STDOUT: %.loc15_3: init %TrivialDestructor = converted %.loc15_42.1, %.loc15_42.2 [concrete = constants.%TrivialDestructor.val]
  263. // CHECK:STDOUT: assign %a.var, %.loc15_3
  264. // CHECK:STDOUT: %.loc15_20: type = splice_block %TrivialDestructor.ref [concrete = constants.%TrivialDestructor] {
  265. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  266. // CHECK:STDOUT: %TrivialDestructor.ref: type = name_ref TrivialDestructor, imports.%TrivialDestructor.decl [concrete = constants.%TrivialDestructor]
  267. // CHECK:STDOUT: }
  268. // CHECK:STDOUT: %a: ref %TrivialDestructor = ref_binding a, %a.var
  269. // CHECK:STDOUT: %TrivialDestructor.Op.decl: %TrivialDestructor.Op.type = fn_decl @TrivialDestructor.Op [concrete = constants.%TrivialDestructor.Op] {
  270. // CHECK:STDOUT: %self.patt: %pattern_type.1b8 = ref_binding_pattern self [concrete]
  271. // CHECK:STDOUT: %self.param_patt: %pattern_type.1b8 = ref_param_pattern %self.patt [concrete]
  272. // CHECK:STDOUT: } {
  273. // CHECK:STDOUT: %self.param: ref %TrivialDestructor = ref_param call_param0
  274. // CHECK:STDOUT: %self: ref %TrivialDestructor = ref_binding self, %self.param
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT: %TrivialDestructor.Op.bound: <bound method> = bound_method %a.var, constants.%TrivialDestructor.Op
  277. // CHECK:STDOUT: %Op.ref: %TrivialDestructor.cpp_destructor.type = name_ref Op, imports.%TrivialDestructor.cpp_destructor.decl [concrete = constants.%TrivialDestructor.cpp_destructor]
  278. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor.bound: <bound method> = bound_method %a.var, %Op.ref
  279. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor.call: init %empty_tuple.type = call %TrivialDestructor.cpp_destructor.bound(%a.var)
  280. // CHECK:STDOUT: return
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT:
  283. // CHECK:STDOUT: fn @TrivialDestructor.cpp_destructor(%self.param: ref %TrivialDestructor) = "no_op";
  284. // CHECK:STDOUT:
  285. // CHECK:STDOUT: fn @TrivialDestructor.Op(%self.param: ref %TrivialDestructor) [thunk imports.%TrivialDestructor.cpp_destructor.decl] {
  286. // CHECK:STDOUT: !entry:
  287. // CHECK:STDOUT: %Op.ref: %TrivialDestructor.cpp_destructor.type = name_ref Op, imports.%TrivialDestructor.cpp_destructor.decl [concrete = constants.%TrivialDestructor.cpp_destructor]
  288. // CHECK:STDOUT: %self.ref: ref %TrivialDestructor = name_ref self, %self.param
  289. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor.bound: <bound method> = bound_method %self.ref, %Op.ref
  290. // CHECK:STDOUT: %TrivialDestructor.cpp_destructor.call: init %empty_tuple.type = call %TrivialDestructor.cpp_destructor.bound(%self.ref)
  291. // CHECK:STDOUT: return
  292. // CHECK:STDOUT: }
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: --- destroy_protected_base_destructor.carbon
  295. // CHECK:STDOUT:
  296. // CHECK:STDOUT: constants {
  297. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  298. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  299. // CHECK:STDOUT: %ProtectedDestructor: type = class_type @ProtectedDestructor [concrete]
  300. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  301. // CHECK:STDOUT: %pattern_type.9f6: type = pattern_type %Derived [concrete]
  302. // CHECK:STDOUT: %empty_struct.a40: %empty_struct_type = struct_value () [concrete]
  303. // CHECK:STDOUT: %struct_type.base.f5e: type = struct_type {.base: %empty_struct_type} [concrete]
  304. // CHECK:STDOUT: %struct: %struct_type.base.f5e = struct_value (%empty_struct.a40) [concrete]
  305. // CHECK:STDOUT: %.ce2: type = partial_type %ProtectedDestructor [concrete]
  306. // CHECK:STDOUT: %empty_struct.377: %.ce2 = struct_value () [concrete]
  307. // CHECK:STDOUT: %ProtectedDestructor.val: %ProtectedDestructor = struct_value () [concrete]
  308. // CHECK:STDOUT: %Derived.val: %Derived = struct_value (%ProtectedDestructor.val) [concrete]
  309. // CHECK:STDOUT: %Destroy.Op.type: type = fn_type @Destroy.Op [concrete]
  310. // CHECK:STDOUT: %Destroy.Op: %Destroy.Op.type = struct_value () [concrete]
  311. // CHECK:STDOUT: }
  312. // CHECK:STDOUT:
  313. // CHECK:STDOUT: fn @DestroyClassWithProtectedBaseDestructor() {
  314. // CHECK:STDOUT: !entry:
  315. // CHECK:STDOUT: name_binding_decl {
  316. // CHECK:STDOUT: %a.patt: %pattern_type.9f6 = ref_binding_pattern a [concrete]
  317. // CHECK:STDOUT: %a.var_patt: %pattern_type.9f6 = var_pattern %a.patt [concrete]
  318. // CHECK:STDOUT: }
  319. // CHECK:STDOUT: %a.var: ref %Derived = var %a.var_patt
  320. // CHECK:STDOUT: %.loc12_37.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct.a40]
  321. // CHECK:STDOUT: %.loc12_38.1: %struct_type.base.f5e = struct_literal (%.loc12_37.1) [concrete = constants.%struct]
  322. // CHECK:STDOUT: %.loc12_38.2: ref %.ce2 = class_element_access %a.var, element0
  323. // CHECK:STDOUT: %.loc12_37.2: init %.ce2 to %.loc12_38.2 = class_init () [concrete = constants.%empty_struct.377]
  324. // CHECK:STDOUT: %.loc12_38.3: init %.ce2 = converted %.loc12_37.1, %.loc12_37.2 [concrete = constants.%empty_struct.377]
  325. // CHECK:STDOUT: %.loc12_38.4: init %ProtectedDestructor = as_compatible %.loc12_38.3 [concrete = constants.%ProtectedDestructor.val]
  326. // CHECK:STDOUT: %.loc12_38.5: init %Derived to %a.var = class_init (%.loc12_38.4) [concrete = constants.%Derived.val]
  327. // CHECK:STDOUT: %.loc12_3: init %Derived = converted %.loc12_38.1, %.loc12_38.5 [concrete = constants.%Derived.val]
  328. // CHECK:STDOUT: assign %a.var, %.loc12_3
  329. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl [concrete = constants.%Derived]
  330. // CHECK:STDOUT: %a: ref %Derived = ref_binding a, %a.var
  331. // CHECK:STDOUT: %Destroy.Op.bound: <bound method> = bound_method %a.var, constants.%Destroy.Op
  332. // CHECK:STDOUT: %Destroy.Op.call: init %empty_tuple.type = call %Destroy.Op.bound(%a.var)
  333. // CHECK:STDOUT: <elided>
  334. // CHECK:STDOUT: }
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: fn @Destroy.Op(%self.param: ref %Derived) = "no_op";
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: --- todo_fail_destroy_private_base_destructor.carbon
  339. // CHECK:STDOUT:
  340. // CHECK:STDOUT: constants {
  341. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  342. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  343. // CHECK:STDOUT: %PrivateDestructor: type = class_type @PrivateDestructor [concrete]
  344. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  345. // CHECK:STDOUT: %pattern_type.9f6: type = pattern_type %Derived [concrete]
  346. // CHECK:STDOUT: %empty_struct.a40: %empty_struct_type = struct_value () [concrete]
  347. // CHECK:STDOUT: %struct_type.base.f5e: type = struct_type {.base: %empty_struct_type} [concrete]
  348. // CHECK:STDOUT: %struct: %struct_type.base.f5e = struct_value (%empty_struct.a40) [concrete]
  349. // CHECK:STDOUT: %.b20: type = partial_type %PrivateDestructor [concrete]
  350. // CHECK:STDOUT: %empty_struct.361: %.b20 = struct_value () [concrete]
  351. // CHECK:STDOUT: %PrivateDestructor.val: %PrivateDestructor = struct_value () [concrete]
  352. // CHECK:STDOUT: %Derived.val: %Derived = struct_value (%PrivateDestructor.val) [concrete]
  353. // CHECK:STDOUT: %Destroy.Op.type: type = fn_type @Destroy.Op [concrete]
  354. // CHECK:STDOUT: %Destroy.Op: %Destroy.Op.type = struct_value () [concrete]
  355. // CHECK:STDOUT: }
  356. // CHECK:STDOUT:
  357. // CHECK:STDOUT: fn @DestroyClassWithPrivateBaseDestructor() {
  358. // CHECK:STDOUT: !entry:
  359. // CHECK:STDOUT: name_binding_decl {
  360. // CHECK:STDOUT: %a.patt: %pattern_type.9f6 = ref_binding_pattern a [concrete]
  361. // CHECK:STDOUT: %a.var_patt: %pattern_type.9f6 = var_pattern %a.patt [concrete]
  362. // CHECK:STDOUT: }
  363. // CHECK:STDOUT: %a.var: ref %Derived = var %a.var_patt
  364. // CHECK:STDOUT: %.loc13_37.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct.a40]
  365. // CHECK:STDOUT: %.loc13_38.1: %struct_type.base.f5e = struct_literal (%.loc13_37.1) [concrete = constants.%struct]
  366. // CHECK:STDOUT: %.loc13_38.2: ref %.b20 = class_element_access %a.var, element0
  367. // CHECK:STDOUT: %.loc13_37.2: init %.b20 to %.loc13_38.2 = class_init () [concrete = constants.%empty_struct.361]
  368. // CHECK:STDOUT: %.loc13_38.3: init %.b20 = converted %.loc13_37.1, %.loc13_37.2 [concrete = constants.%empty_struct.361]
  369. // CHECK:STDOUT: %.loc13_38.4: init %PrivateDestructor = as_compatible %.loc13_38.3 [concrete = constants.%PrivateDestructor.val]
  370. // CHECK:STDOUT: %.loc13_38.5: init %Derived to %a.var = class_init (%.loc13_38.4) [concrete = constants.%Derived.val]
  371. // CHECK:STDOUT: %.loc13_3: init %Derived = converted %.loc13_38.1, %.loc13_38.5 [concrete = constants.%Derived.val]
  372. // CHECK:STDOUT: assign %a.var, %.loc13_3
  373. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, file.%Derived.decl [concrete = constants.%Derived]
  374. // CHECK:STDOUT: %a: ref %Derived = ref_binding a, %a.var
  375. // CHECK:STDOUT: %Destroy.Op.bound: <bound method> = bound_method %a.var, constants.%Destroy.Op
  376. // CHECK:STDOUT: %Destroy.Op.call: init %empty_tuple.type = call %Destroy.Op.bound(%a.var)
  377. // CHECK:STDOUT: <elided>
  378. // CHECK:STDOUT: }
  379. // CHECK:STDOUT:
  380. // CHECK:STDOUT: fn @Destroy.Op(%self.param: ref %Derived) = "no_op";
  381. // CHECK:STDOUT: