@@ -223,22 +223,20 @@ fn F() {
223
223
// Lvalue reference as return type
224
224
// ============================================================================
225
225
226
- // --- fail_todo_call_return_lvalue_ref.carbon
226
+ // --- return_lvalue_ref.h
227
227
228
- library "[[@TEST_NAME]]" ;
229
-
230
- import Cpp inline '''
231
228
struct S {};
232
229
233
230
auto ReturnsLValue () - > S& ;
234
- ''' ;
231
+
232
+ // --- call_return_lvalue_ref.carbon
233
+
234
+ library "[[@TEST_NAME]]" ;
235
+
236
+ import Cpp library "return_lvalue_ref.h" ;
235
237
236
238
fn F () {
237
239
// @dump-sem-ir-begin
238
- // CHECK:STDERR: fail_todo_call_return_lvalue_ref.carbon:[[@LINE+4]]:19: error: semantics TODO: `Unsupported: return type: S &` [SemanticsTodo]
239
- // CHECK:STDERR: let s: Cpp.S* = Cpp.ReturnsLValue();
240
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
241
- // CHECK:STDERR:
242
240
let s: Cpp.S* = Cpp.ReturnsLValue ();
243
241
// @dump-sem-ir-end
244
242
}
@@ -247,22 +245,20 @@ fn F() {
247
245
// Rvalue reference as return type
248
246
// ============================================================================
249
247
250
- // --- fail_todo_call_return_rvalue_ref.carbon
248
+ // --- return_rvalue_ref.h
251
249
252
- library "[[@TEST_NAME]]" ;
253
-
254
- import Cpp inline '''
255
250
struct S {};
256
251
257
252
auto ReturnsRValue () - > S&& ;
258
- ''' ;
253
+
254
+ // --- call_return_rvalue_ref.carbon
255
+
256
+ library "[[@TEST_NAME]]" ;
257
+
258
+ import Cpp library "return_rvalue_ref.h" ;
259
259
260
260
fn F () {
261
261
// @dump-sem-ir-begin
262
- // CHECK:STDERR: fail_todo_call_return_rvalue_ref.carbon:[[@LINE+4]]:18: error: semantics TODO: `Unsupported: return type: S &&` [SemanticsTodo]
263
- // CHECK:STDERR: var s: Cpp.S = Cpp.ReturnsRValue();
264
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
265
- // CHECK:STDERR:
266
262
var s: Cpp.S = Cpp.ReturnsRValue ();
267
263
// @dump-sem-ir-end
268
264
}
@@ -271,26 +267,41 @@ fn F() {
271
267
// Const reference as return type
272
268
// ============================================================================
273
269
274
- // --- fail_todo_call_return_const_lvalue_ref.carbon
270
+ // --- return_const_lvalue_ref.h
275
271
276
- library "[[@TEST_NAME]]" ;
277
-
278
- import Cpp inline '''
279
272
struct S {};
280
273
281
274
auto ReturnConstLValue () - > const S& ;
282
- ''' ;
275
+
276
+ // --- call_return_const_lvalue_ref.carbon
277
+
278
+ library "[[@TEST_NAME]]" ;
279
+
280
+ import Cpp library "return_const_lvalue_ref.h" ;
283
281
284
282
fn F () {
285
283
// @dump-sem-ir-begin
286
- // CHECK:STDERR: fail_todo_call_return_const_lvalue_ref.carbon:[[@LINE+4]]:24: error: semantics TODO: `Unsupported: return type: const S &` [SemanticsTodo]
287
- // CHECK:STDERR: var s: const Cpp.S = Cpp.ReturnConstLValue();
288
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
289
- // CHECK:STDERR:
290
- var s: const Cpp.S = Cpp.ReturnConstLValue ();
284
+ var s: const Cpp.S* = Cpp.ReturnConstLValue ();
291
285
// @dump-sem-ir-end
292
286
}
293
287
288
+ // --- fail_call_return_const_lvalue_ref_const_correctness.carbon
289
+
290
+ library "[[@TEST_NAME]]" ;
291
+
292
+ import Cpp library "return_const_lvalue_ref.h" ;
293
+
294
+ fn F () {
295
+ // CHECK:STDERR: fail_call_return_const_lvalue_ref_const_correctness.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `const Cpp.S*` to `Cpp.S*` [ConversionFailure]
296
+ // CHECK:STDERR: var s: Cpp.S* = Cpp.ReturnConstLValue();
297
+ // CHECK:STDERR: ^~~~~~~~~~~~~
298
+ // CHECK:STDERR: fail_call_return_const_lvalue_ref_const_correctness.carbon:[[@LINE+4]]:3: note: type `const Cpp.S*` does not implement interface `Core.ImplicitAs(Cpp.S*)` [MissingImplInMemberAccessNote]
299
+ // CHECK:STDERR: var s: Cpp.S* = Cpp.ReturnConstLValue();
300
+ // CHECK:STDERR: ^~~~~~~~~~~~~
301
+ // CHECK:STDERR:
302
+ var s: Cpp.S* = Cpp.ReturnConstLValue ();
303
+ }
304
+
294
305
// CHECK:STDOUT: --- call_param_lvalue_ref.carbon
295
306
// CHECK:STDOUT:
296
307
// CHECK:STDOUT: constants {
@@ -873,7 +884,7 @@ fn F() {
873
884
// CHECK:STDOUT: <elided>
874
885
// CHECK:STDOUT: }
875
886
// CHECK:STDOUT:
876
- // CHECK:STDOUT: --- fail_todo_call_return_lvalue_ref .carbon
887
+ // CHECK:STDOUT: --- call_return_lvalue_ref .carbon
877
888
// CHECK:STDOUT:
878
889
// CHECK:STDOUT: constants {
879
890
// CHECK:STDOUT: %S: type = class_type @S [concrete]
@@ -905,33 +916,35 @@ fn F() {
905
916
// CHECK:STDOUT: name_binding_decl {
906
917
// CHECK:STDOUT: %s.patt: %pattern_type = binding_pattern s [concrete]
907
918
// CHECK:STDOUT: }
908
- // CHECK:STDOUT: %Cpp.ref.loc16_19 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
919
+ // CHECK:STDOUT: %Cpp.ref.loc8_19 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
909
920
// CHECK:STDOUT: %ReturnsLValue.ref: %ReturnsLValue.cpp_overload_set.type = name_ref ReturnsLValue, imports.%ReturnsLValue.cpp_overload_set.value [concrete = constants.%ReturnsLValue.cpp_overload_set.value]
910
- // CHECK:STDOUT: %ReturnsLValue.call: init <error> = call imports.%ReturnsLValue.decl()
911
- // CHECK:STDOUT: %.loc16 : type = splice_block %ptr [concrete = constants.%ptr] {
912
- // CHECK:STDOUT: %Cpp.ref.loc16_10 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
921
+ // CHECK:STDOUT: %ReturnsLValue.call: init %ptr = call imports.%ReturnsLValue.decl()
922
+ // CHECK:STDOUT: %.loc8_15 : type = splice_block %ptr [concrete = constants.%ptr] {
923
+ // CHECK:STDOUT: %Cpp.ref.loc8_10 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
913
924
// CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
914
925
// CHECK:STDOUT: %ptr: type = ptr_type %S.ref [concrete = constants.%ptr]
915
926
// CHECK:STDOUT: }
916
- // CHECK:STDOUT: %s: %ptr = bind_name s, <error> [concrete = <error>]
927
+ // CHECK:STDOUT: %.loc8_37.1: %ptr = value_of_initializer %ReturnsLValue.call
928
+ // CHECK:STDOUT: %.loc8_37.2: %ptr = converted %ReturnsLValue.call, %.loc8_37.1
929
+ // CHECK:STDOUT: %s: %ptr = bind_name s, %.loc8_37.2
917
930
// CHECK:STDOUT: <elided>
918
931
// CHECK:STDOUT: }
919
932
// CHECK:STDOUT:
920
- // CHECK:STDOUT: --- fail_todo_call_return_rvalue_ref .carbon
933
+ // CHECK:STDOUT: --- call_return_rvalue_ref .carbon
921
934
// CHECK:STDOUT:
922
935
// CHECK:STDOUT: constants {
923
936
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
924
937
// CHECK:STDOUT: %S: type = class_type @S [concrete]
925
938
// CHECK:STDOUT: %pattern_type.7da: type = pattern_type %S [concrete]
926
939
// CHECK:STDOUT: %ReturnsRValue.cpp_overload_set.type: type = cpp_overload_set_type @ReturnsRValue.cpp_overload_set [concrete]
927
940
// CHECK:STDOUT: %ReturnsRValue.cpp_overload_set.value: %ReturnsRValue.cpp_overload_set.type = cpp_overload_set_value @ReturnsRValue.cpp_overload_set [concrete]
928
- // CHECK:STDOUT: %ReturnsRValue.type: type = fn_type @ReturnsRValue [concrete]
929
- // CHECK:STDOUT: %ReturnsRValue: %ReturnsRValue.type = struct_value () [concrete]
941
+ // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
942
+ // CHECK:STDOUT: %ReturnsRValue__carbon_thunk.type: type = fn_type @ReturnsRValue__carbon_thunk [concrete]
943
+ // CHECK:STDOUT: %ReturnsRValue__carbon_thunk: %ReturnsRValue__carbon_thunk.type = struct_value () [concrete]
930
944
// CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
931
945
// CHECK:STDOUT: %facet_value: %type_where = facet_value %S, () [concrete]
932
946
// CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.34a: type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
933
947
// CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.016: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.34a = struct_value () [concrete]
934
- // CHECK:STDOUT: %ptr.5c7: type = ptr_type %S [concrete]
935
948
// CHECK:STDOUT: }
936
949
// CHECK:STDOUT:
937
950
// CHECK:STDOUT: imports {
@@ -942,7 +955,7 @@ fn F() {
942
955
// CHECK:STDOUT: }
943
956
// CHECK:STDOUT: %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
944
957
// CHECK:STDOUT: %ReturnsRValue.cpp_overload_set.value: %ReturnsRValue.cpp_overload_set.type = cpp_overload_set_value @ReturnsRValue.cpp_overload_set [concrete = constants.%ReturnsRValue.cpp_overload_set.value]
945
- // CHECK:STDOUT: %ReturnsRValue .decl: %ReturnsRValue .type = fn_decl @ReturnsRValue [concrete = constants.%ReturnsRValue ] {
958
+ // CHECK:STDOUT: %ReturnsRValue__carbon_thunk .decl: %ReturnsRValue__carbon_thunk .type = fn_decl @ReturnsRValue__carbon_thunk [concrete = constants.%ReturnsRValue__carbon_thunk ] {
946
959
// CHECK:STDOUT: <elided>
947
960
// CHECK:STDOUT: } {
948
961
// CHECK:STDOUT: <elided>
@@ -956,41 +969,45 @@ fn F() {
956
969
// CHECK:STDOUT: %s.var_patt: %pattern_type.7da = var_pattern %s.patt [concrete]
957
970
// CHECK:STDOUT: }
958
971
// CHECK:STDOUT: %s.var: ref %S = var %s.var_patt
959
- // CHECK:STDOUT: %Cpp.ref.loc16_18 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
972
+ // CHECK:STDOUT: %Cpp.ref.loc8_18 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
960
973
// CHECK:STDOUT: %ReturnsRValue.ref: %ReturnsRValue.cpp_overload_set.type = name_ref ReturnsRValue, imports.%ReturnsRValue.cpp_overload_set.value [concrete = constants.%ReturnsRValue.cpp_overload_set.value]
961
- // CHECK:STDOUT: %ReturnsRValue.call: init <error> = call imports.%ReturnsRValue.decl()
962
- // CHECK:STDOUT: assign %s.var, <error>
963
- // CHECK:STDOUT: %.loc16_13: type = splice_block %S.ref [concrete = constants.%S] {
964
- // CHECK:STDOUT: %Cpp.ref.loc16_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
974
+ // CHECK:STDOUT: %.loc8_3.1: ref %S = splice_block %s.var {}
975
+ // CHECK:STDOUT: %addr.loc8_36: %ptr.5c7 = addr_of %.loc8_3.1
976
+ // CHECK:STDOUT: %ReturnsRValue__carbon_thunk.call: init %empty_tuple.type = call imports.%ReturnsRValue__carbon_thunk.decl(%addr.loc8_36)
977
+ // CHECK:STDOUT: %.loc8_36: init %S = in_place_init %ReturnsRValue__carbon_thunk.call, %.loc8_3.1
978
+ // CHECK:STDOUT: assign %s.var, %.loc8_36
979
+ // CHECK:STDOUT: %.loc8_13: type = splice_block %S.ref [concrete = constants.%S] {
980
+ // CHECK:STDOUT: %Cpp.ref.loc8_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
965
981
// CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
966
982
// CHECK:STDOUT: }
967
983
// CHECK:STDOUT: %s: ref %S = bind_name s, %s.var
968
984
// CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%S, () [concrete = constants.%facet_value]
969
- // CHECK:STDOUT: %.loc16_3 : %type_where = converted constants.%S, %facet_value [concrete = constants.%facet_value]
985
+ // CHECK:STDOUT: %.loc8_3.2 : %type_where = converted constants.%S, %facet_value [concrete = constants.%facet_value]
970
986
// CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %s.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.016
971
987
// CHECK:STDOUT: <elided>
972
988
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %s.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
973
- // CHECK:STDOUT: %addr: %ptr.5c7 = addr_of %s.var
974
- // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr)
989
+ // CHECK:STDOUT: %addr.loc8_3 : %ptr.5c7 = addr_of %s.var
990
+ // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr.loc8_3 )
975
991
// CHECK:STDOUT: <elided>
976
992
// CHECK:STDOUT: }
977
993
// CHECK:STDOUT:
978
- // CHECK:STDOUT: --- fail_todo_call_return_const_lvalue_ref .carbon
994
+ // CHECK:STDOUT: --- call_return_const_lvalue_ref .carbon
979
995
// CHECK:STDOUT:
980
996
// CHECK:STDOUT: constants {
981
997
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
982
998
// CHECK:STDOUT: %S: type = class_type @S [concrete]
983
999
// CHECK:STDOUT: %const: type = const_type %S [concrete]
984
- // CHECK:STDOUT: %pattern_type.9be: type = pattern_type %const [concrete]
1000
+ // CHECK:STDOUT: %ptr.ff5: type = ptr_type %const [concrete]
1001
+ // CHECK:STDOUT: %pattern_type.32f: type = pattern_type %ptr.ff5 [concrete]
985
1002
// CHECK:STDOUT: %ReturnConstLValue.cpp_overload_set.type: type = cpp_overload_set_type @ReturnConstLValue.cpp_overload_set [concrete]
986
1003
// CHECK:STDOUT: %ReturnConstLValue.cpp_overload_set.value: %ReturnConstLValue.cpp_overload_set.type = cpp_overload_set_value @ReturnConstLValue.cpp_overload_set [concrete]
987
1004
// CHECK:STDOUT: %ReturnConstLValue.type: type = fn_type @ReturnConstLValue [concrete]
988
1005
// CHECK:STDOUT: %ReturnConstLValue: %ReturnConstLValue.type = struct_value () [concrete]
989
1006
// CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanDestroy>> [concrete]
990
- // CHECK:STDOUT: %facet_value: %type_where = facet_value %const , () [concrete]
991
- // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.56e : type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
992
- // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.089 : %DestroyT.binding.as_type.as.Destroy.impl.Op.type.56e = struct_value () [concrete]
993
- // CHECK:STDOUT: %ptr.ff5 : type = ptr_type %const [concrete]
1007
+ // CHECK:STDOUT: %facet_value: %type_where = facet_value %ptr.ff5 , () [concrete]
1008
+ // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.type.40d : type = fn_type @DestroyT.binding.as_type.as.Destroy.impl.Op, @DestroyT.binding.as_type.as.Destroy.impl(%facet_value) [concrete]
1009
+ // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.c44 : %DestroyT.binding.as_type.as.Destroy.impl.Op.type.40d = struct_value () [concrete]
1010
+ // CHECK:STDOUT: %ptr.dec : type = ptr_type %ptr.ff5 [concrete]
994
1011
// CHECK:STDOUT: }
995
1012
// CHECK:STDOUT:
996
1013
// CHECK:STDOUT: imports {
@@ -1011,26 +1028,27 @@ fn F() {
1011
1028
// CHECK:STDOUT: fn @F() {
1012
1029
// CHECK:STDOUT: !entry:
1013
1030
// CHECK:STDOUT: name_binding_decl {
1014
- // CHECK:STDOUT: %s.patt: %pattern_type.9be = binding_pattern s [concrete]
1015
- // CHECK:STDOUT: %s.var_patt: %pattern_type.9be = var_pattern %s.patt [concrete]
1031
+ // CHECK:STDOUT: %s.patt: %pattern_type.32f = binding_pattern s [concrete]
1032
+ // CHECK:STDOUT: %s.var_patt: %pattern_type.32f = var_pattern %s.patt [concrete]
1016
1033
// CHECK:STDOUT: }
1017
- // CHECK:STDOUT: %s.var: ref %const = var %s.var_patt
1018
- // CHECK:STDOUT: %Cpp.ref.loc16_24 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
1034
+ // CHECK:STDOUT: %s.var: ref %ptr.ff5 = var %s.var_patt
1035
+ // CHECK:STDOUT: %Cpp.ref.loc8_25 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
1019
1036
// CHECK:STDOUT: %ReturnConstLValue.ref: %ReturnConstLValue.cpp_overload_set.type = name_ref ReturnConstLValue, imports.%ReturnConstLValue.cpp_overload_set.value [concrete = constants.%ReturnConstLValue.cpp_overload_set.value]
1020
- // CHECK:STDOUT: %ReturnConstLValue.call: init <error> = call imports.%ReturnConstLValue.decl()
1021
- // CHECK:STDOUT: assign %s.var, <error>
1022
- // CHECK:STDOUT: %.loc16_10 : type = splice_block %const [concrete = constants.%const ] {
1023
- // CHECK:STDOUT: %Cpp.ref.loc16_16 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
1037
+ // CHECK:STDOUT: %ReturnConstLValue.call: init %ptr.ff5 = call imports.%ReturnConstLValue.decl()
1038
+ // CHECK:STDOUT: assign %s.var, %ReturnConstLValue.call
1039
+ // CHECK:STDOUT: %.loc8_21 : type = splice_block %ptr [concrete = constants.%ptr.ff5 ] {
1040
+ // CHECK:STDOUT: %Cpp.ref.loc8_16 : <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
1024
1041
// CHECK:STDOUT: %S.ref: type = name_ref S, imports.%S.decl [concrete = constants.%S]
1025
1042
// CHECK:STDOUT: %const: type = const_type %S.ref [concrete = constants.%const]
1043
+ // CHECK:STDOUT: %ptr: type = ptr_type %const [concrete = constants.%ptr.ff5]
1026
1044
// CHECK:STDOUT: }
1027
- // CHECK:STDOUT: %s: ref %const = bind_name s, %s.var
1028
- // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%const , () [concrete = constants.%facet_value]
1029
- // CHECK:STDOUT: %.loc16_3 : %type_where = converted constants.%const , %facet_value [concrete = constants.%facet_value]
1030
- // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %s.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.089
1045
+ // CHECK:STDOUT: %s: ref %ptr.ff5 = bind_name s, %s.var
1046
+ // CHECK:STDOUT: %facet_value: %type_where = facet_value constants.%ptr.ff5 , () [concrete = constants.%facet_value]
1047
+ // CHECK:STDOUT: %.loc8_3 : %type_where = converted constants.%ptr.ff5 , %facet_value [concrete = constants.%facet_value]
1048
+ // CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.bound: <bound method> = bound_method %s.var, constants.%DestroyT.binding.as_type.as.Destroy.impl.Op.c44
1031
1049
// CHECK:STDOUT: <elided>
1032
1050
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %s.var, %DestroyT.binding.as_type.as.Destroy.impl.Op.specific_fn
1033
- // CHECK:STDOUT: %addr: %ptr.ff5 = addr_of %s.var
1051
+ // CHECK:STDOUT: %addr: %ptr.dec = addr_of %s.var
1034
1052
// CHECK:STDOUT: %DestroyT.binding.as_type.as.Destroy.impl.Op.call: init %empty_tuple.type = call %bound_method(%addr)
1035
1053
// CHECK:STDOUT: <elided>
1036
1054
// CHECK:STDOUT: }
0 commit comments