base.carbon 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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/primitives.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/base.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/base.carbon
  12. // --- derived_to_base_conversion.h
  13. class Base {};
  14. class Derived : public Base {};
  15. // --- use_derived_to_base_conversion.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp library "derived_to_base_conversion.h";
  18. //@dump-sem-ir-begin
  19. fn ConvertPtr(d: Cpp.Derived*) -> Cpp.Base* {
  20. return d;
  21. }
  22. //@dump-sem-ir-end
  23. fn AcceptVal(b: Cpp.Base);
  24. //@dump-sem-ir-begin
  25. fn ConvertVal(d: Cpp.Derived) {
  26. AcceptVal(d);
  27. }
  28. //@dump-sem-ir-end
  29. // --- static_member.h
  30. class Base {
  31. public:
  32. static auto base_fn() -> void;
  33. };
  34. class Derived : public Base {
  35. public:
  36. static auto derived_fn() -> void;
  37. };
  38. // --- use_static_member.carbon
  39. library "[[@TEST_NAME]]";
  40. import Cpp library "static_member.h";
  41. fn MyF() {
  42. //@dump-sem-ir-begin
  43. Cpp.Base.base_fn();
  44. Cpp.Derived.base_fn();
  45. Cpp.Derived.derived_fn();
  46. //@dump-sem-ir-end
  47. }
  48. // --- base_field.h
  49. struct Base {
  50. int a;
  51. int b;
  52. };
  53. struct Derived : Base {
  54. int b;
  55. };
  56. // --- use_base_field.carbon
  57. library "[[@TEST_NAME]]";
  58. import Cpp library "base_field.h";
  59. fn AccessDirect(d: Cpp.Derived) -> i32 {
  60. //@dump-sem-ir-begin
  61. return d.a;
  62. //@dump-sem-ir-end
  63. }
  64. fn AccessQualified(d: Cpp.Derived) -> i32 {
  65. //@dump-sem-ir-begin
  66. return d.(Cpp.Base.b);
  67. //@dump-sem-ir-end
  68. }
  69. // --- base_method.h
  70. struct Base {
  71. void f() const;
  72. void g() const;
  73. };
  74. struct Derived : Base {
  75. void g() const;
  76. };
  77. // --- use_base_method.carbon
  78. library "[[@TEST_NAME]]";
  79. import Cpp library "base_method.h";
  80. fn CallDirect(d: Cpp.Derived) {
  81. //@dump-sem-ir-begin
  82. d.f();
  83. //@dump-sem-ir-end
  84. }
  85. fn CallQualified(d: Cpp.Derived) {
  86. //@dump-sem-ir-begin
  87. d.(Cpp.Base.g)();
  88. //@dump-sem-ir-end
  89. }
  90. // --- multiple_inheritance.h
  91. struct A { int a; };
  92. struct B { int b; };
  93. struct C : A, B {};
  94. // --- fail_todo_use_multiple_inheritance.carbon
  95. library "[[@TEST_NAME]]";
  96. import Cpp library "multiple_inheritance.h";
  97. fn ConvertA(p: Cpp.C*) -> Cpp.A* {
  98. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.C*` to `Cpp.A*` [ConversionFailure]
  99. // CHECK:STDERR: return p;
  100. // CHECK:STDERR: ^~~~~~~~~
  101. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.C*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  102. // CHECK:STDERR: return p;
  103. // CHECK:STDERR: ^~~~~~~~~
  104. // CHECK:STDERR:
  105. return p;
  106. }
  107. fn ConvertB(p: Cpp.C*) -> Cpp.B* {
  108. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.C*` to `Cpp.B*` [ConversionFailure]
  109. // CHECK:STDERR: return p;
  110. // CHECK:STDERR: ^~~~~~~~~
  111. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.C*` does not implement interface `Core.ImplicitAs(Cpp.B*)` [MissingImplInMemberAccessNote]
  112. // CHECK:STDERR: return p;
  113. // CHECK:STDERR: ^~~~~~~~~
  114. // CHECK:STDERR:
  115. return p;
  116. }
  117. // --- virtual_inheritance.h
  118. struct A { int a; };
  119. struct B : virtual A {};
  120. void UseB(B * _Nonnull p);
  121. // --- use_virtual_inheritance_incomplete.carbon
  122. library "[[@TEST_NAME]]";
  123. import Cpp library "virtual_inheritance.h";
  124. fn Convert(p: Cpp.B*) {
  125. // OK, doesn't require `Cpp.B` to be a complete type.
  126. Cpp.UseB(p);
  127. }
  128. // --- fail_todo_use_virtual_inheritance.carbon
  129. library "[[@TEST_NAME]]";
  130. // CHECK:STDERR: fail_todo_use_virtual_inheritance.carbon:[[@LINE+2]]:1: in import [InImport]
  131. // CHECK:STDERR: ./virtual_inheritance.h:3: error: semantics TODO: `class with virtual bases` [SemanticsTodo]
  132. import Cpp library "virtual_inheritance.h";
  133. fn Convert(p: Cpp.B*) -> Cpp.A* {
  134. // CHECK:STDERR: fail_todo_use_virtual_inheritance.carbon:[[@LINE+11]]:3: note: while completing C++ class type `Cpp.B` [InCppTypeCompletion]
  135. // CHECK:STDERR: return p;
  136. // CHECK:STDERR: ^~~~~~~~~
  137. // CHECK:STDERR:
  138. // CHECK:STDERR: fail_todo_use_virtual_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.B*` to `Cpp.A*` [ConversionFailure]
  139. // CHECK:STDERR: return p;
  140. // CHECK:STDERR: ^~~~~~~~~
  141. // CHECK:STDERR: fail_todo_use_virtual_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.B*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  142. // CHECK:STDERR: return p;
  143. // CHECK:STDERR: ^~~~~~~~~
  144. // CHECK:STDERR:
  145. return p;
  146. }
  147. // --- final.h
  148. struct A final {};
  149. // --- fail_derive_from_final.carbon
  150. library "[[@TEST_NAME]]";
  151. import Cpp library "final.h";
  152. class B {
  153. // CHECK:STDERR: fail_derive_from_final.carbon:[[@LINE+4]]:16: error: deriving from final type `A`; base type must be an `abstract` or `base` class [BaseIsFinal]
  154. // CHECK:STDERR: extend base: Cpp.A;
  155. // CHECK:STDERR: ^~~~~
  156. // CHECK:STDERR:
  157. extend base: Cpp.A;
  158. }
  159. // --- union.h
  160. union U {};
  161. // --- fail_derive_from_union.carbon
  162. library "[[@TEST_NAME]]";
  163. import Cpp library "union.h";
  164. class V {
  165. // CHECK:STDERR: fail_derive_from_union.carbon:[[@LINE+4]]:16: error: deriving from final type `U`; base type must be an `abstract` or `base` class [BaseIsFinal]
  166. // CHECK:STDERR: extend base: Cpp.U;
  167. // CHECK:STDERR: ^~~~~
  168. // CHECK:STDERR:
  169. extend base: Cpp.U;
  170. }
  171. // CHECK:STDOUT: --- use_derived_to_base_conversion.carbon
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: constants {
  174. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  175. // CHECK:STDOUT: %ptr.ddb: type = ptr_type %Derived [concrete]
  176. // CHECK:STDOUT: %pattern_type.5c8: type = pattern_type %ptr.ddb [concrete]
  177. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  178. // CHECK:STDOUT: %ptr.fb2: type = ptr_type %Base [concrete]
  179. // CHECK:STDOUT: %pattern_type.72a: type = pattern_type %ptr.fb2 [concrete]
  180. // CHECK:STDOUT: %ConvertPtr.type: type = fn_type @ConvertPtr [concrete]
  181. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  182. // CHECK:STDOUT: %ConvertPtr: %ConvertPtr.type = struct_value () [concrete]
  183. // CHECK:STDOUT: %AcceptVal.type: type = fn_type @AcceptVal [concrete]
  184. // CHECK:STDOUT: %AcceptVal: %AcceptVal.type = struct_value () [concrete]
  185. // CHECK:STDOUT: %pattern_type.5de: type = pattern_type %Derived [concrete]
  186. // CHECK:STDOUT: %ConvertVal.type: type = fn_type @ConvertVal [concrete]
  187. // CHECK:STDOUT: %ConvertVal: %ConvertVal.type = struct_value () [concrete]
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: imports {
  191. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  192. // CHECK:STDOUT: .Derived = %Derived.decl
  193. // CHECK:STDOUT: .Base = %Base.decl
  194. // CHECK:STDOUT: import Cpp//...
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  197. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: file {
  201. // CHECK:STDOUT: %ConvertPtr.decl: %ConvertPtr.type = fn_decl @ConvertPtr [concrete = constants.%ConvertPtr] {
  202. // CHECK:STDOUT: %d.patt: %pattern_type.5c8 = binding_pattern d [concrete]
  203. // CHECK:STDOUT: %d.param_patt: %pattern_type.5c8 = value_param_pattern %d.patt, call_param0 [concrete]
  204. // CHECK:STDOUT: %return.patt: %pattern_type.72a = return_slot_pattern [concrete]
  205. // CHECK:STDOUT: %return.param_patt: %pattern_type.72a = out_param_pattern %return.patt, call_param1 [concrete]
  206. // CHECK:STDOUT: } {
  207. // CHECK:STDOUT: %Cpp.ref.loc7_35: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  208. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  209. // CHECK:STDOUT: %ptr.loc7_43: type = ptr_type %Base.ref [concrete = constants.%ptr.fb2]
  210. // CHECK:STDOUT: %d.param: %ptr.ddb = value_param call_param0
  211. // CHECK:STDOUT: %.loc7: type = splice_block %ptr.loc7_29 [concrete = constants.%ptr.ddb] {
  212. // CHECK:STDOUT: %Cpp.ref.loc7_18: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  213. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  214. // CHECK:STDOUT: %ptr.loc7_29: type = ptr_type %Derived.ref [concrete = constants.%ptr.ddb]
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT: %d: %ptr.ddb = bind_name d, %d.param
  217. // CHECK:STDOUT: %return.param: ref %ptr.fb2 = out_param call_param1
  218. // CHECK:STDOUT: %return: ref %ptr.fb2 = return_slot %return.param
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT: %ConvertVal.decl: %ConvertVal.type = fn_decl @ConvertVal [concrete = constants.%ConvertVal] {
  221. // CHECK:STDOUT: %d.patt: %pattern_type.5de = binding_pattern d [concrete]
  222. // CHECK:STDOUT: %d.param_patt: %pattern_type.5de = value_param_pattern %d.patt, call_param0 [concrete]
  223. // CHECK:STDOUT: } {
  224. // CHECK:STDOUT: %d.param: %Derived = value_param call_param0
  225. // CHECK:STDOUT: %.loc15: type = splice_block %Derived.ref [concrete = constants.%Derived] {
  226. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  227. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  228. // CHECK:STDOUT: }
  229. // CHECK:STDOUT: %d: %Derived = bind_name d, %d.param
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: fn @ConvertPtr(%d.param: %ptr.ddb) -> %ptr.fb2 {
  234. // CHECK:STDOUT: !entry:
  235. // CHECK:STDOUT: %d.ref: %ptr.ddb = name_ref d, %d
  236. // CHECK:STDOUT: %.loc8_11.1: ref %Derived = deref %d.ref
  237. // CHECK:STDOUT: %.loc8_11.2: ref %Base = class_element_access %.loc8_11.1, element0
  238. // CHECK:STDOUT: %addr: %ptr.fb2 = addr_of %.loc8_11.2
  239. // CHECK:STDOUT: %.loc8_11.3: %ptr.fb2 = converted %d.ref, %addr
  240. // CHECK:STDOUT: return %.loc8_11.3
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: fn @ConvertVal(%d.param: %Derived) {
  244. // CHECK:STDOUT: !entry:
  245. // CHECK:STDOUT: %AcceptVal.ref: %AcceptVal.type = name_ref AcceptVal, file.%AcceptVal.decl [concrete = constants.%AcceptVal]
  246. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  247. // CHECK:STDOUT: %.loc16_13.1: ref %Base = class_element_access %d.ref, element0
  248. // CHECK:STDOUT: %.loc16_13.2: ref %Base = converted %d.ref, %.loc16_13.1
  249. // CHECK:STDOUT: %.loc16_13.3: %Base = bind_value %.loc16_13.2
  250. // CHECK:STDOUT: %AcceptVal.call: init %empty_tuple.type = call %AcceptVal.ref(%.loc16_13.3)
  251. // CHECK:STDOUT: return
  252. // CHECK:STDOUT: }
  253. // CHECK:STDOUT:
  254. // CHECK:STDOUT: --- use_static_member.carbon
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: constants {
  257. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  258. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  259. // CHECK:STDOUT: %Base.base_fn.type: type = fn_type @Base.base_fn [concrete]
  260. // CHECK:STDOUT: %Base.base_fn: %Base.base_fn.type = struct_value () [concrete]
  261. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  262. // CHECK:STDOUT: %Derived.derived_fn.type: type = fn_type @Derived.derived_fn [concrete]
  263. // CHECK:STDOUT: %Derived.derived_fn: %Derived.derived_fn.type = struct_value () [concrete]
  264. // CHECK:STDOUT: }
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: imports {
  267. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  268. // CHECK:STDOUT: .Base = %Base.decl
  269. // CHECK:STDOUT: .Derived = %Derived.decl
  270. // CHECK:STDOUT: import Cpp//...
  271. // CHECK:STDOUT: }
  272. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  273. // CHECK:STDOUT: %Base.base_fn.decl: %Base.base_fn.type = fn_decl @Base.base_fn [concrete = constants.%Base.base_fn] {} {}
  274. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  275. // CHECK:STDOUT: %Derived.derived_fn.decl: %Derived.derived_fn.type = fn_decl @Derived.derived_fn [concrete = constants.%Derived.derived_fn] {} {}
  276. // CHECK:STDOUT: }
  277. // CHECK:STDOUT:
  278. // CHECK:STDOUT: fn @MyF() {
  279. // CHECK:STDOUT: !entry:
  280. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  281. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  282. // CHECK:STDOUT: %base_fn.ref.loc8: %Base.base_fn.type = name_ref base_fn, imports.%Base.base_fn.decl [concrete = constants.%Base.base_fn]
  283. // CHECK:STDOUT: %Base.base_fn.call.loc8: init %empty_tuple.type = call %base_fn.ref.loc8()
  284. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  285. // CHECK:STDOUT: %Derived.ref.loc9: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  286. // CHECK:STDOUT: %base_fn.ref.loc9: %Base.base_fn.type = name_ref base_fn, imports.%Base.base_fn.decl [concrete = constants.%Base.base_fn]
  287. // CHECK:STDOUT: %Base.base_fn.call.loc9: init %empty_tuple.type = call %base_fn.ref.loc9()
  288. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  289. // CHECK:STDOUT: %Derived.ref.loc10: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  290. // CHECK:STDOUT: %derived_fn.ref: %Derived.derived_fn.type = name_ref derived_fn, imports.%Derived.derived_fn.decl [concrete = constants.%Derived.derived_fn]
  291. // CHECK:STDOUT: %Derived.derived_fn.call: init %empty_tuple.type = call %derived_fn.ref()
  292. // CHECK:STDOUT: <elided>
  293. // CHECK:STDOUT: }
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: --- use_base_field.carbon
  296. // CHECK:STDOUT:
  297. // CHECK:STDOUT: constants {
  298. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  299. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  300. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  301. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  302. // CHECK:STDOUT: %Base.elem: type = unbound_element_type %Base, %i32 [concrete]
  303. // CHECK:STDOUT: }
  304. // CHECK:STDOUT:
  305. // CHECK:STDOUT: imports {
  306. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  307. // CHECK:STDOUT: .Derived = %Derived.decl
  308. // CHECK:STDOUT: .Base = %Base.decl
  309. // CHECK:STDOUT: import Cpp//...
  310. // CHECK:STDOUT: }
  311. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  312. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  313. // CHECK:STDOUT: }
  314. // CHECK:STDOUT:
  315. // CHECK:STDOUT: fn @AccessDirect(%d.param: %Derived) -> %i32 {
  316. // CHECK:STDOUT: !entry:
  317. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  318. // CHECK:STDOUT: %a.ref: %Base.elem = name_ref a, @Base.%.1 [concrete = @Base.%.1]
  319. // CHECK:STDOUT: %.loc8_11.1: ref %Base = class_element_access %d.ref, element0
  320. // CHECK:STDOUT: %.loc8_11.2: ref %Base = converted %d.ref, %.loc8_11.1
  321. // CHECK:STDOUT: %.loc8_11.3: ref %i32 = class_element_access %.loc8_11.2, element0
  322. // CHECK:STDOUT: %.loc8_11.4: %i32 = bind_value %.loc8_11.3
  323. // CHECK:STDOUT: return %.loc8_11.4
  324. // CHECK:STDOUT: }
  325. // CHECK:STDOUT:
  326. // CHECK:STDOUT: fn @AccessQualified(%d.param: %Derived) -> %i32 {
  327. // CHECK:STDOUT: !entry:
  328. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  329. // CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  330. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  331. // CHECK:STDOUT: %b.ref: %Base.elem = name_ref b, @Base.%.2 [concrete = @Base.%.2]
  332. // CHECK:STDOUT: %.loc14_11.1: ref %Base = class_element_access %d.ref, element0
  333. // CHECK:STDOUT: %.loc14_11.2: ref %Base = converted %d.ref, %.loc14_11.1
  334. // CHECK:STDOUT: %.loc14_11.3: ref %i32 = class_element_access %.loc14_11.2, element1
  335. // CHECK:STDOUT: %.loc14_11.4: %i32 = bind_value %.loc14_11.3
  336. // CHECK:STDOUT: return %.loc14_11.4
  337. // CHECK:STDOUT: }
  338. // CHECK:STDOUT:
  339. // CHECK:STDOUT: --- use_base_method.carbon
  340. // CHECK:STDOUT:
  341. // CHECK:STDOUT: constants {
  342. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  343. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  344. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  345. // CHECK:STDOUT: %Base.f.type: type = fn_type @Base.f [concrete]
  346. // CHECK:STDOUT: %Base.f: %Base.f.type = struct_value () [concrete]
  347. // CHECK:STDOUT: %Base.g.type: type = fn_type @Base.g [concrete]
  348. // CHECK:STDOUT: %Base.g: %Base.g.type = struct_value () [concrete]
  349. // CHECK:STDOUT: }
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: imports {
  352. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  353. // CHECK:STDOUT: .Derived = %Derived.decl
  354. // CHECK:STDOUT: .Base = %Base.decl
  355. // CHECK:STDOUT: import Cpp//...
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  358. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  359. // CHECK:STDOUT: %Base.f.decl: %Base.f.type = fn_decl @Base.f [concrete = constants.%Base.f] {
  360. // CHECK:STDOUT: <elided>
  361. // CHECK:STDOUT: } {
  362. // CHECK:STDOUT: <elided>
  363. // CHECK:STDOUT: }
  364. // CHECK:STDOUT: %Base.g.decl: %Base.g.type = fn_decl @Base.g [concrete = constants.%Base.g] {
  365. // CHECK:STDOUT: <elided>
  366. // CHECK:STDOUT: } {
  367. // CHECK:STDOUT: <elided>
  368. // CHECK:STDOUT: }
  369. // CHECK:STDOUT: }
  370. // CHECK:STDOUT:
  371. // CHECK:STDOUT: fn @CallDirect(%d.param: %Derived) {
  372. // CHECK:STDOUT: !entry:
  373. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  374. // CHECK:STDOUT: %f.ref: %Base.f.type = name_ref f, imports.%Base.f.decl [concrete = constants.%Base.f]
  375. // CHECK:STDOUT: %Base.f.bound: <bound method> = bound_method %d.ref, %f.ref
  376. // CHECK:STDOUT: %.loc8_3.1: ref %Base = class_element_access %d.ref, element0
  377. // CHECK:STDOUT: %.loc8_3.2: ref %Base = converted %d.ref, %.loc8_3.1
  378. // CHECK:STDOUT: %.loc8_3.3: %Base = bind_value %.loc8_3.2
  379. // CHECK:STDOUT: %Base.f.call: init %empty_tuple.type = call %Base.f.bound(%.loc8_3.3)
  380. // CHECK:STDOUT: <elided>
  381. // CHECK:STDOUT: }
  382. // CHECK:STDOUT:
  383. // CHECK:STDOUT: fn @CallQualified(%d.param: %Derived) {
  384. // CHECK:STDOUT: !entry:
  385. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  386. // CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  387. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  388. // CHECK:STDOUT: %g.ref: %Base.g.type = name_ref g, imports.%Base.g.decl [concrete = constants.%Base.g]
  389. // CHECK:STDOUT: %Base.g.bound: <bound method> = bound_method %d.ref, %g.ref
  390. // CHECK:STDOUT: %.loc14_3.1: ref %Base = class_element_access %d.ref, element0
  391. // CHECK:STDOUT: %.loc14_3.2: ref %Base = converted %d.ref, %.loc14_3.1
  392. // CHECK:STDOUT: %.loc14_3.3: %Base = bind_value %.loc14_3.2
  393. // CHECK:STDOUT: %Base.g.call: init %empty_tuple.type = call %Base.g.bound(%.loc14_3.3)
  394. // CHECK:STDOUT: <elided>
  395. // CHECK:STDOUT: }
  396. // CHECK:STDOUT: