reference.carbon 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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. //
  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/function/reference.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/reference.carbon
  12. // ============================================================================
  13. // Lvalue reference as a parameter type
  14. // ============================================================================
  15. // --- lvalue_ref.h
  16. struct S {};
  17. struct T {};
  18. auto TakesLValue(S&) -> void;
  19. // --- call_lvalue_ref.carbon
  20. library "[[@TEST_NAME]]";
  21. import Cpp library "lvalue_ref.h";
  22. fn F() {
  23. //@dump-sem-ir-begin
  24. var s: Cpp.S = {};
  25. Cpp.TakesLValue(s);
  26. //@dump-sem-ir-end
  27. }
  28. // --- fail_lvalue_ref.carbon
  29. library "[[@TEST_NAME]]";
  30. import Cpp library "lvalue_ref.h";
  31. fn F() {
  32. //@dump-sem-ir-begin
  33. var v: Cpp.S;
  34. let s: Cpp.S = v;
  35. // CHECK:STDERR: fail_lvalue_ref.carbon:[[@LINE+8]]:20: error: no matching function for call to 'TakesLValue' [CppInteropParseError]
  36. // CHECK:STDERR: 18 | Cpp.TakesLValue(s);
  37. // CHECK:STDERR: | ^
  38. // CHECK:STDERR: fail_lvalue_ref.carbon:[[@LINE-9]]:10: in file included here [InCppInclude]
  39. // CHECK:STDERR: ./lvalue_ref.h:5:6: note: candidate function not viable: expects an lvalue for 1st argument [CppInteropParseNote]
  40. // CHECK:STDERR: 5 | auto TakesLValue(S&) -> void;
  41. // CHECK:STDERR: | ^ ~~
  42. // CHECK:STDERR:
  43. Cpp.TakesLValue(s);
  44. var t: Cpp.T;
  45. // CHECK:STDERR: fail_lvalue_ref.carbon:[[@LINE+8]]:20: error: no matching function for call to 'TakesLValue' [CppInteropParseError]
  46. // CHECK:STDERR: 29 | Cpp.TakesLValue(t);
  47. // CHECK:STDERR: | ^
  48. // CHECK:STDERR: fail_lvalue_ref.carbon:[[@LINE-20]]:10: in file included here [InCppInclude]
  49. // CHECK:STDERR: ./lvalue_ref.h:5:6: note: candidate function not viable: no known conversion from 'T' to 'S &' for 1st argument [CppInteropParseNote]
  50. // CHECK:STDERR: 5 | auto TakesLValue(S&) -> void;
  51. // CHECK:STDERR: | ^ ~~
  52. // CHECK:STDERR:
  53. Cpp.TakesLValue(t);
  54. var u: Cpp.S;
  55. // CHECK:STDERR: fail_lvalue_ref.carbon:[[@LINE+8]]:35: error: no matching function for call to 'TakesLValue' [CppInteropParseError]
  56. // CHECK:STDERR: 40 | Cpp.TakesLValue(u as const Cpp.S);
  57. // CHECK:STDERR: | ^
  58. // CHECK:STDERR: fail_lvalue_ref.carbon:[[@LINE-31]]:10: in file included here [InCppInclude]
  59. // CHECK:STDERR: ./lvalue_ref.h:5:6: note: candidate function not viable: 1st argument ('const S') would lose const qualifier [CppInteropParseNote]
  60. // CHECK:STDERR: 5 | auto TakesLValue(S&) -> void;
  61. // CHECK:STDERR: | ^ ~~
  62. // CHECK:STDERR:
  63. Cpp.TakesLValue(u as const Cpp.S);
  64. //@dump-sem-ir-end
  65. }
  66. // ============================================================================
  67. // Rvalue reference as a parameter type
  68. // ============================================================================
  69. // --- rvalue_ref.h
  70. struct S {};
  71. struct T {};
  72. auto TakesRValue(S&&) -> void;
  73. // --- call_rvalue_ref.carbon
  74. library "[[@TEST_NAME]]";
  75. import Cpp library "rvalue_ref.h";
  76. fn F() {
  77. //@dump-sem-ir-begin
  78. Cpp.TakesRValue({} as Cpp.S);
  79. //@dump-sem-ir-end
  80. }
  81. // --- todo_fail_value_arg_for_rvalue_ref.carbon
  82. library "[[@TEST_NAME]]";
  83. import Cpp library "rvalue_ref.h";
  84. fn F() {
  85. //@dump-sem-ir-begin
  86. // TODO: We should probably reject binding an rvalue reference to a value
  87. // expression. If we don't reject, we should instead force a copy to be made,
  88. // at least if the type has a pointer value representation, so that moving
  89. // from the reference doesn't alter tne original value.
  90. let s: Cpp.S = {};
  91. Cpp.TakesRValue(s);
  92. //@dump-sem-ir-end
  93. }
  94. // --- fail_rvalue_ref.carbon
  95. library "[[@TEST_NAME]]";
  96. import Cpp library "rvalue_ref.h";
  97. fn F() {
  98. //@dump-sem-ir-begin
  99. var s: Cpp.S;
  100. // CHECK:STDERR: fail_rvalue_ref.carbon:[[@LINE+8]]:20: error: no matching function for call to 'TakesRValue' [CppInteropParseError]
  101. // CHECK:STDERR: 17 | Cpp.TakesRValue(s);
  102. // CHECK:STDERR: | ^
  103. // CHECK:STDERR: fail_rvalue_ref.carbon:[[@LINE-8]]:10: in file included here [InCppInclude]
  104. // CHECK:STDERR: ./rvalue_ref.h:5:6: note: candidate function not viable: expects an rvalue for 1st argument [CppInteropParseNote]
  105. // CHECK:STDERR: 5 | auto TakesRValue(S&&) -> void;
  106. // CHECK:STDERR: | ^ ~~~
  107. // CHECK:STDERR:
  108. Cpp.TakesRValue(s);
  109. var t: Cpp.T;
  110. // CHECK:STDERR: fail_rvalue_ref.carbon:[[@LINE+8]]:20: error: no matching function for call to 'TakesRValue' [CppInteropParseError]
  111. // CHECK:STDERR: 28 | Cpp.TakesRValue(t);
  112. // CHECK:STDERR: | ^
  113. // CHECK:STDERR: fail_rvalue_ref.carbon:[[@LINE-19]]:10: in file included here [InCppInclude]
  114. // CHECK:STDERR: ./rvalue_ref.h:5:6: note: candidate function not viable: no known conversion from 'T' to 'S' for 1st argument [CppInteropParseNote]
  115. // CHECK:STDERR: 5 | auto TakesRValue(S&&) -> void;
  116. // CHECK:STDERR: | ^ ~~~
  117. // CHECK:STDERR:
  118. Cpp.TakesRValue(t);
  119. // CHECK:STDERR: fail_rvalue_ref.carbon:[[@LINE+8]]:47: error: no matching function for call to 'TakesRValue' [CppInteropParseError]
  120. // CHECK:STDERR: 38 | Cpp.TakesRValue(({} as Cpp.S) as const Cpp.S);
  121. // CHECK:STDERR: | ^
  122. // CHECK:STDERR: fail_rvalue_ref.carbon:[[@LINE-29]]:10: in file included here [InCppInclude]
  123. // CHECK:STDERR: ./rvalue_ref.h:5:6: note: candidate function not viable: 1st argument ('const S') would lose const qualifier [CppInteropParseNote]
  124. // CHECK:STDERR: 5 | auto TakesRValue(S&&) -> void;
  125. // CHECK:STDERR: | ^ ~~~
  126. // CHECK:STDERR:
  127. Cpp.TakesRValue(({} as Cpp.S) as const Cpp.S);
  128. //@dump-sem-ir-end
  129. }
  130. // ============================================================================
  131. // Const reference as a parameter type
  132. // ============================================================================
  133. // --- const_lvalue_ref.h
  134. struct S {};
  135. struct T {};
  136. auto TakesConstLValue(const S&) -> void;
  137. // --- call_const_lvalue_ref.carbon
  138. library "[[@TEST_NAME]]";
  139. import Cpp library "const_lvalue_ref.h";
  140. fn F() {
  141. //@dump-sem-ir-begin
  142. var s: Cpp.S = {};
  143. Cpp.TakesConstLValue(s as const Cpp.S);
  144. Cpp.TakesConstLValue(s);
  145. //@dump-sem-ir-end
  146. }
  147. // --- fail_const_lvalue_ref.carbon
  148. library "[[@TEST_NAME]]";
  149. import Cpp library "const_lvalue_ref.h";
  150. fn F() {
  151. //@dump-sem-ir-begin
  152. // TODO: Should this work? We could create a temporary. Overload resolution
  153. // accepts this but the Carbon-side call fails.
  154. // TODO: The diagnostic here is wrong; we're internally using `addr` but this
  155. // is not `addr self`.
  156. let s: Cpp.S = {};
  157. // CHECK:STDERR: fail_const_lvalue_ref.carbon:[[@LINE+5]]:24: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
  158. // CHECK:STDERR: Cpp.TakesConstLValue(s);
  159. // CHECK:STDERR: ^
  160. // CHECK:STDERR: fail_const_lvalue_ref.carbon: note: initializing function parameter [InCallToFunctionParam]
  161. // CHECK:STDERR:
  162. Cpp.TakesConstLValue(s);
  163. var t: Cpp.T;
  164. // CHECK:STDERR: fail_const_lvalue_ref.carbon:[[@LINE+8]]:25: error: no matching function for call to 'TakesConstLValue' [CppInteropParseError]
  165. // CHECK:STDERR: 29 | Cpp.TakesConstLValue(t);
  166. // CHECK:STDERR: | ^
  167. // CHECK:STDERR: fail_const_lvalue_ref.carbon:[[@LINE-20]]:10: in file included here [InCppInclude]
  168. // CHECK:STDERR: ./const_lvalue_ref.h:5:6: note: candidate function not viable: no known conversion from 'T' to 'const S' for 1st argument [CppInteropParseNote]
  169. // CHECK:STDERR: 5 | auto TakesConstLValue(const S&) -> void;
  170. // CHECK:STDERR: | ^ ~~~~~~~~
  171. // CHECK:STDERR:
  172. Cpp.TakesConstLValue(t);
  173. //@dump-sem-ir-end
  174. }
  175. // CHECK:STDOUT: --- call_lvalue_ref.carbon
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: constants {
  178. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  179. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  180. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  181. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  182. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  183. // CHECK:STDOUT: %.547: type = cpp_overload_set_type @TakesLValue [concrete]
  184. // CHECK:STDOUT: %empty_struct: %.547 = struct_value () [concrete]
  185. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  186. // CHECK:STDOUT: %TakesLValue__carbon_thunk.type: type = fn_type @TakesLValue__carbon_thunk [concrete]
  187. // CHECK:STDOUT: %TakesLValue__carbon_thunk: %TakesLValue__carbon_thunk.type = struct_value () [concrete]
  188. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  189. // CHECK:STDOUT: %facet_value: %type_where = facet_value %S, () [concrete]
  190. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  191. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: imports {
  195. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  196. // CHECK:STDOUT: .S = %S.decl
  197. // CHECK:STDOUT: .TakesLValue = %.a7f
  198. // CHECK:STDOUT: import Cpp//...
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  201. // CHECK:STDOUT: %.a7f: %.547 = cpp_overload_set_value @TakesLValue [concrete = constants.%empty_struct]
  202. // CHECK:STDOUT: %TakesLValue__carbon_thunk.decl: %TakesLValue__carbon_thunk.type = fn_decl @TakesLValue__carbon_thunk [concrete = constants.%TakesLValue__carbon_thunk] {
  203. // CHECK:STDOUT: <elided>
  204. // CHECK:STDOUT: } {
  205. // CHECK:STDOUT: <elided>
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: fn @F() {
  210. // CHECK:STDOUT: !entry:
  211. // CHECK:STDOUT: name_binding_decl {
  212. // CHECK:STDOUT: %s.patt: %pattern_type.7da = binding_pattern s [concrete]
  213. // CHECK:STDOUT: %s.var_patt: %pattern_type.7da = var_pattern %s.patt [concrete]
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT: %s.var: ref %S = var %s.var_patt
  216. // CHECK:STDOUT: %.loc8_19.1: %empty_struct_type = struct_literal ()
  217. // CHECK:STDOUT: %.loc8_19.2: init %S = class_init (), %s.var [concrete = constants.%S.val]
  218. // CHECK:STDOUT: %.loc8_3.1: init %S = converted %.loc8_19.1, %.loc8_19.2 [concrete = constants.%S.val]
  219. // CHECK:STDOUT: assign %s.var, %.loc8_3.1
  220. // CHECK:STDOUT: %.loc8_13: type = splice_block %S.ref [concrete = constants.%S] {
  221. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  222. // CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT: %s: ref %S = bind_name s, %s.var
  225. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  226. // CHECK:STDOUT: %TakesLValue.ref: %.547 = name_ref TakesLValue, imports.%.a7f [concrete = constants.%empty_struct]
  227. // CHECK:STDOUT: %s.ref: ref %S = name_ref s, %s
  228. // CHECK:STDOUT: %addr.loc9: %ptr.5c7 = addr_of %s.ref
  229. // CHECK:STDOUT: %TakesLValue__carbon_thunk.call: init %empty_tuple.type = call imports.%TakesLValue__carbon_thunk.decl(%addr.loc9)
  230. // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value]
  231. // CHECK:STDOUT: %.loc8_3.2: %type_where = converted constants.%S, %facet_value [concrete = constants.%facet_value]
  232. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %s.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  233. // CHECK:STDOUT: <elided>
  234. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %s.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
  235. // CHECK:STDOUT: %addr.loc8: %ptr.5c7 = addr_of %s.var
  236. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr.loc8)
  237. // CHECK:STDOUT: <elided>
  238. // CHECK:STDOUT: }
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: --- fail_lvalue_ref.carbon
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: constants {
  243. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  244. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  245. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  246. // CHECK:STDOUT: %.547: type = cpp_overload_set_type @Destroy.Op [concrete]
  247. // CHECK:STDOUT: %empty_struct: %.547 = struct_value () [concrete]
  248. // CHECK:STDOUT: %T: type = class_type @T [concrete]
  249. // CHECK:STDOUT: %pattern_type.e6b: type = pattern_type %T [concrete]
  250. // CHECK:STDOUT: %const.e39: type = const_type %S [concrete]
  251. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  252. // CHECK:STDOUT: %facet_value.7bd: %type_where = facet_value %S, () [concrete]
  253. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value.7bd) [concrete]
  254. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  255. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  256. // CHECK:STDOUT: %facet_value.19d: %type_where = facet_value %T, () [concrete]
  257. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.896: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value.19d) [concrete]
  258. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.8c8: %AggregateT.as_type.as.Destroy.impl.Op.type.896 = struct_value () [concrete]
  259. // CHECK:STDOUT: %ptr.b04: type = ptr_type %T [concrete]
  260. // CHECK:STDOUT: }
  261. // CHECK:STDOUT:
  262. // CHECK:STDOUT: imports {
  263. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  264. // CHECK:STDOUT: .S = %S.decl
  265. // CHECK:STDOUT: .TakesLValue = %.a7f
  266. // CHECK:STDOUT: .T = %T.decl
  267. // CHECK:STDOUT: import Cpp//...
  268. // CHECK:STDOUT: }
  269. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  270. // CHECK:STDOUT: %.a7f: %.547 = cpp_overload_set_value @Destroy.Op [concrete = constants.%empty_struct]
  271. // CHECK:STDOUT: %T.decl: type = class_decl @T [concrete = constants.%T] {} {}
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT:
  274. // CHECK:STDOUT: fn @F() {
  275. // CHECK:STDOUT: !entry:
  276. // CHECK:STDOUT: name_binding_decl {
  277. // CHECK:STDOUT: %v.patt: %pattern_type.7da = binding_pattern v [concrete]
  278. // CHECK:STDOUT: %v.var_patt: %pattern_type.7da = var_pattern %v.patt [concrete]
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT: %v.var: ref %S = var %v.var_patt
  281. // CHECK:STDOUT: %.loc8_13: type = splice_block %S.ref.loc8 [concrete = constants.%S] {
  282. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  283. // CHECK:STDOUT: %S.ref.loc8: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT: %v: ref %S = bind_name v, %v.var
  286. // CHECK:STDOUT: name_binding_decl {
  287. // CHECK:STDOUT: %s.patt: %pattern_type.7da = binding_pattern s [concrete]
  288. // CHECK:STDOUT: }
  289. // CHECK:STDOUT: %v.ref: ref %S = name_ref v, %v
  290. // CHECK:STDOUT: %.loc9_13: type = splice_block %S.ref.loc9 [concrete = constants.%S] {
  291. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  292. // CHECK:STDOUT: %S.ref.loc9: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  293. // CHECK:STDOUT: }
  294. // CHECK:STDOUT: %.loc9_18: %S = bind_value %v.ref
  295. // CHECK:STDOUT: %s: %S = bind_name s, %.loc9_18
  296. // CHECK:STDOUT: %Cpp.ref.loc18: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  297. // CHECK:STDOUT: %TakesLValue.ref.loc18: %.547 = name_ref TakesLValue, imports.%.a7f [concrete = constants.%empty_struct]
  298. // CHECK:STDOUT: %s.ref: %S = name_ref s, %s
  299. // CHECK:STDOUT: name_binding_decl {
  300. // CHECK:STDOUT: %t.patt: %pattern_type.e6b = binding_pattern t [concrete]
  301. // CHECK:STDOUT: %t.var_patt: %pattern_type.e6b = var_pattern %t.patt [concrete]
  302. // CHECK:STDOUT: }
  303. // CHECK:STDOUT: %t.var: ref %T = var %t.var_patt
  304. // CHECK:STDOUT: %.loc20_13: type = splice_block %T.ref [concrete = constants.%T] {
  305. // CHECK:STDOUT: %Cpp.ref.loc20: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  306. // CHECK:STDOUT: %T.ref: type = name_ref T, imports.%T.decl [concrete = constants.%T]
  307. // CHECK:STDOUT: }
  308. // CHECK:STDOUT: %t: ref %T = bind_name t, %t.var
  309. // CHECK:STDOUT: %Cpp.ref.loc29: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  310. // CHECK:STDOUT: %TakesLValue.ref.loc29: %.547 = name_ref TakesLValue, imports.%.a7f [concrete = constants.%empty_struct]
  311. // CHECK:STDOUT: %t.ref: ref %T = name_ref t, %t
  312. // CHECK:STDOUT: name_binding_decl {
  313. // CHECK:STDOUT: %u.patt: %pattern_type.7da = binding_pattern u [concrete]
  314. // CHECK:STDOUT: %u.var_patt: %pattern_type.7da = var_pattern %u.patt [concrete]
  315. // CHECK:STDOUT: }
  316. // CHECK:STDOUT: %u.var: ref %S = var %u.var_patt
  317. // CHECK:STDOUT: %.loc31_13: type = splice_block %S.ref.loc31 [concrete = constants.%S] {
  318. // CHECK:STDOUT: %Cpp.ref.loc31: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  319. // CHECK:STDOUT: %S.ref.loc31: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT: %u: ref %S = bind_name u, %u.var
  322. // CHECK:STDOUT: %Cpp.ref.loc40_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  323. // CHECK:STDOUT: %TakesLValue.ref.loc40: %.547 = name_ref TakesLValue, imports.%.a7f [concrete = constants.%empty_struct]
  324. // CHECK:STDOUT: %u.ref: ref %S = name_ref u, %u
  325. // CHECK:STDOUT: %Cpp.ref.loc40_30: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  326. // CHECK:STDOUT: %S.ref.loc40: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  327. // CHECK:STDOUT: %const: type = const_type %S.ref.loc40 [concrete = constants.%const.e39]
  328. // CHECK:STDOUT: %.loc40_21.1: ref %const.e39 = as_compatible %u.ref
  329. // CHECK:STDOUT: %.loc40_21.2: ref %const.e39 = converted %u.ref, %.loc40_21.1
  330. // CHECK:STDOUT: %facet_value.loc31: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value.7bd]
  331. // CHECK:STDOUT: %.loc31_3: %type_where = converted constants.%S, %facet_value.loc31 [concrete = constants.%facet_value.7bd]
  332. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc31: <bound method> = bound_method %u.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  333. // CHECK:STDOUT: <elided>
  334. // CHECK:STDOUT: %bound_method.loc31: <bound method> = bound_method %u.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1
  335. // CHECK:STDOUT: %addr.loc31: %ptr.5c7 = addr_of %u.var
  336. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc31: init %empty_tuple.type = call %bound_method.loc31(%addr.loc31)
  337. // CHECK:STDOUT: %facet_value.loc20: %type_where = facet_value constants.%T, () [concrete = constants.%facet_value.19d]
  338. // CHECK:STDOUT: %.loc20_3: %type_where = converted constants.%T, %facet_value.loc20 [concrete = constants.%facet_value.19d]
  339. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc20: <bound method> = bound_method %t.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.8c8
  340. // CHECK:STDOUT: <elided>
  341. // CHECK:STDOUT: %bound_method.loc20: <bound method> = bound_method %t.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2
  342. // CHECK:STDOUT: %addr.loc20: %ptr.b04 = addr_of %t.var
  343. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc20: init %empty_tuple.type = call %bound_method.loc20(%addr.loc20)
  344. // CHECK:STDOUT: %facet_value.loc8: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value.7bd]
  345. // CHECK:STDOUT: %.loc8_3: %type_where = converted constants.%S, %facet_value.loc8 [concrete = constants.%facet_value.7bd]
  346. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc8: <bound method> = bound_method %v.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  347. // CHECK:STDOUT: <elided>
  348. // CHECK:STDOUT: %bound_method.loc8: <bound method> = bound_method %v.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.3
  349. // CHECK:STDOUT: %addr.loc8: %ptr.5c7 = addr_of %v.var
  350. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc8: init %empty_tuple.type = call %bound_method.loc8(%addr.loc8)
  351. // CHECK:STDOUT: <elided>
  352. // CHECK:STDOUT: }
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: --- call_rvalue_ref.carbon
  355. // CHECK:STDOUT:
  356. // CHECK:STDOUT: constants {
  357. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  358. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  359. // CHECK:STDOUT: %.1b9: type = cpp_overload_set_type @TakesRValue [concrete]
  360. // CHECK:STDOUT: %empty_struct: %.1b9 = struct_value () [concrete]
  361. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  362. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  363. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  364. // CHECK:STDOUT: %TakesRValue__carbon_thunk.type: type = fn_type @TakesRValue__carbon_thunk [concrete]
  365. // CHECK:STDOUT: %TakesRValue__carbon_thunk: %TakesRValue__carbon_thunk.type = struct_value () [concrete]
  366. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  367. // CHECK:STDOUT: %facet_value: %type_where = facet_value %S, () [concrete]
  368. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  369. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  370. // CHECK:STDOUT: }
  371. // CHECK:STDOUT:
  372. // CHECK:STDOUT: imports {
  373. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  374. // CHECK:STDOUT: .TakesRValue = %.1f6
  375. // CHECK:STDOUT: .S = %S.decl
  376. // CHECK:STDOUT: import Cpp//...
  377. // CHECK:STDOUT: }
  378. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  379. // CHECK:STDOUT: %.1f6: %.1b9 = cpp_overload_set_value @TakesRValue [concrete = constants.%empty_struct]
  380. // CHECK:STDOUT: %TakesRValue__carbon_thunk.decl: %TakesRValue__carbon_thunk.type = fn_decl @TakesRValue__carbon_thunk [concrete = constants.%TakesRValue__carbon_thunk] {
  381. // CHECK:STDOUT: <elided>
  382. // CHECK:STDOUT: } {
  383. // CHECK:STDOUT: <elided>
  384. // CHECK:STDOUT: }
  385. // CHECK:STDOUT: }
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: fn @F() {
  388. // CHECK:STDOUT: !entry:
  389. // CHECK:STDOUT: %Cpp.ref.loc8_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  390. // CHECK:STDOUT: %TakesRValue.ref: %.1b9 = name_ref TakesRValue, imports.%.1f6 [concrete = constants.%empty_struct]
  391. // CHECK:STDOUT: %.loc8_20.1: %empty_struct_type = struct_literal ()
  392. // CHECK:STDOUT: %Cpp.ref.loc8_25: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  393. // CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  394. // CHECK:STDOUT: %.loc8_20.2: ref %S = temporary_storage
  395. // CHECK:STDOUT: %.loc8_20.3: init %S = class_init (), %.loc8_20.2 [concrete = constants.%S.val]
  396. // CHECK:STDOUT: %.loc8_20.4: ref %S = temporary %.loc8_20.2, %.loc8_20.3
  397. // CHECK:STDOUT: %.loc8_22.1: ref %S = converted %.loc8_20.1, %.loc8_20.4
  398. // CHECK:STDOUT: %.loc8_22.2: %S = bind_value %.loc8_22.1
  399. // CHECK:STDOUT: %.loc8_22.3: ref %S = value_as_ref %.loc8_22.2
  400. // CHECK:STDOUT: %addr.loc8_30: %ptr.5c7 = addr_of %.loc8_22.3
  401. // CHECK:STDOUT: %TakesRValue__carbon_thunk.call: init %empty_tuple.type = call imports.%TakesRValue__carbon_thunk.decl(%addr.loc8_30)
  402. // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value]
  403. // CHECK:STDOUT: %.loc8_20.5: %type_where = converted constants.%S, %facet_value [concrete = constants.%facet_value]
  404. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %.loc8_20.4, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  405. // CHECK:STDOUT: <elided>
  406. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc8_20.4, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
  407. // CHECK:STDOUT: %addr.loc8_20: %ptr.5c7 = addr_of %.loc8_20.4
  408. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr.loc8_20)
  409. // CHECK:STDOUT: <elided>
  410. // CHECK:STDOUT: }
  411. // CHECK:STDOUT:
  412. // CHECK:STDOUT: --- todo_fail_value_arg_for_rvalue_ref.carbon
  413. // CHECK:STDOUT:
  414. // CHECK:STDOUT: constants {
  415. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  416. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  417. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  418. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  419. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  420. // CHECK:STDOUT: %.1b9: type = cpp_overload_set_type @TakesRValue [concrete]
  421. // CHECK:STDOUT: %empty_struct: %.1b9 = struct_value () [concrete]
  422. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  423. // CHECK:STDOUT: %TakesRValue__carbon_thunk.type: type = fn_type @TakesRValue__carbon_thunk [concrete]
  424. // CHECK:STDOUT: %TakesRValue__carbon_thunk: %TakesRValue__carbon_thunk.type = struct_value () [concrete]
  425. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  426. // CHECK:STDOUT: %facet_value: %type_where = facet_value %S, () [concrete]
  427. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  428. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  429. // CHECK:STDOUT: }
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: imports {
  432. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  433. // CHECK:STDOUT: .S = %S.decl
  434. // CHECK:STDOUT: .TakesRValue = %.1f6
  435. // CHECK:STDOUT: import Cpp//...
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  438. // CHECK:STDOUT: %.1f6: %.1b9 = cpp_overload_set_value @TakesRValue [concrete = constants.%empty_struct]
  439. // CHECK:STDOUT: %TakesRValue__carbon_thunk.decl: %TakesRValue__carbon_thunk.type = fn_decl @TakesRValue__carbon_thunk [concrete = constants.%TakesRValue__carbon_thunk] {
  440. // CHECK:STDOUT: <elided>
  441. // CHECK:STDOUT: } {
  442. // CHECK:STDOUT: <elided>
  443. // CHECK:STDOUT: }
  444. // CHECK:STDOUT: }
  445. // CHECK:STDOUT:
  446. // CHECK:STDOUT: fn @F() {
  447. // CHECK:STDOUT: !entry:
  448. // CHECK:STDOUT: name_binding_decl {
  449. // CHECK:STDOUT: %s.patt: %pattern_type.7da = binding_pattern s [concrete]
  450. // CHECK:STDOUT: }
  451. // CHECK:STDOUT: %.loc12_19.1: %empty_struct_type = struct_literal ()
  452. // CHECK:STDOUT: %.loc12_13: type = splice_block %S.ref [concrete = constants.%S] {
  453. // CHECK:STDOUT: %Cpp.ref.loc12: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  454. // CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  455. // CHECK:STDOUT: }
  456. // CHECK:STDOUT: %.loc12_19.2: ref %S = temporary_storage
  457. // CHECK:STDOUT: %.loc12_19.3: init %S = class_init (), %.loc12_19.2 [concrete = constants.%S.val]
  458. // CHECK:STDOUT: %.loc12_19.4: ref %S = temporary %.loc12_19.2, %.loc12_19.3
  459. // CHECK:STDOUT: %.loc12_19.5: ref %S = converted %.loc12_19.1, %.loc12_19.4
  460. // CHECK:STDOUT: %.loc12_19.6: %S = bind_value %.loc12_19.5
  461. // CHECK:STDOUT: %s: %S = bind_name s, %.loc12_19.6
  462. // CHECK:STDOUT: %Cpp.ref.loc13: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  463. // CHECK:STDOUT: %TakesRValue.ref: %.1b9 = name_ref TakesRValue, imports.%.1f6 [concrete = constants.%empty_struct]
  464. // CHECK:STDOUT: %s.ref: %S = name_ref s, %s
  465. // CHECK:STDOUT: %.loc13: ref %S = value_as_ref %s.ref
  466. // CHECK:STDOUT: %addr.loc13: %ptr.5c7 = addr_of %.loc13
  467. // CHECK:STDOUT: %TakesRValue__carbon_thunk.call: init %empty_tuple.type = call imports.%TakesRValue__carbon_thunk.decl(%addr.loc13)
  468. // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value]
  469. // CHECK:STDOUT: %.loc12_19.7: %type_where = converted constants.%S, %facet_value [concrete = constants.%facet_value]
  470. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %.loc12_19.4, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  471. // CHECK:STDOUT: <elided>
  472. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %.loc12_19.4, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
  473. // CHECK:STDOUT: %addr.loc12: %ptr.5c7 = addr_of %.loc12_19.4
  474. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr.loc12)
  475. // CHECK:STDOUT: <elided>
  476. // CHECK:STDOUT: }
  477. // CHECK:STDOUT:
  478. // CHECK:STDOUT: --- fail_rvalue_ref.carbon
  479. // CHECK:STDOUT:
  480. // CHECK:STDOUT: constants {
  481. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  482. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  483. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  484. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  485. // CHECK:STDOUT: %.1b9: type = cpp_overload_set_type @Destroy.Op [concrete]
  486. // CHECK:STDOUT: %empty_struct: %.1b9 = struct_value () [concrete]
  487. // CHECK:STDOUT: %T: type = class_type @T [concrete]
  488. // CHECK:STDOUT: %pattern_type.e6b: type = pattern_type %T [concrete]
  489. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  490. // CHECK:STDOUT: %const.e39: type = const_type %S [concrete]
  491. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  492. // CHECK:STDOUT: %facet_value.7bd: %type_where = facet_value %S, () [concrete]
  493. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value.7bd) [concrete]
  494. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  495. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  496. // CHECK:STDOUT: %facet_value.19d: %type_where = facet_value %T, () [concrete]
  497. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.896: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value.19d) [concrete]
  498. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.8c8: %AggregateT.as_type.as.Destroy.impl.Op.type.896 = struct_value () [concrete]
  499. // CHECK:STDOUT: %ptr.b04: type = ptr_type %T [concrete]
  500. // CHECK:STDOUT: }
  501. // CHECK:STDOUT:
  502. // CHECK:STDOUT: imports {
  503. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  504. // CHECK:STDOUT: .S = %S.decl
  505. // CHECK:STDOUT: .TakesRValue = %.1f6
  506. // CHECK:STDOUT: .T = %T.decl
  507. // CHECK:STDOUT: import Cpp//...
  508. // CHECK:STDOUT: }
  509. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  510. // CHECK:STDOUT: %.1f6: %.1b9 = cpp_overload_set_value @Destroy.Op [concrete = constants.%empty_struct]
  511. // CHECK:STDOUT: %T.decl: type = class_decl @T [concrete = constants.%T] {} {}
  512. // CHECK:STDOUT: }
  513. // CHECK:STDOUT:
  514. // CHECK:STDOUT: fn @F() {
  515. // CHECK:STDOUT: !entry:
  516. // CHECK:STDOUT: name_binding_decl {
  517. // CHECK:STDOUT: %s.patt: %pattern_type.7da = binding_pattern s [concrete]
  518. // CHECK:STDOUT: %s.var_patt: %pattern_type.7da = var_pattern %s.patt [concrete]
  519. // CHECK:STDOUT: }
  520. // CHECK:STDOUT: %s.var: ref %S = var %s.var_patt
  521. // CHECK:STDOUT: %.loc8_13: type = splice_block %S.ref.loc8 [concrete = constants.%S] {
  522. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  523. // CHECK:STDOUT: %S.ref.loc8: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  524. // CHECK:STDOUT: }
  525. // CHECK:STDOUT: %s: ref %S = bind_name s, %s.var
  526. // CHECK:STDOUT: %Cpp.ref.loc17: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  527. // CHECK:STDOUT: %TakesRValue.ref.loc17: %.1b9 = name_ref TakesRValue, imports.%.1f6 [concrete = constants.%empty_struct]
  528. // CHECK:STDOUT: %s.ref: ref %S = name_ref s, %s
  529. // CHECK:STDOUT: name_binding_decl {
  530. // CHECK:STDOUT: %t.patt: %pattern_type.e6b = binding_pattern t [concrete]
  531. // CHECK:STDOUT: %t.var_patt: %pattern_type.e6b = var_pattern %t.patt [concrete]
  532. // CHECK:STDOUT: }
  533. // CHECK:STDOUT: %t.var: ref %T = var %t.var_patt
  534. // CHECK:STDOUT: %.loc19_13: type = splice_block %T.ref [concrete = constants.%T] {
  535. // CHECK:STDOUT: %Cpp.ref.loc19: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  536. // CHECK:STDOUT: %T.ref: type = name_ref T, imports.%T.decl [concrete = constants.%T]
  537. // CHECK:STDOUT: }
  538. // CHECK:STDOUT: %t: ref %T = bind_name t, %t.var
  539. // CHECK:STDOUT: %Cpp.ref.loc28: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  540. // CHECK:STDOUT: %TakesRValue.ref.loc28: %.1b9 = name_ref TakesRValue, imports.%.1f6 [concrete = constants.%empty_struct]
  541. // CHECK:STDOUT: %t.ref: ref %T = name_ref t, %t
  542. // CHECK:STDOUT: %Cpp.ref.loc38_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  543. // CHECK:STDOUT: %TakesRValue.ref.loc38: %.1b9 = name_ref TakesRValue, imports.%.1f6 [concrete = constants.%empty_struct]
  544. // CHECK:STDOUT: %.loc38_21.1: %empty_struct_type = struct_literal ()
  545. // CHECK:STDOUT: %Cpp.ref.loc38_26: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  546. // CHECK:STDOUT: %S.ref.loc38_29: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  547. // CHECK:STDOUT: %.loc38_21.2: ref %S = temporary_storage
  548. // CHECK:STDOUT: %.loc38_21.3: init %S = class_init (), %.loc38_21.2 [concrete = constants.%S.val]
  549. // CHECK:STDOUT: %.loc38_21.4: ref %S = temporary %.loc38_21.2, %.loc38_21.3
  550. // CHECK:STDOUT: %.loc38_23: ref %S = converted %.loc38_21.1, %.loc38_21.4
  551. // CHECK:STDOUT: %Cpp.ref.loc38_42: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  552. // CHECK:STDOUT: %S.ref.loc38_45: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  553. // CHECK:STDOUT: %const: type = const_type %S.ref.loc38_45 [concrete = constants.%const.e39]
  554. // CHECK:STDOUT: %.loc38_33.1: ref %const.e39 = as_compatible %.loc38_23
  555. // CHECK:STDOUT: %.loc38_33.2: ref %const.e39 = converted %.loc38_23, %.loc38_33.1
  556. // CHECK:STDOUT: %facet_value.loc38: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value.7bd]
  557. // CHECK:STDOUT: %.loc38_21.5: %type_where = converted constants.%S, %facet_value.loc38 [concrete = constants.%facet_value.7bd]
  558. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc38: <bound method> = bound_method %.loc38_21.4, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  559. // CHECK:STDOUT: <elided>
  560. // CHECK:STDOUT: %bound_method.loc38: <bound method> = bound_method %.loc38_21.4, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1
  561. // CHECK:STDOUT: %addr.loc38: %ptr.5c7 = addr_of %.loc38_21.4
  562. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc38: init %empty_tuple.type = call %bound_method.loc38(%addr.loc38)
  563. // CHECK:STDOUT: %facet_value.loc19: %type_where = facet_value constants.%T, () [concrete = constants.%facet_value.19d]
  564. // CHECK:STDOUT: %.loc19_3: %type_where = converted constants.%T, %facet_value.loc19 [concrete = constants.%facet_value.19d]
  565. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc19: <bound method> = bound_method %t.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.8c8
  566. // CHECK:STDOUT: <elided>
  567. // CHECK:STDOUT: %bound_method.loc19: <bound method> = bound_method %t.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2
  568. // CHECK:STDOUT: %addr.loc19: %ptr.b04 = addr_of %t.var
  569. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc19: init %empty_tuple.type = call %bound_method.loc19(%addr.loc19)
  570. // CHECK:STDOUT: %facet_value.loc8: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value.7bd]
  571. // CHECK:STDOUT: %.loc8_3: %type_where = converted constants.%S, %facet_value.loc8 [concrete = constants.%facet_value.7bd]
  572. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc8: <bound method> = bound_method %s.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  573. // CHECK:STDOUT: <elided>
  574. // CHECK:STDOUT: %bound_method.loc8: <bound method> = bound_method %s.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.3
  575. // CHECK:STDOUT: %addr.loc8: %ptr.5c7 = addr_of %s.var
  576. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc8: init %empty_tuple.type = call %bound_method.loc8(%addr.loc8)
  577. // CHECK:STDOUT: <elided>
  578. // CHECK:STDOUT: }
  579. // CHECK:STDOUT:
  580. // CHECK:STDOUT: --- call_const_lvalue_ref.carbon
  581. // CHECK:STDOUT:
  582. // CHECK:STDOUT: constants {
  583. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  584. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  585. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  586. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  587. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  588. // CHECK:STDOUT: %.4e1: type = cpp_overload_set_type @TakesConstLValue [concrete]
  589. // CHECK:STDOUT: %empty_struct: %.4e1 = struct_value () [concrete]
  590. // CHECK:STDOUT: %const.e39: type = const_type %S [concrete]
  591. // CHECK:STDOUT: %ptr.ff5: type = ptr_type %const.e39 [concrete]
  592. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.type: type = fn_type @TakesConstLValue__carbon_thunk [concrete]
  593. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk: %TakesConstLValue__carbon_thunk.type = struct_value () [concrete]
  594. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  595. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  596. // CHECK:STDOUT: %facet_value: %type_where = facet_value %S, () [concrete]
  597. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  598. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  599. // CHECK:STDOUT: }
  600. // CHECK:STDOUT:
  601. // CHECK:STDOUT: imports {
  602. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  603. // CHECK:STDOUT: .S = %S.decl
  604. // CHECK:STDOUT: .TakesConstLValue = %.9bc
  605. // CHECK:STDOUT: import Cpp//...
  606. // CHECK:STDOUT: }
  607. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  608. // CHECK:STDOUT: %.9bc: %.4e1 = cpp_overload_set_value @TakesConstLValue [concrete = constants.%empty_struct]
  609. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.decl: %TakesConstLValue__carbon_thunk.type = fn_decl @TakesConstLValue__carbon_thunk [concrete = constants.%TakesConstLValue__carbon_thunk] {
  610. // CHECK:STDOUT: <elided>
  611. // CHECK:STDOUT: } {
  612. // CHECK:STDOUT: <elided>
  613. // CHECK:STDOUT: }
  614. // CHECK:STDOUT: }
  615. // CHECK:STDOUT:
  616. // CHECK:STDOUT: fn @F() {
  617. // CHECK:STDOUT: !entry:
  618. // CHECK:STDOUT: name_binding_decl {
  619. // CHECK:STDOUT: %s.patt: %pattern_type.7da = binding_pattern s [concrete]
  620. // CHECK:STDOUT: %s.var_patt: %pattern_type.7da = var_pattern %s.patt [concrete]
  621. // CHECK:STDOUT: }
  622. // CHECK:STDOUT: %s.var: ref %S = var %s.var_patt
  623. // CHECK:STDOUT: %.loc8_19.1: %empty_struct_type = struct_literal ()
  624. // CHECK:STDOUT: %.loc8_19.2: init %S = class_init (), %s.var [concrete = constants.%S.val]
  625. // CHECK:STDOUT: %.loc8_3.1: init %S = converted %.loc8_19.1, %.loc8_19.2 [concrete = constants.%S.val]
  626. // CHECK:STDOUT: assign %s.var, %.loc8_3.1
  627. // CHECK:STDOUT: %.loc8_13: type = splice_block %S.ref.loc8 [concrete = constants.%S] {
  628. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  629. // CHECK:STDOUT: %S.ref.loc8: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  630. // CHECK:STDOUT: }
  631. // CHECK:STDOUT: %s: ref %S = bind_name s, %s.var
  632. // CHECK:STDOUT: %Cpp.ref.loc9_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  633. // CHECK:STDOUT: %TakesConstLValue.ref.loc9: %.4e1 = name_ref TakesConstLValue, imports.%.9bc [concrete = constants.%empty_struct]
  634. // CHECK:STDOUT: %s.ref.loc9: ref %S = name_ref s, %s
  635. // CHECK:STDOUT: %Cpp.ref.loc9_35: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  636. // CHECK:STDOUT: %S.ref.loc9: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  637. // CHECK:STDOUT: %const: type = const_type %S.ref.loc9 [concrete = constants.%const.e39]
  638. // CHECK:STDOUT: %.loc9_26.1: ref %const.e39 = as_compatible %s.ref.loc9
  639. // CHECK:STDOUT: %.loc9_26.2: ref %const.e39 = converted %s.ref.loc9, %.loc9_26.1
  640. // CHECK:STDOUT: %addr.loc9: %ptr.ff5 = addr_of %.loc9_26.2
  641. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.call.loc9: init %empty_tuple.type = call imports.%TakesConstLValue__carbon_thunk.decl(%addr.loc9)
  642. // CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  643. // CHECK:STDOUT: %TakesConstLValue.ref.loc11: %.4e1 = name_ref TakesConstLValue, imports.%.9bc [concrete = constants.%empty_struct]
  644. // CHECK:STDOUT: %s.ref.loc11: ref %S = name_ref s, %s
  645. // CHECK:STDOUT: %addr.loc11: %ptr.5c7 = addr_of %s.ref.loc11
  646. // CHECK:STDOUT: %.loc11_24.1: %ptr.ff5 = as_compatible %addr.loc11
  647. // CHECK:STDOUT: %.loc11_24.2: %ptr.ff5 = converted %addr.loc11, %.loc11_24.1
  648. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.call.loc11: init %empty_tuple.type = call imports.%TakesConstLValue__carbon_thunk.decl(%.loc11_24.2)
  649. // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value]
  650. // CHECK:STDOUT: %.loc8_3.2: %type_where = converted constants.%S, %facet_value [concrete = constants.%facet_value]
  651. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %s.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  652. // CHECK:STDOUT: <elided>
  653. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %s.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn
  654. // CHECK:STDOUT: %addr.loc8: %ptr.5c7 = addr_of %s.var
  655. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr.loc8)
  656. // CHECK:STDOUT: <elided>
  657. // CHECK:STDOUT: }
  658. // CHECK:STDOUT:
  659. // CHECK:STDOUT: --- fail_const_lvalue_ref.carbon
  660. // CHECK:STDOUT:
  661. // CHECK:STDOUT: constants {
  662. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  663. // CHECK:STDOUT: %S: type = class_type @S [concrete]
  664. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  665. // CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
  666. // CHECK:STDOUT: %S.val: %S = struct_value () [concrete]
  667. // CHECK:STDOUT: %.4e1: type = cpp_overload_set_type @TakesConstLValue [concrete]
  668. // CHECK:STDOUT: %empty_struct: %.4e1 = struct_value () [concrete]
  669. // CHECK:STDOUT: %const.e39: type = const_type %S [concrete]
  670. // CHECK:STDOUT: %ptr.ff5: type = ptr_type %const.e39 [concrete]
  671. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.type: type = fn_type @TakesConstLValue__carbon_thunk [concrete]
  672. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk: %TakesConstLValue__carbon_thunk.type = struct_value () [concrete]
  673. // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
  674. // CHECK:STDOUT: %T: type = class_type @T [concrete]
  675. // CHECK:STDOUT: %pattern_type.e6b: type = pattern_type %T [concrete]
  676. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  677. // CHECK:STDOUT: %facet_value.19d: %type_where = facet_value %T, () [concrete]
  678. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.896: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value.19d) [concrete]
  679. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.8c8: %AggregateT.as_type.as.Destroy.impl.Op.type.896 = struct_value () [concrete]
  680. // CHECK:STDOUT: %ptr.b04: type = ptr_type %T [concrete]
  681. // CHECK:STDOUT: %facet_value.7bd: %type_where = facet_value %S, () [concrete]
  682. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.df1: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value.7bd) [concrete]
  683. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.cc2: %AggregateT.as_type.as.Destroy.impl.Op.type.df1 = struct_value () [concrete]
  684. // CHECK:STDOUT: }
  685. // CHECK:STDOUT:
  686. // CHECK:STDOUT: imports {
  687. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  688. // CHECK:STDOUT: .S = %S.decl
  689. // CHECK:STDOUT: .TakesConstLValue = %.9bc
  690. // CHECK:STDOUT: .T = %T.decl
  691. // CHECK:STDOUT: import Cpp//...
  692. // CHECK:STDOUT: }
  693. // CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
  694. // CHECK:STDOUT: %.9bc: %.4e1 = cpp_overload_set_value @TakesConstLValue [concrete = constants.%empty_struct]
  695. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.decl: %TakesConstLValue__carbon_thunk.type = fn_decl @TakesConstLValue__carbon_thunk [concrete = constants.%TakesConstLValue__carbon_thunk] {
  696. // CHECK:STDOUT: <elided>
  697. // CHECK:STDOUT: } {
  698. // CHECK:STDOUT: <elided>
  699. // CHECK:STDOUT: }
  700. // CHECK:STDOUT: %T.decl: type = class_decl @T [concrete = constants.%T] {} {}
  701. // CHECK:STDOUT: }
  702. // CHECK:STDOUT:
  703. // CHECK:STDOUT: fn @F() {
  704. // CHECK:STDOUT: !entry:
  705. // CHECK:STDOUT: name_binding_decl {
  706. // CHECK:STDOUT: %s.patt: %pattern_type.7da = binding_pattern s [concrete]
  707. // CHECK:STDOUT: }
  708. // CHECK:STDOUT: %.loc12_19.1: %empty_struct_type = struct_literal ()
  709. // CHECK:STDOUT: %.loc12_13: type = splice_block %S.ref [concrete = constants.%S] {
  710. // CHECK:STDOUT: %Cpp.ref.loc12: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  711. // CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
  712. // CHECK:STDOUT: }
  713. // CHECK:STDOUT: %.loc12_19.2: ref %S = temporary_storage
  714. // CHECK:STDOUT: %.loc12_19.3: init %S = class_init (), %.loc12_19.2 [concrete = constants.%S.val]
  715. // CHECK:STDOUT: %.loc12_19.4: ref %S = temporary %.loc12_19.2, %.loc12_19.3
  716. // CHECK:STDOUT: %.loc12_19.5: ref %S = converted %.loc12_19.1, %.loc12_19.4
  717. // CHECK:STDOUT: %.loc12_19.6: %S = bind_value %.loc12_19.5
  718. // CHECK:STDOUT: %s: %S = bind_name s, %.loc12_19.6
  719. // CHECK:STDOUT: %Cpp.ref.loc18: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  720. // CHECK:STDOUT: %TakesConstLValue.ref.loc18: %.4e1 = name_ref TakesConstLValue, imports.%.9bc [concrete = constants.%empty_struct]
  721. // CHECK:STDOUT: %s.ref: %S = name_ref s, %s
  722. // CHECK:STDOUT: %.loc18_24.1: ref %S = temporary_storage
  723. // CHECK:STDOUT: %addr.loc18: %ptr.5c7 = addr_of %.loc18_24.1
  724. // CHECK:STDOUT: %.loc18_24.2: %ptr.ff5 = as_compatible %addr.loc18
  725. // CHECK:STDOUT: %.loc18_24.3: %ptr.ff5 = converted %addr.loc18, %.loc18_24.2
  726. // CHECK:STDOUT: %TakesConstLValue__carbon_thunk.call: init %empty_tuple.type = call imports.%TakesConstLValue__carbon_thunk.decl(%.loc18_24.3)
  727. // CHECK:STDOUT: name_binding_decl {
  728. // CHECK:STDOUT: %t.patt: %pattern_type.e6b = binding_pattern t [concrete]
  729. // CHECK:STDOUT: %t.var_patt: %pattern_type.e6b = var_pattern %t.patt [concrete]
  730. // CHECK:STDOUT: }
  731. // CHECK:STDOUT: %t.var: ref %T = var %t.var_patt
  732. // CHECK:STDOUT: %.loc20_13: type = splice_block %T.ref [concrete = constants.%T] {
  733. // CHECK:STDOUT: %Cpp.ref.loc20: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  734. // CHECK:STDOUT: %T.ref: type = name_ref T, imports.%T.decl [concrete = constants.%T]
  735. // CHECK:STDOUT: }
  736. // CHECK:STDOUT: %t: ref %T = bind_name t, %t.var
  737. // CHECK:STDOUT: %Cpp.ref.loc29: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  738. // CHECK:STDOUT: %TakesConstLValue.ref.loc29: %.4e1 = name_ref TakesConstLValue, imports.%.9bc [concrete = constants.%empty_struct]
  739. // CHECK:STDOUT: %t.ref: ref %T = name_ref t, %t
  740. // CHECK:STDOUT: %facet_value.loc20: %type_where = facet_value constants.%T, () [concrete = constants.%facet_value.19d]
  741. // CHECK:STDOUT: %.loc20_3: %type_where = converted constants.%T, %facet_value.loc20 [concrete = constants.%facet_value.19d]
  742. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc20: <bound method> = bound_method %t.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.8c8
  743. // CHECK:STDOUT: <elided>
  744. // CHECK:STDOUT: %bound_method.loc20: <bound method> = bound_method %t.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1
  745. // CHECK:STDOUT: %addr.loc20: %ptr.b04 = addr_of %t.var
  746. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc20: init %empty_tuple.type = call %bound_method.loc20(%addr.loc20)
  747. // CHECK:STDOUT: %facet_value.loc12: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value.7bd]
  748. // CHECK:STDOUT: %.loc12_19.7: %type_where = converted constants.%S, %facet_value.loc12 [concrete = constants.%facet_value.7bd]
  749. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc12: <bound method> = bound_method %.loc12_19.4, constants.%AggregateT.as_type.as.Destroy.impl.Op.cc2
  750. // CHECK:STDOUT: <elided>
  751. // CHECK:STDOUT: %bound_method.loc12: <bound method> = bound_method %.loc12_19.4, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2
  752. // CHECK:STDOUT: %addr.loc12: %ptr.5c7 = addr_of %.loc12_19.4
  753. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc12: init %empty_tuple.type = call %bound_method.loc12(%addr.loc12)
  754. // CHECK:STDOUT: <elided>
  755. // CHECK:STDOUT: }
  756. // CHECK:STDOUT: