method.carbon 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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/method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/method.carbon
  10. class Class {
  11. fn F[self: Self]() -> i32;
  12. fn G[addr self: Self*]() -> i32;
  13. alias A = F;
  14. var k: i32;
  15. }
  16. fn Class.F[self: Self]() -> i32 {
  17. return self.k;
  18. }
  19. fn Call(c: Class) -> i32 {
  20. // TODO: The sem-ir for this call doesn't distinguish the `self` argument from
  21. // the explicit arguments.
  22. return c.F();
  23. }
  24. fn CallAlias(c: Class) -> i32 {
  25. return c.A();
  26. }
  27. fn CallOnConstBoundMethod() -> i32 {
  28. return ({.k = 1} as Class).F();
  29. }
  30. fn CallWithAddr() -> i32 {
  31. var c: Class;
  32. return c.G();
  33. }
  34. fn CallFThroughPointer(p: Class*) -> i32 {
  35. return (*p).F();
  36. }
  37. fn CallGThroughPointer(p: Class*) -> i32 {
  38. return (*p).G();
  39. }
  40. fn Make() -> Class;
  41. fn CallFOnInitializingExpr() -> i32 {
  42. return Make().F();
  43. }
  44. fn CallGOnInitializingExpr() -> i32 {
  45. return Make().G();
  46. }
  47. // CHECK:STDOUT: --- method.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  51. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  52. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  53. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  54. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  55. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  56. // CHECK:STDOUT: %.2: type = ptr_type %Class [template]
  57. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  58. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  59. // CHECK:STDOUT: %.3: type = unbound_element_type %Class, i32 [template]
  60. // CHECK:STDOUT: %.4: type = struct_type {.k: i32} [template]
  61. // CHECK:STDOUT: %.5: type = ptr_type %.4 [template]
  62. // CHECK:STDOUT: %Call.type: type = fn_type @Call [template]
  63. // CHECK:STDOUT: %Call: %Call.type = struct_value () [template]
  64. // CHECK:STDOUT: %CallAlias.type: type = fn_type @CallAlias [template]
  65. // CHECK:STDOUT: %CallAlias: %CallAlias.type = struct_value () [template]
  66. // CHECK:STDOUT: %CallOnConstBoundMethod.type: type = fn_type @CallOnConstBoundMethod [template]
  67. // CHECK:STDOUT: %CallOnConstBoundMethod: %CallOnConstBoundMethod.type = struct_value () [template]
  68. // CHECK:STDOUT: %.6: i32 = int_literal 1 [template]
  69. // CHECK:STDOUT: %struct: %Class = struct_value (%.6) [template]
  70. // CHECK:STDOUT: %CallWithAddr.type: type = fn_type @CallWithAddr [template]
  71. // CHECK:STDOUT: %CallWithAddr: %CallWithAddr.type = struct_value () [template]
  72. // CHECK:STDOUT: %CallFThroughPointer.type: type = fn_type @CallFThroughPointer [template]
  73. // CHECK:STDOUT: %CallFThroughPointer: %CallFThroughPointer.type = struct_value () [template]
  74. // CHECK:STDOUT: %CallGThroughPointer.type: type = fn_type @CallGThroughPointer [template]
  75. // CHECK:STDOUT: %CallGThroughPointer: %CallGThroughPointer.type = struct_value () [template]
  76. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  77. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  78. // CHECK:STDOUT: %CallFOnInitializingExpr.type: type = fn_type @CallFOnInitializingExpr [template]
  79. // CHECK:STDOUT: %CallFOnInitializingExpr: %CallFOnInitializingExpr.type = struct_value () [template]
  80. // CHECK:STDOUT: %CallGOnInitializingExpr.type: type = fn_type @CallGOnInitializingExpr [template]
  81. // CHECK:STDOUT: %CallGOnInitializingExpr: %CallGOnInitializingExpr.type = struct_value () [template]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: file {
  85. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  86. // CHECK:STDOUT: .Core = %Core
  87. // CHECK:STDOUT: .Class = %Class.decl
  88. // CHECK:STDOUT: .Call = %Call.decl
  89. // CHECK:STDOUT: .CallAlias = %CallAlias.decl
  90. // CHECK:STDOUT: .CallOnConstBoundMethod = %CallOnConstBoundMethod.decl
  91. // CHECK:STDOUT: .CallWithAddr = %CallWithAddr.decl
  92. // CHECK:STDOUT: .CallFThroughPointer = %CallFThroughPointer.decl
  93. // CHECK:STDOUT: .CallGThroughPointer = %CallGThroughPointer.decl
  94. // CHECK:STDOUT: .Make = %Make.decl
  95. // CHECK:STDOUT: .CallFOnInitializingExpr = %CallFOnInitializingExpr.decl
  96. // CHECK:STDOUT: .CallGOnInitializingExpr = %CallGOnInitializingExpr.decl
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  99. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  100. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  101. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  102. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  103. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  104. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  105. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Class [template = constants.%Class]
  106. // CHECK:STDOUT: %self.loc20_12.1: %Class = param self
  107. // CHECK:STDOUT: @F.%self: %Class = bind_name self, %self.loc20_12.1
  108. // CHECK:STDOUT: %int.make_type_32.loc20: init type = call constants.%Int32() [template = i32]
  109. // CHECK:STDOUT: %.loc20_29.1: type = value_of_initializer %int.make_type_32.loc20 [template = i32]
  110. // CHECK:STDOUT: %.loc20_29.2: type = converted %int.make_type_32.loc20, %.loc20_29.1 [template = i32]
  111. // CHECK:STDOUT: @F.%return: ref i32 = var <return slot>
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  114. // CHECK:STDOUT: %Call.decl: %Call.type = fn_decl @Call [template = constants.%Call] {
  115. // CHECK:STDOUT: %Class.ref.loc24: type = name_ref Class, %Class.decl [template = constants.%Class]
  116. // CHECK:STDOUT: %c.loc24_9.1: %Class = param c
  117. // CHECK:STDOUT: @Call.%c: %Class = bind_name c, %c.loc24_9.1
  118. // CHECK:STDOUT: %int.make_type_32.loc24: init type = call constants.%Int32() [template = i32]
  119. // CHECK:STDOUT: %.loc24_22.1: type = value_of_initializer %int.make_type_32.loc24 [template = i32]
  120. // CHECK:STDOUT: %.loc24_22.2: type = converted %int.make_type_32.loc24, %.loc24_22.1 [template = i32]
  121. // CHECK:STDOUT: @Call.%return: ref i32 = var <return slot>
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  124. // CHECK:STDOUT: %CallAlias.decl: %CallAlias.type = fn_decl @CallAlias [template = constants.%CallAlias] {
  125. // CHECK:STDOUT: %Class.ref.loc30: type = name_ref Class, %Class.decl [template = constants.%Class]
  126. // CHECK:STDOUT: %c.loc30_14.1: %Class = param c
  127. // CHECK:STDOUT: @CallAlias.%c: %Class = bind_name c, %c.loc30_14.1
  128. // CHECK:STDOUT: %int.make_type_32.loc30: init type = call constants.%Int32() [template = i32]
  129. // CHECK:STDOUT: %.loc30_27.1: type = value_of_initializer %int.make_type_32.loc30 [template = i32]
  130. // CHECK:STDOUT: %.loc30_27.2: type = converted %int.make_type_32.loc30, %.loc30_27.1 [template = i32]
  131. // CHECK:STDOUT: @CallAlias.%return: ref i32 = var <return slot>
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  134. // CHECK:STDOUT: %CallOnConstBoundMethod.decl: %CallOnConstBoundMethod.type = fn_decl @CallOnConstBoundMethod [template = constants.%CallOnConstBoundMethod] {
  135. // CHECK:STDOUT: %int.make_type_32.loc34: init type = call constants.%Int32() [template = i32]
  136. // CHECK:STDOUT: %.loc34_32.1: type = value_of_initializer %int.make_type_32.loc34 [template = i32]
  137. // CHECK:STDOUT: %.loc34_32.2: type = converted %int.make_type_32.loc34, %.loc34_32.1 [template = i32]
  138. // CHECK:STDOUT: @CallOnConstBoundMethod.%return: ref i32 = var <return slot>
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  141. // CHECK:STDOUT: %CallWithAddr.decl: %CallWithAddr.type = fn_decl @CallWithAddr [template = constants.%CallWithAddr] {
  142. // CHECK:STDOUT: %int.make_type_32.loc38: init type = call constants.%Int32() [template = i32]
  143. // CHECK:STDOUT: %.loc38_22.1: type = value_of_initializer %int.make_type_32.loc38 [template = i32]
  144. // CHECK:STDOUT: %.loc38_22.2: type = converted %int.make_type_32.loc38, %.loc38_22.1 [template = i32]
  145. // CHECK:STDOUT: @CallWithAddr.%return: ref i32 = var <return slot>
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %import_ref.9: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  148. // CHECK:STDOUT: %CallFThroughPointer.decl: %CallFThroughPointer.type = fn_decl @CallFThroughPointer [template = constants.%CallFThroughPointer] {
  149. // CHECK:STDOUT: %Class.ref.loc43: type = name_ref Class, %Class.decl [template = constants.%Class]
  150. // CHECK:STDOUT: %.loc43_32: type = ptr_type %Class [template = constants.%.2]
  151. // CHECK:STDOUT: %p.loc43_24.1: %.2 = param p
  152. // CHECK:STDOUT: @CallFThroughPointer.%p: %.2 = bind_name p, %p.loc43_24.1
  153. // CHECK:STDOUT: %int.make_type_32.loc43: init type = call constants.%Int32() [template = i32]
  154. // CHECK:STDOUT: %.loc43_38.1: type = value_of_initializer %int.make_type_32.loc43 [template = i32]
  155. // CHECK:STDOUT: %.loc43_38.2: type = converted %int.make_type_32.loc43, %.loc43_38.1 [template = i32]
  156. // CHECK:STDOUT: @CallFThroughPointer.%return: ref i32 = var <return slot>
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %import_ref.10: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  159. // CHECK:STDOUT: %CallGThroughPointer.decl: %CallGThroughPointer.type = fn_decl @CallGThroughPointer [template = constants.%CallGThroughPointer] {
  160. // CHECK:STDOUT: %Class.ref.loc47: type = name_ref Class, %Class.decl [template = constants.%Class]
  161. // CHECK:STDOUT: %.loc47_32: type = ptr_type %Class [template = constants.%.2]
  162. // CHECK:STDOUT: %p.loc47_24.1: %.2 = param p
  163. // CHECK:STDOUT: @CallGThroughPointer.%p: %.2 = bind_name p, %p.loc47_24.1
  164. // CHECK:STDOUT: %int.make_type_32.loc47: init type = call constants.%Int32() [template = i32]
  165. // CHECK:STDOUT: %.loc47_38.1: type = value_of_initializer %int.make_type_32.loc47 [template = i32]
  166. // CHECK:STDOUT: %.loc47_38.2: type = converted %int.make_type_32.loc47, %.loc47_38.1 [template = i32]
  167. // CHECK:STDOUT: @CallGThroughPointer.%return: ref i32 = var <return slot>
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  170. // CHECK:STDOUT: %Class.ref.loc51: type = name_ref Class, %Class.decl [template = constants.%Class]
  171. // CHECK:STDOUT: @Make.%return: ref %Class = var <return slot>
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT: %import_ref.11: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  174. // CHECK:STDOUT: %CallFOnInitializingExpr.decl: %CallFOnInitializingExpr.type = fn_decl @CallFOnInitializingExpr [template = constants.%CallFOnInitializingExpr] {
  175. // CHECK:STDOUT: %int.make_type_32.loc53: init type = call constants.%Int32() [template = i32]
  176. // CHECK:STDOUT: %.loc53_33.1: type = value_of_initializer %int.make_type_32.loc53 [template = i32]
  177. // CHECK:STDOUT: %.loc53_33.2: type = converted %int.make_type_32.loc53, %.loc53_33.1 [template = i32]
  178. // CHECK:STDOUT: @CallFOnInitializingExpr.%return: ref i32 = var <return slot>
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: %import_ref.12: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  181. // CHECK:STDOUT: %CallGOnInitializingExpr.decl: %CallGOnInitializingExpr.type = fn_decl @CallGOnInitializingExpr [template = constants.%CallGOnInitializingExpr] {
  182. // CHECK:STDOUT: %int.make_type_32.loc57: init type = call constants.%Int32() [template = i32]
  183. // CHECK:STDOUT: %.loc57_33.1: type = value_of_initializer %int.make_type_32.loc57 [template = i32]
  184. // CHECK:STDOUT: %.loc57_33.2: type = converted %int.make_type_32.loc57, %.loc57_33.1 [template = i32]
  185. // CHECK:STDOUT: @CallGOnInitializingExpr.%return: ref i32 = var <return slot>
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: class @Class {
  190. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  191. // CHECK:STDOUT: %Self.ref.loc12: type = name_ref Self, constants.%Class [template = constants.%Class]
  192. // CHECK:STDOUT: %self.loc12_8.1: %Class = param self
  193. // CHECK:STDOUT: %self.loc12_8.2: %Class = bind_name self, %self.loc12_8.1
  194. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  195. // CHECK:STDOUT: %.loc12_25.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  196. // CHECK:STDOUT: %.loc12_25.2: type = converted %int.make_type_32.loc12, %.loc12_25.1 [template = i32]
  197. // CHECK:STDOUT: %return.var.loc12: ref i32 = var <return slot>
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  200. // CHECK:STDOUT: %Self.ref.loc13: type = name_ref Self, constants.%Class [template = constants.%Class]
  201. // CHECK:STDOUT: %.loc13_23: type = ptr_type %Class [template = constants.%.2]
  202. // CHECK:STDOUT: %self.loc13_13.1: %.2 = param self
  203. // CHECK:STDOUT: %self.loc13_13.3: %.2 = bind_name self, %self.loc13_13.1
  204. // CHECK:STDOUT: %.loc13_8: %.2 = addr_pattern %self.loc13_13.3
  205. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  206. // CHECK:STDOUT: %.loc13_31.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  207. // CHECK:STDOUT: %.loc13_31.2: type = converted %int.make_type_32.loc13, %.loc13_31.1 [template = i32]
  208. // CHECK:STDOUT: %return.var.loc13: ref i32 = var <return slot>
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, %F.decl [template = constants.%F]
  211. // CHECK:STDOUT: %A: %F.type = bind_alias A, %F.decl [template = constants.%F]
  212. // CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
  213. // CHECK:STDOUT: %.loc17_10.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
  214. // CHECK:STDOUT: %.loc17_10.2: type = converted %int.make_type_32.loc17, %.loc17_10.1 [template = i32]
  215. // CHECK:STDOUT: %.loc17_8: %.3 = field_decl k, element0 [template]
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: !members:
  218. // CHECK:STDOUT: .Self = constants.%Class
  219. // CHECK:STDOUT: .F = %F.decl
  220. // CHECK:STDOUT: .G = %G.decl
  221. // CHECK:STDOUT: .A = %A
  222. // CHECK:STDOUT: .k = %.loc17_8
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: fn @F[%self: %Class]() -> i32 {
  228. // CHECK:STDOUT: !entry:
  229. // CHECK:STDOUT: %self.ref: %Class = name_ref self, %self
  230. // CHECK:STDOUT: %k.ref: %.3 = name_ref k, @Class.%.loc17_8 [template = @Class.%.loc17_8]
  231. // CHECK:STDOUT: %.loc21_14.1: ref i32 = class_element_access %self.ref, element0
  232. // CHECK:STDOUT: %.loc21_14.2: i32 = bind_value %.loc21_14.1
  233. // CHECK:STDOUT: return %.loc21_14.2
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: fn @G[addr @Class.%self.loc13_13.3: %.2]() -> i32;
  237. // CHECK:STDOUT:
  238. // CHECK:STDOUT: fn @Call(%c: %Class) -> i32 {
  239. // CHECK:STDOUT: !entry:
  240. // CHECK:STDOUT: %c.ref: %Class = name_ref c, %c
  241. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  242. // CHECK:STDOUT: %.loc27_11: <bound method> = bound_method %c.ref, %F.ref
  243. // CHECK:STDOUT: %F.call: init i32 = call %.loc27_11(%c.ref)
  244. // CHECK:STDOUT: %.loc27_15.1: i32 = value_of_initializer %F.call
  245. // CHECK:STDOUT: %.loc27_15.2: i32 = converted %F.call, %.loc27_15.1
  246. // CHECK:STDOUT: return %.loc27_15.2
  247. // CHECK:STDOUT: }
  248. // CHECK:STDOUT:
  249. // CHECK:STDOUT: fn @CallAlias(%c: %Class) -> i32 {
  250. // CHECK:STDOUT: !entry:
  251. // CHECK:STDOUT: %c.ref: %Class = name_ref c, %c
  252. // CHECK:STDOUT: %A.ref: %F.type = name_ref A, @Class.%A [template = constants.%F]
  253. // CHECK:STDOUT: %.loc31_11: <bound method> = bound_method %c.ref, %A.ref
  254. // CHECK:STDOUT: %F.call: init i32 = call %.loc31_11(%c.ref)
  255. // CHECK:STDOUT: %.loc31_15.1: i32 = value_of_initializer %F.call
  256. // CHECK:STDOUT: %.loc31_15.2: i32 = converted %F.call, %.loc31_15.1
  257. // CHECK:STDOUT: return %.loc31_15.2
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: fn @CallOnConstBoundMethod() -> i32 {
  261. // CHECK:STDOUT: !entry:
  262. // CHECK:STDOUT: %.loc35_17: i32 = int_literal 1 [template = constants.%.6]
  263. // CHECK:STDOUT: %.loc35_18.1: %.4 = struct_literal (%.loc35_17)
  264. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  265. // CHECK:STDOUT: %.loc35_18.2: ref %Class = temporary_storage
  266. // CHECK:STDOUT: %.loc35_18.3: ref i32 = class_element_access %.loc35_18.2, element0
  267. // CHECK:STDOUT: %.loc35_18.4: init i32 = initialize_from %.loc35_17 to %.loc35_18.3 [template = constants.%.6]
  268. // CHECK:STDOUT: %.loc35_18.5: init %Class = class_init (%.loc35_18.4), %.loc35_18.2 [template = constants.%struct]
  269. // CHECK:STDOUT: %.loc35_18.6: ref %Class = temporary %.loc35_18.2, %.loc35_18.5
  270. // CHECK:STDOUT: %.loc35_20.1: ref %Class = converted %.loc35_18.1, %.loc35_18.6
  271. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  272. // CHECK:STDOUT: %.loc35_29: <bound method> = bound_method %.loc35_20.1, %F.ref
  273. // CHECK:STDOUT: %.loc35_20.2: %Class = bind_value %.loc35_20.1
  274. // CHECK:STDOUT: %F.call: init i32 = call %.loc35_29(%.loc35_20.2)
  275. // CHECK:STDOUT: %.loc35_33.1: i32 = value_of_initializer %F.call
  276. // CHECK:STDOUT: %.loc35_33.2: i32 = converted %F.call, %.loc35_33.1
  277. // CHECK:STDOUT: return %.loc35_33.2
  278. // CHECK:STDOUT: }
  279. // CHECK:STDOUT:
  280. // CHECK:STDOUT: fn @CallWithAddr() -> i32 {
  281. // CHECK:STDOUT: !entry:
  282. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  283. // CHECK:STDOUT: %c.var: ref %Class = var c
  284. // CHECK:STDOUT: %c: ref %Class = bind_name c, %c.var
  285. // CHECK:STDOUT: %c.ref: ref %Class = name_ref c, %c
  286. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, @Class.%G.decl [template = constants.%G]
  287. // CHECK:STDOUT: %.loc40_11: <bound method> = bound_method %c.ref, %G.ref
  288. // CHECK:STDOUT: %.loc40_10: %.2 = addr_of %c.ref
  289. // CHECK:STDOUT: %G.call: init i32 = call %.loc40_11(%.loc40_10)
  290. // CHECK:STDOUT: %.loc40_15.1: i32 = value_of_initializer %G.call
  291. // CHECK:STDOUT: %.loc40_15.2: i32 = converted %G.call, %.loc40_15.1
  292. // CHECK:STDOUT: return %.loc40_15.2
  293. // CHECK:STDOUT: }
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: fn @CallFThroughPointer(%p: %.2) -> i32 {
  296. // CHECK:STDOUT: !entry:
  297. // CHECK:STDOUT: %p.ref: %.2 = name_ref p, %p
  298. // CHECK:STDOUT: %.loc44_11.1: ref %Class = deref %p.ref
  299. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  300. // CHECK:STDOUT: %.loc44_14: <bound method> = bound_method %.loc44_11.1, %F.ref
  301. // CHECK:STDOUT: %.loc44_11.2: %Class = bind_value %.loc44_11.1
  302. // CHECK:STDOUT: %F.call: init i32 = call %.loc44_14(%.loc44_11.2)
  303. // CHECK:STDOUT: %.loc44_18.1: i32 = value_of_initializer %F.call
  304. // CHECK:STDOUT: %.loc44_18.2: i32 = converted %F.call, %.loc44_18.1
  305. // CHECK:STDOUT: return %.loc44_18.2
  306. // CHECK:STDOUT: }
  307. // CHECK:STDOUT:
  308. // CHECK:STDOUT: fn @CallGThroughPointer(%p: %.2) -> i32 {
  309. // CHECK:STDOUT: !entry:
  310. // CHECK:STDOUT: %p.ref: %.2 = name_ref p, %p
  311. // CHECK:STDOUT: %.loc48_11.1: ref %Class = deref %p.ref
  312. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, @Class.%G.decl [template = constants.%G]
  313. // CHECK:STDOUT: %.loc48_14: <bound method> = bound_method %.loc48_11.1, %G.ref
  314. // CHECK:STDOUT: %.loc48_11.2: %.2 = addr_of %.loc48_11.1
  315. // CHECK:STDOUT: %G.call: init i32 = call %.loc48_14(%.loc48_11.2)
  316. // CHECK:STDOUT: %.loc48_18.1: i32 = value_of_initializer %G.call
  317. // CHECK:STDOUT: %.loc48_18.2: i32 = converted %G.call, %.loc48_18.1
  318. // CHECK:STDOUT: return %.loc48_18.2
  319. // CHECK:STDOUT: }
  320. // CHECK:STDOUT:
  321. // CHECK:STDOUT: fn @Make() -> %Class;
  322. // CHECK:STDOUT:
  323. // CHECK:STDOUT: fn @CallFOnInitializingExpr() -> i32 {
  324. // CHECK:STDOUT: !entry:
  325. // CHECK:STDOUT: %Make.ref: %Make.type = name_ref Make, file.%Make.decl [template = constants.%Make]
  326. // CHECK:STDOUT: %.loc54_14.1: ref %Class = temporary_storage
  327. // CHECK:STDOUT: %Make.call: init %Class = call %Make.ref() to %.loc54_14.1
  328. // CHECK:STDOUT: %.loc54_14.2: ref %Class = temporary %.loc54_14.1, %Make.call
  329. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @Class.%F.decl [template = constants.%F]
  330. // CHECK:STDOUT: %.loc54_16: <bound method> = bound_method %.loc54_14.2, %F.ref
  331. // CHECK:STDOUT: %.loc54_14.3: %Class = bind_value %.loc54_14.2
  332. // CHECK:STDOUT: %F.call: init i32 = call %.loc54_16(%.loc54_14.3)
  333. // CHECK:STDOUT: %.loc54_20.1: i32 = value_of_initializer %F.call
  334. // CHECK:STDOUT: %.loc54_20.2: i32 = converted %F.call, %.loc54_20.1
  335. // CHECK:STDOUT: return %.loc54_20.2
  336. // CHECK:STDOUT: }
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: fn @CallGOnInitializingExpr() -> i32 {
  339. // CHECK:STDOUT: !entry:
  340. // CHECK:STDOUT: %Make.ref: %Make.type = name_ref Make, file.%Make.decl [template = constants.%Make]
  341. // CHECK:STDOUT: %.loc58_14.1: ref %Class = temporary_storage
  342. // CHECK:STDOUT: %Make.call: init %Class = call %Make.ref() to %.loc58_14.1
  343. // CHECK:STDOUT: %.loc58_14.2: ref %Class = temporary %.loc58_14.1, %Make.call
  344. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, @Class.%G.decl [template = constants.%G]
  345. // CHECK:STDOUT: %.loc58_16: <bound method> = bound_method %.loc58_14.2, %G.ref
  346. // CHECK:STDOUT: %.loc58_14.3: %.2 = addr_of %.loc58_14.2
  347. // CHECK:STDOUT: %G.call: init i32 = call %.loc58_16(%.loc58_14.3)
  348. // CHECK:STDOUT: %.loc58_20.1: i32 = value_of_initializer %G.call
  349. // CHECK:STDOUT: %.loc58_20.2: i32 = converted %G.call, %.loc58_20.1
  350. // CHECK:STDOUT: return %.loc58_20.2
  351. // CHECK:STDOUT: }
  352. // CHECK:STDOUT: