derived_to_base.carbon 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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/class/derived_to_base.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/derived_to_base.carbon
  10. base class A {
  11. var a: i32;
  12. }
  13. base class B {
  14. extend base: A;
  15. var b: i32;
  16. }
  17. class C {
  18. extend base: B;
  19. var c: i32;
  20. }
  21. fn ConvertCToB(p: C*) -> B* { return p; }
  22. fn ConvertBToA(p: B*) -> A* { return p; }
  23. fn ConvertCToA(p: C*) -> A* { return p; }
  24. fn ConvertValue(c: C) {
  25. let a: A = c;
  26. }
  27. fn ConvertRef(c: C*) -> A* {
  28. return &(*c as A);
  29. }
  30. fn ConvertInit() {
  31. let a: A = {.base = {.base = {.a = 1}, .b = 2}, .c = 3} as C;
  32. }
  33. // CHECK:STDOUT: --- derived_to_base.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %A: type = class_type @A [template]
  37. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  38. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  39. // CHECK:STDOUT: %A.elem: type = unbound_element_type %A, %i32 [template]
  40. // CHECK:STDOUT: %struct_type.a.ba9: type = struct_type {.a: %i32} [template]
  41. // CHECK:STDOUT: %complete_type.fd7: <witness> = complete_type_witness %struct_type.a.ba9 [template]
  42. // CHECK:STDOUT: %B: type = class_type @B [template]
  43. // CHECK:STDOUT: %B.elem.e38: type = unbound_element_type %B, %A [template]
  44. // CHECK:STDOUT: %B.elem.5c3: type = unbound_element_type %B, %i32 [template]
  45. // CHECK:STDOUT: %struct_type.base.b.b44: type = struct_type {.base: %A, .b: %i32} [template]
  46. // CHECK:STDOUT: %complete_type.725: <witness> = complete_type_witness %struct_type.base.b.b44 [template]
  47. // CHECK:STDOUT: %C: type = class_type @C [template]
  48. // CHECK:STDOUT: %C.elem.f0c: type = unbound_element_type %C, %B [template]
  49. // CHECK:STDOUT: %C.elem.646: type = unbound_element_type %C, %i32 [template]
  50. // CHECK:STDOUT: %struct_type.base.c.8e2: type = struct_type {.base: %B, .c: %i32} [template]
  51. // CHECK:STDOUT: %complete_type.58a: <witness> = complete_type_witness %struct_type.base.c.8e2 [template]
  52. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [template]
  53. // CHECK:STDOUT: %ptr.e79: type = ptr_type %B [template]
  54. // CHECK:STDOUT: %ConvertCToB.type: type = fn_type @ConvertCToB [template]
  55. // CHECK:STDOUT: %ConvertCToB: %ConvertCToB.type = struct_value () [template]
  56. // CHECK:STDOUT: %ptr.6db: type = ptr_type %A [template]
  57. // CHECK:STDOUT: %ConvertBToA.type: type = fn_type @ConvertBToA [template]
  58. // CHECK:STDOUT: %ConvertBToA: %ConvertBToA.type = struct_value () [template]
  59. // CHECK:STDOUT: %ConvertCToA.type: type = fn_type @ConvertCToA [template]
  60. // CHECK:STDOUT: %ConvertCToA: %ConvertCToA.type = struct_value () [template]
  61. // CHECK:STDOUT: %ConvertValue.type: type = fn_type @ConvertValue [template]
  62. // CHECK:STDOUT: %ConvertValue: %ConvertValue.type = struct_value () [template]
  63. // CHECK:STDOUT: %ConvertRef.type: type = fn_type @ConvertRef [template]
  64. // CHECK:STDOUT: %ConvertRef: %ConvertRef.type = struct_value () [template]
  65. // CHECK:STDOUT: %ConvertInit.type: type = fn_type @ConvertInit [template]
  66. // CHECK:STDOUT: %ConvertInit: %ConvertInit.type = struct_value () [template]
  67. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  68. // CHECK:STDOUT: %struct_type.a.a6c: type = struct_type {.a: Core.IntLiteral} [template]
  69. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  70. // CHECK:STDOUT: %struct_type.base.b.bf0: type = struct_type {.base: %struct_type.a.a6c, .b: Core.IntLiteral} [template]
  71. // CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [template]
  72. // CHECK:STDOUT: %struct_type.base.c.136: type = struct_type {.base: %struct_type.base.b.bf0, .c: Core.IntLiteral} [template]
  73. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  74. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  75. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  76. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  77. // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
  78. // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
  79. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
  80. // CHECK:STDOUT: %A.val: %A = struct_value (%int_1.5d2) [template]
  81. // CHECK:STDOUT: %Convert.bound.ef9: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  82. // CHECK:STDOUT: %Convert.specific_fn.787: <specific function> = specific_function %Convert.bound.ef9, @Convert.2(%int_32) [template]
  83. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  84. // CHECK:STDOUT: %B.val: %B = struct_value (%A.val, %int_2.ef8) [template]
  85. // CHECK:STDOUT: %Convert.bound.b30: <bound method> = bound_method %int_3.1ba, %Convert.956 [template]
  86. // CHECK:STDOUT: %Convert.specific_fn.b42: <specific function> = specific_function %Convert.bound.b30, @Convert.2(%int_32) [template]
  87. // CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [template]
  88. // CHECK:STDOUT: %C.val: %C = struct_value (%B.val, %int_3.822) [template]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: imports {
  92. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  93. // CHECK:STDOUT: .Int = %Core.Int
  94. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  95. // CHECK:STDOUT: import Core//prelude
  96. // CHECK:STDOUT: import Core//prelude/...
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: file {
  101. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  102. // CHECK:STDOUT: .Core = imports.%Core
  103. // CHECK:STDOUT: .A = %A.decl
  104. // CHECK:STDOUT: .B = %B.decl
  105. // CHECK:STDOUT: .C = %C.decl
  106. // CHECK:STDOUT: .ConvertCToB = %ConvertCToB.decl
  107. // CHECK:STDOUT: .ConvertBToA = %ConvertBToA.decl
  108. // CHECK:STDOUT: .ConvertCToA = %ConvertCToA.decl
  109. // CHECK:STDOUT: .ConvertValue = %ConvertValue.decl
  110. // CHECK:STDOUT: .ConvertRef = %ConvertRef.decl
  111. // CHECK:STDOUT: .ConvertInit = %ConvertInit.decl
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %Core.import = import Core
  114. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  115. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  116. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  117. // CHECK:STDOUT: %ConvertCToB.decl: %ConvertCToB.type = fn_decl @ConvertCToB [template = constants.%ConvertCToB] {
  118. // CHECK:STDOUT: %p.patt: %ptr.019 = binding_pattern p
  119. // CHECK:STDOUT: %p.param_patt: %ptr.019 = value_param_pattern %p.patt, runtime_param0
  120. // CHECK:STDOUT: %return.patt: %ptr.e79 = return_slot_pattern
  121. // CHECK:STDOUT: %return.param_patt: %ptr.e79 = out_param_pattern %return.patt, runtime_param1
  122. // CHECK:STDOUT: } {
  123. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  124. // CHECK:STDOUT: %ptr.loc25_27: type = ptr_type %B [template = constants.%ptr.e79]
  125. // CHECK:STDOUT: %p.param: %ptr.019 = value_param runtime_param0
  126. // CHECK:STDOUT: %.loc25_20: type = splice_block %ptr.loc25_20 [template = constants.%ptr.019] {
  127. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  128. // CHECK:STDOUT: %ptr.loc25_20: type = ptr_type %C [template = constants.%ptr.019]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %p: %ptr.019 = bind_name p, %p.param
  131. // CHECK:STDOUT: %return.param: ref %ptr.e79 = out_param runtime_param1
  132. // CHECK:STDOUT: %return: ref %ptr.e79 = return_slot %return.param
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT: %ConvertBToA.decl: %ConvertBToA.type = fn_decl @ConvertBToA [template = constants.%ConvertBToA] {
  135. // CHECK:STDOUT: %p.patt: %ptr.e79 = binding_pattern p
  136. // CHECK:STDOUT: %p.param_patt: %ptr.e79 = value_param_pattern %p.patt, runtime_param0
  137. // CHECK:STDOUT: %return.patt: %ptr.6db = return_slot_pattern
  138. // CHECK:STDOUT: %return.param_patt: %ptr.6db = out_param_pattern %return.patt, runtime_param1
  139. // CHECK:STDOUT: } {
  140. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  141. // CHECK:STDOUT: %ptr.loc26_27: type = ptr_type %A [template = constants.%ptr.6db]
  142. // CHECK:STDOUT: %p.param: %ptr.e79 = value_param runtime_param0
  143. // CHECK:STDOUT: %.loc26_20: type = splice_block %ptr.loc26_20 [template = constants.%ptr.e79] {
  144. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  145. // CHECK:STDOUT: %ptr.loc26_20: type = ptr_type %B [template = constants.%ptr.e79]
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %p: %ptr.e79 = bind_name p, %p.param
  148. // CHECK:STDOUT: %return.param: ref %ptr.6db = out_param runtime_param1
  149. // CHECK:STDOUT: %return: ref %ptr.6db = return_slot %return.param
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT: %ConvertCToA.decl: %ConvertCToA.type = fn_decl @ConvertCToA [template = constants.%ConvertCToA] {
  152. // CHECK:STDOUT: %p.patt: %ptr.019 = binding_pattern p
  153. // CHECK:STDOUT: %p.param_patt: %ptr.019 = value_param_pattern %p.patt, runtime_param0
  154. // CHECK:STDOUT: %return.patt: %ptr.6db = return_slot_pattern
  155. // CHECK:STDOUT: %return.param_patt: %ptr.6db = out_param_pattern %return.patt, runtime_param1
  156. // CHECK:STDOUT: } {
  157. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  158. // CHECK:STDOUT: %ptr.loc27_27: type = ptr_type %A [template = constants.%ptr.6db]
  159. // CHECK:STDOUT: %p.param: %ptr.019 = value_param runtime_param0
  160. // CHECK:STDOUT: %.loc27_20: type = splice_block %ptr.loc27_20 [template = constants.%ptr.019] {
  161. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  162. // CHECK:STDOUT: %ptr.loc27_20: type = ptr_type %C [template = constants.%ptr.019]
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT: %p: %ptr.019 = bind_name p, %p.param
  165. // CHECK:STDOUT: %return.param: ref %ptr.6db = out_param runtime_param1
  166. // CHECK:STDOUT: %return: ref %ptr.6db = return_slot %return.param
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: %ConvertValue.decl: %ConvertValue.type = fn_decl @ConvertValue [template = constants.%ConvertValue] {
  169. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  170. // CHECK:STDOUT: %c.param_patt: %C = value_param_pattern %c.patt, runtime_param0
  171. // CHECK:STDOUT: } {
  172. // CHECK:STDOUT: %c.param: %C = value_param runtime_param0
  173. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  174. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT: %ConvertRef.decl: %ConvertRef.type = fn_decl @ConvertRef [template = constants.%ConvertRef] {
  177. // CHECK:STDOUT: %c.patt: %ptr.019 = binding_pattern c
  178. // CHECK:STDOUT: %c.param_patt: %ptr.019 = value_param_pattern %c.patt, runtime_param0
  179. // CHECK:STDOUT: %return.patt: %ptr.6db = return_slot_pattern
  180. // CHECK:STDOUT: %return.param_patt: %ptr.6db = out_param_pattern %return.patt, runtime_param1
  181. // CHECK:STDOUT: } {
  182. // CHECK:STDOUT: %A.ref.loc33: type = name_ref A, file.%A.decl [template = constants.%A]
  183. // CHECK:STDOUT: %ptr.loc33_26: type = ptr_type %A [template = constants.%ptr.6db]
  184. // CHECK:STDOUT: %c.param: %ptr.019 = value_param runtime_param0
  185. // CHECK:STDOUT: %.loc33: type = splice_block %ptr.loc33_19 [template = constants.%ptr.019] {
  186. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  187. // CHECK:STDOUT: %ptr.loc33_19: type = ptr_type %C [template = constants.%ptr.019]
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT: %c: %ptr.019 = bind_name c, %c.param
  190. // CHECK:STDOUT: %return.param: ref %ptr.6db = out_param runtime_param1
  191. // CHECK:STDOUT: %return: ref %ptr.6db = return_slot %return.param
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT: %ConvertInit.decl: %ConvertInit.type = fn_decl @ConvertInit [template = constants.%ConvertInit] {} {}
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: class @A {
  197. // CHECK:STDOUT: %.loc12_8: %A.elem = field_decl a, element0 [template]
  198. // CHECK:STDOUT: name_binding_decl {
  199. // CHECK:STDOUT: %.loc12_3: %A.elem = var_pattern %.loc12_8
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT: %.var: ref %A.elem = var <invalid>
  202. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a.ba9 [template = constants.%complete_type.fd7]
  203. // CHECK:STDOUT: complete_type_witness = %complete_type
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: !members:
  206. // CHECK:STDOUT: .Self = constants.%A
  207. // CHECK:STDOUT: .a = %.loc12_8
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: class @B {
  211. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  212. // CHECK:STDOUT: %.loc16: %B.elem.e38 = base_decl %A.ref, element0 [template]
  213. // CHECK:STDOUT: %.loc17_8: %B.elem.5c3 = field_decl b, element1 [template]
  214. // CHECK:STDOUT: name_binding_decl {
  215. // CHECK:STDOUT: %.loc17_3: %B.elem.5c3 = var_pattern %.loc17_8
  216. // CHECK:STDOUT: }
  217. // CHECK:STDOUT: %.var: ref %B.elem.5c3 = var <invalid>
  218. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base.b.b44 [template = constants.%complete_type.725]
  219. // CHECK:STDOUT: complete_type_witness = %complete_type
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: !members:
  222. // CHECK:STDOUT: .Self = constants.%B
  223. // CHECK:STDOUT: .base = %.loc16
  224. // CHECK:STDOUT: .b = %.loc17_8
  225. // CHECK:STDOUT: extend %A.ref
  226. // CHECK:STDOUT: }
  227. // CHECK:STDOUT:
  228. // CHECK:STDOUT: class @C {
  229. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  230. // CHECK:STDOUT: %.loc21: %C.elem.f0c = base_decl %B.ref, element0 [template]
  231. // CHECK:STDOUT: %.loc22_8: %C.elem.646 = field_decl c, element1 [template]
  232. // CHECK:STDOUT: name_binding_decl {
  233. // CHECK:STDOUT: %.loc22_3: %C.elem.646 = var_pattern %.loc22_8
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT: %.var: ref %C.elem.646 = var <invalid>
  236. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base.c.8e2 [template = constants.%complete_type.58a]
  237. // CHECK:STDOUT: complete_type_witness = %complete_type
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: !members:
  240. // CHECK:STDOUT: .Self = constants.%C
  241. // CHECK:STDOUT: .base = %.loc21
  242. // CHECK:STDOUT: .c = %.loc22_8
  243. // CHECK:STDOUT: extend %B.ref
  244. // CHECK:STDOUT: }
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: fn @ConvertCToB(%p.param_patt: %ptr.019) -> %ptr.e79 {
  247. // CHECK:STDOUT: !entry:
  248. // CHECK:STDOUT: %p.ref: %ptr.019 = name_ref p, %p
  249. // CHECK:STDOUT: %.loc25_39.1: ref %C = deref %p.ref
  250. // CHECK:STDOUT: %.loc25_39.2: ref %B = class_element_access %.loc25_39.1, element0
  251. // CHECK:STDOUT: %addr: %ptr.e79 = addr_of %.loc25_39.2
  252. // CHECK:STDOUT: %.loc25_39.3: %ptr.e79 = converted %p.ref, %addr
  253. // CHECK:STDOUT: return %.loc25_39.3
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: fn @ConvertBToA(%p.param_patt: %ptr.e79) -> %ptr.6db {
  257. // CHECK:STDOUT: !entry:
  258. // CHECK:STDOUT: %p.ref: %ptr.e79 = name_ref p, %p
  259. // CHECK:STDOUT: %.loc26_39.1: ref %B = deref %p.ref
  260. // CHECK:STDOUT: %.loc26_39.2: ref %A = class_element_access %.loc26_39.1, element0
  261. // CHECK:STDOUT: %addr: %ptr.6db = addr_of %.loc26_39.2
  262. // CHECK:STDOUT: %.loc26_39.3: %ptr.6db = converted %p.ref, %addr
  263. // CHECK:STDOUT: return %.loc26_39.3
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: fn @ConvertCToA(%p.param_patt: %ptr.019) -> %ptr.6db {
  267. // CHECK:STDOUT: !entry:
  268. // CHECK:STDOUT: %p.ref: %ptr.019 = name_ref p, %p
  269. // CHECK:STDOUT: %.loc27_39.1: ref %C = deref %p.ref
  270. // CHECK:STDOUT: %.loc27_39.2: ref %B = class_element_access %.loc27_39.1, element0
  271. // CHECK:STDOUT: %.loc27_39.3: ref %A = class_element_access %.loc27_39.2, element0
  272. // CHECK:STDOUT: %addr: %ptr.6db = addr_of %.loc27_39.3
  273. // CHECK:STDOUT: %.loc27_39.4: %ptr.6db = converted %p.ref, %addr
  274. // CHECK:STDOUT: return %.loc27_39.4
  275. // CHECK:STDOUT: }
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: fn @ConvertValue(%c.param_patt: %C) {
  278. // CHECK:STDOUT: !entry:
  279. // CHECK:STDOUT: name_binding_decl {
  280. // CHECK:STDOUT: %a.patt: %A = binding_pattern a
  281. // CHECK:STDOUT: }
  282. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  283. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  284. // CHECK:STDOUT: %.loc30_14.1: ref %B = class_element_access %c.ref, element0
  285. // CHECK:STDOUT: %.loc30_14.2: ref %A = class_element_access %.loc30_14.1, element0
  286. // CHECK:STDOUT: %.loc30_14.3: ref %A = converted %c.ref, %.loc30_14.2
  287. // CHECK:STDOUT: %a: ref %A = bind_name a, %.loc30_14.3
  288. // CHECK:STDOUT: return
  289. // CHECK:STDOUT: }
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: fn @ConvertRef(%c.param_patt: %ptr.019) -> %ptr.6db {
  292. // CHECK:STDOUT: !entry:
  293. // CHECK:STDOUT: %c.ref: %ptr.019 = name_ref c, %c
  294. // CHECK:STDOUT: %.loc34_12: ref %C = deref %c.ref
  295. // CHECK:STDOUT: %A.ref.loc34: type = name_ref A, file.%A.decl [template = constants.%A]
  296. // CHECK:STDOUT: %.loc34_15.1: ref %B = class_element_access %.loc34_12, element0
  297. // CHECK:STDOUT: %.loc34_15.2: ref %A = class_element_access %.loc34_15.1, element0
  298. // CHECK:STDOUT: %.loc34_15.3: ref %A = converted %.loc34_12, %.loc34_15.2
  299. // CHECK:STDOUT: %addr: %ptr.6db = addr_of %.loc34_15.3
  300. // CHECK:STDOUT: return %addr
  301. // CHECK:STDOUT: }
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: fn @ConvertInit() {
  304. // CHECK:STDOUT: !entry:
  305. // CHECK:STDOUT: name_binding_decl {
  306. // CHECK:STDOUT: %a.patt: %A = binding_pattern a
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  309. // CHECK:STDOUT: %.loc38_39.1: %struct_type.a.a6c = struct_literal (%int_1)
  310. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  311. // CHECK:STDOUT: %.loc38_48.1: %struct_type.base.b.bf0 = struct_literal (%.loc38_39.1, %int_2)
  312. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3.1ba]
  313. // CHECK:STDOUT: %.loc38_57.1: %struct_type.base.c.136 = struct_literal (%.loc38_48.1, %int_3)
  314. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  315. // CHECK:STDOUT: %impl.elem0.loc38_39: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  316. // CHECK:STDOUT: %Convert.bound.loc38_39: <bound method> = bound_method %int_1, %impl.elem0.loc38_39 [template = constants.%Convert.bound.ab5]
  317. // CHECK:STDOUT: %Convert.specific_fn.loc38_39: <specific function> = specific_function %Convert.bound.loc38_39, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
  318. // CHECK:STDOUT: %int.convert_checked.loc38_39: init %i32 = call %Convert.specific_fn.loc38_39(%int_1) [template = constants.%int_1.5d2]
  319. // CHECK:STDOUT: %.loc38_39.2: init %i32 = converted %int_1, %int.convert_checked.loc38_39 [template = constants.%int_1.5d2]
  320. // CHECK:STDOUT: %.loc38_57.2: ref %C = temporary_storage
  321. // CHECK:STDOUT: %.loc38_57.3: ref %B = class_element_access %.loc38_57.2, element0
  322. // CHECK:STDOUT: %.loc38_48.2: ref %A = class_element_access %.loc38_57.3, element0
  323. // CHECK:STDOUT: %.loc38_39.3: ref %i32 = class_element_access %.loc38_48.2, element0
  324. // CHECK:STDOUT: %.loc38_39.4: init %i32 = initialize_from %.loc38_39.2 to %.loc38_39.3 [template = constants.%int_1.5d2]
  325. // CHECK:STDOUT: %.loc38_39.5: init %A = class_init (%.loc38_39.4), %.loc38_48.2 [template = constants.%A.val]
  326. // CHECK:STDOUT: %.loc38_48.3: init %A = converted %.loc38_39.1, %.loc38_39.5 [template = constants.%A.val]
  327. // CHECK:STDOUT: %impl.elem0.loc38_48: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  328. // CHECK:STDOUT: %Convert.bound.loc38_48: <bound method> = bound_method %int_2, %impl.elem0.loc38_48 [template = constants.%Convert.bound.ef9]
  329. // CHECK:STDOUT: %Convert.specific_fn.loc38_48: <specific function> = specific_function %Convert.bound.loc38_48, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.787]
  330. // CHECK:STDOUT: %int.convert_checked.loc38_48: init %i32 = call %Convert.specific_fn.loc38_48(%int_2) [template = constants.%int_2.ef8]
  331. // CHECK:STDOUT: %.loc38_48.4: init %i32 = converted %int_2, %int.convert_checked.loc38_48 [template = constants.%int_2.ef8]
  332. // CHECK:STDOUT: %.loc38_48.5: ref %i32 = class_element_access %.loc38_57.3, element1
  333. // CHECK:STDOUT: %.loc38_48.6: init %i32 = initialize_from %.loc38_48.4 to %.loc38_48.5 [template = constants.%int_2.ef8]
  334. // CHECK:STDOUT: %.loc38_48.7: init %B = class_init (%.loc38_48.3, %.loc38_48.6), %.loc38_57.3 [template = constants.%B.val]
  335. // CHECK:STDOUT: %.loc38_57.4: init %B = converted %.loc38_48.1, %.loc38_48.7 [template = constants.%B.val]
  336. // CHECK:STDOUT: %impl.elem0.loc38_57: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  337. // CHECK:STDOUT: %Convert.bound.loc38_57: <bound method> = bound_method %int_3, %impl.elem0.loc38_57 [template = constants.%Convert.bound.b30]
  338. // CHECK:STDOUT: %Convert.specific_fn.loc38_57: <specific function> = specific_function %Convert.bound.loc38_57, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.b42]
  339. // CHECK:STDOUT: %int.convert_checked.loc38_57: init %i32 = call %Convert.specific_fn.loc38_57(%int_3) [template = constants.%int_3.822]
  340. // CHECK:STDOUT: %.loc38_57.5: init %i32 = converted %int_3, %int.convert_checked.loc38_57 [template = constants.%int_3.822]
  341. // CHECK:STDOUT: %.loc38_57.6: ref %i32 = class_element_access %.loc38_57.2, element1
  342. // CHECK:STDOUT: %.loc38_57.7: init %i32 = initialize_from %.loc38_57.5 to %.loc38_57.6 [template = constants.%int_3.822]
  343. // CHECK:STDOUT: %.loc38_57.8: init %C = class_init (%.loc38_57.4, %.loc38_57.7), %.loc38_57.2 [template = constants.%C.val]
  344. // CHECK:STDOUT: %.loc38_57.9: ref %C = temporary %.loc38_57.2, %.loc38_57.8
  345. // CHECK:STDOUT: %.loc38_59.1: ref %C = converted %.loc38_57.1, %.loc38_57.9
  346. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  347. // CHECK:STDOUT: %.loc38_59.2: ref %B = class_element_access %.loc38_59.1, element0
  348. // CHECK:STDOUT: %.loc38_59.3: ref %A = class_element_access %.loc38_59.2, element0
  349. // CHECK:STDOUT: %.loc38_59.4: ref %A = converted %.loc38_59.1, %.loc38_59.3
  350. // CHECK:STDOUT: %a: ref %A = bind_name a, %.loc38_59.4
  351. // CHECK:STDOUT: return
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT: