diff --git a/toolchain/check/testdata/interop/cpp/function/param_int16.carbon b/toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon similarity index 83% rename from toolchain/check/testdata/interop/cpp/function/param_int16.carbon rename to toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon index b407fdf8cee1..e23891b9ea84 100644 --- a/toolchain/check/testdata/interop/cpp/function/param_int16.carbon +++ b/toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon @@ -6,23 +6,23 @@ // // AUTOUPDATE // TIP: To test this file alone, run: -// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/param_int16.carbon +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon // TIP: To dump output, run: -// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/param_int16.carbon +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon // ============================================================================ -// short +// short param // ============================================================================ -// --- short.h +// --- short_param.h auto foo(short a) -> void; -// --- import_short.carbon +// --- import_short_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "short.h"; +import Cpp library "short_param.h"; fn F() { //@dump-sem-ir-begin @@ -30,11 +30,11 @@ fn F() { //@dump-sem-ir-end } -// --- import_short_max.carbon +// --- import_short_param_max.carbon library "[[@TEST_NAME]]"; -import Cpp library "short.h"; +import Cpp library "short_param.h"; fn F() { //@dump-sem-ir-begin @@ -42,26 +42,26 @@ fn F() { //@dump-sem-ir-end } -// --- fail_import_short_overflow_max.carbon +// --- fail_import_short_param_overflow_max.carbon library "[[@TEST_NAME]]"; -import Cpp library "short.h"; +import Cpp library "short_param.h"; fn F() { - // CHECK:STDERR: fail_import_short_overflow_max.carbon:[[@LINE+5]]:11: error: integer value 32768 too large for type `i16` [IntTooLargeForType] + // CHECK:STDERR: fail_import_short_param_overflow_max.carbon:[[@LINE+5]]:11: error: integer value 32768 too large for type `i16` [IntTooLargeForType] // CHECK:STDERR: Cpp.foo(0x8000); // CHECK:STDERR: ^~~~~~ - // CHECK:STDERR: fail_import_short_overflow_max.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_import_short_param_overflow_max.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(0x8000); } -// --- import_short_min.carbon +// --- import_short_param_min.carbon library "[[@TEST_NAME]]"; -import Cpp library "short.h"; +import Cpp library "short_param.h"; fn F() { //@dump-sem-ir-begin @@ -69,52 +69,52 @@ fn F() { //@dump-sem-ir-end } -// --- fail_import_short_overflow_min.carbon +// --- fail_import_short_param_overflow_min.carbon library "[[@TEST_NAME]]"; -import Cpp library "short.h"; +import Cpp library "short_param.h"; fn F() { - // CHECK:STDERR: fail_import_short_overflow_min.carbon:[[@LINE+5]]:11: error: integer value -32769 too large for type `i16` [IntTooLargeForType] + // CHECK:STDERR: fail_import_short_param_overflow_min.carbon:[[@LINE+5]]:11: error: integer value -32769 too large for type `i16` [IntTooLargeForType] // CHECK:STDERR: Cpp.foo(-0x8001); // CHECK:STDERR: ^~~~~~~ - // CHECK:STDERR: fail_import_short_overflow_min.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_import_short_param_overflow_min.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(-0x8001); } -// --- fail_import_short_int32_arg.carbon +// --- fail_import_short_param_int32_arg.carbon library "[[@TEST_NAME]]"; -import Cpp library "short.h"; +import Cpp library "short_param.h"; fn F() { - // CHECK:STDERR: fail_import_short_int32_arg.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32` to `i16` [ConversionFailure] + // CHECK:STDERR: fail_import_short_param_int32_arg.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32` to `i16` [ConversionFailure] // CHECK:STDERR: Cpp.foo(1 as i32); // CHECK:STDERR: ^~~~~~~~ - // CHECK:STDERR: fail_import_short_int32_arg.carbon:[[@LINE+5]]:11: note: type `i32` does not implement interface `Core.ImplicitAs(i16)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: fail_import_short_param_int32_arg.carbon:[[@LINE+5]]:11: note: type `i32` does not implement interface `Core.ImplicitAs(i16)` [MissingImplInMemberAccessNote] // CHECK:STDERR: Cpp.foo(1 as i32); // CHECK:STDERR: ^~~~~~~~ - // CHECK:STDERR: fail_import_short_int32_arg.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_import_short_param_int32_arg.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(1 as i32); } // ============================================================================ -// short int +// short int param // ============================================================================ -// --- short_int.h +// --- short_int_param.h auto foo(short int a) -> void; -// --- import_short_int.carbon +// --- import_short_int_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "short_int.h"; +import Cpp library "short_int_param.h"; fn F() { //@dump-sem-ir-begin @@ -123,18 +123,18 @@ fn F() { } // ============================================================================ -// signed short +// signed short param // ============================================================================ -// --- signed_short.h +// --- signed_short_param.h auto foo(signed short a) -> void; -// --- import_signed_short.carbon +// --- import_signed_short_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "signed_short.h"; +import Cpp library "signed_short_param.h"; fn F() { //@dump-sem-ir-begin @@ -143,18 +143,18 @@ fn F() { } // ============================================================================ -// signed short int +// signed short int param // ============================================================================ -// --- signed_short_int.h +// --- signed_short_int_param.h auto foo(signed short int a) -> void; -// --- import_signed_short_int.carbon +// --- import_signed_short_int_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "signed_short_int.h"; +import Cpp library "signed_short_int_param.h"; fn F() { //@dump-sem-ir-begin @@ -163,10 +163,10 @@ fn F() { } // ============================================================================ -// typedef for short +// typedef for short param // ============================================================================ -// --- int16_t.h +// --- int16_t_param.h namespace std { // Mimicking glibc definition for int16_t: https://codebrowser.dev/glibc/glibc/posix/bits/types.h.html#__int16_t @@ -175,11 +175,11 @@ namespace std { auto foo(std::int16_t a) -> void; -// --- import_int16_t.carbon +// --- import_int16_t_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "int16_t.h"; +import Cpp library "int16_t_param.h"; fn F() { //@dump-sem-ir-begin @@ -188,54 +188,54 @@ fn F() { } // ============================================================================ -// const short +// const short param // ============================================================================ -// --- const_short.h +// --- const_short_param.h auto foo(const short a) -> void; -// --- fail_todo_import_const_short.carbon +// --- fail_todo_import_const_short_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "const_short.h"; +import Cpp library "const_short_param.h"; fn F() { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_const_short.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i16` to `const i16` [ConversionFailure] + // CHECK:STDERR: fail_todo_import_const_short_param.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i16` to `const i16` [ConversionFailure] // CHECK:STDERR: Cpp.foo(1 as i16); // CHECK:STDERR: ^~~~~~~~ - // CHECK:STDERR: fail_todo_import_const_short.carbon:[[@LINE+5]]:11: note: type `i16` does not implement interface `Core.ImplicitAs(const i16)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: fail_todo_import_const_short_param.carbon:[[@LINE+5]]:11: note: type `i16` does not implement interface `Core.ImplicitAs(const i16)` [MissingImplInMemberAccessNote] // CHECK:STDERR: Cpp.foo(1 as i16); // CHECK:STDERR: ^~~~~~~~ - // CHECK:STDERR: fail_todo_import_const_short.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_todo_import_const_short_param.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(1 as i16); //@dump-sem-ir-end } // ============================================================================ -// short reference +// short reference param // ============================================================================ -// --- short_ref.h +// --- short_ref_param.h auto foo(short& a) -> void; -// --- fail_todo_import_short_ref.carbon +// --- fail_todo_import_short_ref_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "short_ref.h"; +import Cpp library "short_ref_param.h"; fn F() { var a: i16 = 1; //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_short_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: short &` [SemanticsTodo] + // CHECK:STDERR: fail_todo_import_short_ref_param.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: short &` [SemanticsTodo] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ - // CHECK:STDERR: fail_todo_import_short_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: fail_todo_import_short_ref_param.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: @@ -244,26 +244,26 @@ fn F() { } // ============================================================================ -// const short reference +// const short reference param // ============================================================================ -// --- const_short_ref.h +// --- const_short_ref_param.h auto foo(const short& a) -> void; -// --- fail_todo_import_const_short_ref.carbon +// --- fail_todo_import_const_short_ref_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "const_short_ref.h"; +import Cpp library "const_short_ref_param.h"; fn F() { var a: i16 = 1; //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_const_short_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: const short &` [SemanticsTodo] + // CHECK:STDERR: fail_todo_import_const_short_ref_param.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: const short &` [SemanticsTodo] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ - // CHECK:STDERR: fail_todo_import_const_short_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: fail_todo_import_const_short_ref_param.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: @@ -272,18 +272,18 @@ fn F() { } // ============================================================================ -// short pointer +// short pointer param // ============================================================================ -// --- short_pointer.h +// --- short_pointer_param.h auto foo(short* _Nonnull a) -> void; -// --- import_short_pointer.carbon +// --- import_short_pointer_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "short_pointer.h"; +import Cpp library "short_pointer_param.h"; fn F() { var a: i16 = 1; @@ -293,35 +293,82 @@ fn F() { } // ============================================================================ -// const short pointer +// const short pointer param // ============================================================================ -// --- const_short_pointer.h +// --- const_short_pointer_param.h auto foo(const short* _Nonnull a) -> void; -// --- fail_todo_import_const_short_pointer.carbon +// --- fail_todo_import_const_short_pointer_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "const_short_pointer.h"; +import Cpp library "const_short_pointer_param.h"; fn F() { var a: i16 = 1; //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_const_short_pointer.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i16*` to `const i16*` [ConversionFailure] + // CHECK:STDERR: fail_todo_import_const_short_pointer_param.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i16*` to `const i16*` [ConversionFailure] // CHECK:STDERR: Cpp.foo(&a); // CHECK:STDERR: ^~ - // CHECK:STDERR: fail_todo_import_const_short_pointer.carbon:[[@LINE+5]]:11: note: type `i16*` does not implement interface `Core.ImplicitAs(const i16*)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: fail_todo_import_const_short_pointer_param.carbon:[[@LINE+5]]:11: note: type `i16*` does not implement interface `Core.ImplicitAs(const i16*)` [MissingImplInMemberAccessNote] // CHECK:STDERR: Cpp.foo(&a); // CHECK:STDERR: ^~ - // CHECK:STDERR: fail_todo_import_const_short_pointer.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_todo_import_const_short_pointer_param.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(&a); //@dump-sem-ir-end } -// CHECK:STDOUT: --- import_short.carbon +// ============================================================================ +// short return +// ============================================================================ + +// --- short_return.h + +auto foo_short() -> short; + +// --- import_short_return.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_return.h"; + +fn F() { + //@dump-sem-ir-begin + let x: i16 = Cpp.foo_short(); + //@dump-sem-ir-end +} + +// ============================================================================ +// float return +// ============================================================================ + +// --- float_return.h + +auto foo_float() -> float; + +// --- fail_todo_import_float_return.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "float_return.h"; + +fn F() { + //@dump-sem-ir-begin + // CHECK:STDERR: fail_todo_import_float_return.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: return type: float` [SemanticsTodo] + // CHECK:STDERR: Cpp.foo_float(); + // CHECK:STDERR: ^~~~~~~~~~~~~ + // CHECK:STDERR: fail_todo_import_float_return.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo_float` [InCppNameLookup] + // CHECK:STDERR: Cpp.foo_float(); + // CHECK:STDERR: ^~~~~~~~~~~~~ + // CHECK:STDERR: + Cpp.foo_float(); + //@dump-sem-ir-end +} + +// CHECK:STDOUT: --- import_short_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -378,7 +425,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_short_max.carbon +// CHECK:STDOUT: --- import_short_param_max.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -433,7 +480,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_short_min.carbon +// CHECK:STDOUT: --- import_short_param_min.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -505,7 +552,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_short_int.carbon +// CHECK:STDOUT: --- import_short_int_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -562,7 +609,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_signed_short.carbon +// CHECK:STDOUT: --- import_signed_short_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -619,7 +666,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_signed_short_int.carbon +// CHECK:STDOUT: --- import_signed_short_int_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -676,7 +723,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_int16_t.carbon +// CHECK:STDOUT: --- import_int16_t_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -733,7 +780,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_const_short.carbon +// CHECK:STDOUT: --- fail_todo_import_const_short_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -792,7 +839,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_short_ref.carbon +// CHECK:STDOUT: --- fail_todo_import_short_ref_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] @@ -815,7 +862,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_const_short_ref.carbon +// CHECK:STDOUT: --- fail_todo_import_const_short_ref_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] @@ -838,7 +885,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_short_pointer.carbon +// CHECK:STDOUT: --- import_short_pointer_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -872,7 +919,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_const_short_pointer.carbon +// CHECK:STDOUT: --- fail_todo_import_const_short_pointer_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -909,3 +956,62 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_return.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %pattern_type.2f8: type = pattern_type %i16 [concrete] +// CHECK:STDOUT: %foo_short.type: type = fn_type @foo_short [concrete] +// CHECK:STDOUT: %foo_short: %foo_short.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo_short = %foo_short.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: %foo_short.decl: %foo_short.type = fn_decl @foo_short [concrete = constants.%foo_short] { +// CHECK:STDOUT: +// CHECK:STDOUT: } { +// CHECK:STDOUT: +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %x.patt: %pattern_type.2f8 = binding_pattern x [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %foo_short.ref: %foo_short.type = name_ref foo_short, imports.%foo_short.decl [concrete = constants.%foo_short] +// CHECK:STDOUT: %foo_short.call: init %i16 = call %foo_short.ref() +// CHECK:STDOUT: %.loc8_10: type = splice_block %i16 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %.loc8_30.1: %i16 = value_of_initializer %foo_short.call +// CHECK:STDOUT: %.loc8_30.2: %i16 = converted %foo_short.call, %.loc8_30.1 +// CHECK:STDOUT: %x: %i16 = bind_name x, %.loc8_30.2 +// CHECK:STDOUT: +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_todo_import_float_return.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo_float = +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %foo_float.ref: = name_ref foo_float, [concrete = ] +// CHECK:STDOUT: +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/function/param_int32.carbon b/toolchain/check/testdata/interop/cpp/function/arithmetic_types_mapped.carbon similarity index 89% rename from toolchain/check/testdata/interop/cpp/function/param_int32.carbon rename to toolchain/check/testdata/interop/cpp/function/arithmetic_types_mapped.carbon index b14aa1ae6b02..89c5a97e2d4c 100644 --- a/toolchain/check/testdata/interop/cpp/function/param_int32.carbon +++ b/toolchain/check/testdata/interop/cpp/function/arithmetic_types_mapped.carbon @@ -6,33 +6,33 @@ // // AUTOUPDATE // TIP: To test this file alone, run: -// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/param_int32.carbon +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/arithmetic_types_mapped.carbon // TIP: To dump output, run: -// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/param_int32.carbon +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/arithmetic_types_mapped.carbon // ============================================================================ -// int +// int param // ============================================================================ -// --- int.h +// --- int_param.h auto foo(int a) -> void; -// --- import_int.carbon +// --- import_int_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "int.h"; +import Cpp library "int_param.h"; fn F() { Cpp.foo(1); } -// --- import_int_max.carbon +// --- import_int_param_max.carbon library "[[@TEST_NAME]]"; -import Cpp library "int.h"; +import Cpp library "int_param.h"; fn F() { //@dump-sem-ir-begin @@ -40,26 +40,26 @@ fn F() { //@dump-sem-ir-end } -// --- fail_import_int_overflow_max.carbon +// --- fail_import_int_param_overflow_max.carbon library "[[@TEST_NAME]]"; -import Cpp library "int.h"; +import Cpp library "int_param.h"; fn F() { - // CHECK:STDERR: fail_import_int_overflow_max.carbon:[[@LINE+5]]:11: error: integer value 2147483648 too large for type `i32` [IntTooLargeForType] + // CHECK:STDERR: fail_import_int_param_overflow_max.carbon:[[@LINE+5]]:11: error: integer value 2147483648 too large for type `i32` [IntTooLargeForType] // CHECK:STDERR: Cpp.foo(0x8000_0000); // CHECK:STDERR: ^~~~~~~~~~~ - // CHECK:STDERR: fail_import_int_overflow_max.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_import_int_param_overflow_max.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(0x8000_0000); } -// --- import_int_min.carbon +// --- import_int_param_min.carbon library "[[@TEST_NAME]]"; -import Cpp library "int.h"; +import Cpp library "int_param.h"; fn F() { //@dump-sem-ir-begin @@ -67,34 +67,34 @@ fn F() { //@dump-sem-ir-end } -// --- fail_import_int_overflow_min.carbon +// --- fail_import_int_param_overflow_min.carbon library "[[@TEST_NAME]]"; -import Cpp library "int.h"; +import Cpp library "int_param.h"; fn F() { - // CHECK:STDERR: fail_import_int_overflow_min.carbon:[[@LINE+5]]:11: error: integer value -2147483649 too large for type `i32` [IntTooLargeForType] + // CHECK:STDERR: fail_import_int_param_overflow_min.carbon:[[@LINE+5]]:11: error: integer value -2147483649 too large for type `i32` [IntTooLargeForType] // CHECK:STDERR: Cpp.foo(-0x8000_0001); // CHECK:STDERR: ^~~~~~~~~~~~ - // CHECK:STDERR: fail_import_int_overflow_min.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_import_int_param_overflow_min.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(-0x8000_0001); } // ============================================================================ -// signed int +// signed int param // ============================================================================ -// --- signed_int.h +// --- signed_int_param.h auto foo(signed int a) -> void; -// --- import_signed_int.carbon +// --- import_signed_int_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "signed_int.h"; +import Cpp library "signed_int_param.h"; fn F() { //@dump-sem-ir-begin @@ -103,18 +103,18 @@ fn F() { } // ============================================================================ -// signed +// signed param // ============================================================================ -// --- signed.h +// --- signed_param.h auto foo(signed a) -> void; -// --- import_signed.carbon +// --- import_signed_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "signed.h"; +import Cpp library "signed_param.h"; fn F() { //@dump-sem-ir-begin @@ -123,10 +123,10 @@ fn F() { } // ============================================================================ -// typedef for int +// typedef for int param // ============================================================================ -// --- int32_t.h +// --- int32_t_param.h namespace std { // Mimicking glibc definition for int32_t: https://codebrowser.dev/glibc/glibc/posix/bits/types.h.html#__int32_t @@ -135,11 +135,11 @@ namespace std { auto foo(std::int32_t a) -> void; -// --- import_int32_t.carbon +// --- import_int32_t_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "int32_t.h"; +import Cpp library "int32_t_param.h"; fn F() { //@dump-sem-ir-begin @@ -148,18 +148,18 @@ fn F() { } // ============================================================================ -// ints +// int params // ============================================================================ -// --- ints.h +// --- int_params.h auto foo(int a, int b) -> void; -// --- import_ints.carbon +// --- import_int_params.carbon library "[[@TEST_NAME]]"; -import Cpp library "ints.h"; +import Cpp library "int_params.h"; fn F() { //@dump-sem-ir-begin @@ -168,20 +168,20 @@ fn F() { } // ============================================================================ -// Multiple ints +// Multiple function with int params // ============================================================================ -// --- multiple_ints.h +// --- multiple_int_params.h auto foo1(int a, int b) -> void; auto foo2(int c, int b) -> void; -// --- import_multiple_ints.carbon +// --- import_multiple_int_params.carbon library "[[@TEST_NAME]]"; -import Cpp library "multiple_ints.h"; +import Cpp library "multiple_int_params.h"; fn F() { //@dump-sem-ir-begin @@ -191,18 +191,18 @@ fn F() { } // ============================================================================ -// Unnamed int +// Unnamed int param // ============================================================================ -// --- unnamed_int.h +// --- unnamed_int_param.h auto foo(int) -> void; -// --- import_unnamed_int.carbon +// --- import_unnamed_int_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "unnamed_int.h"; +import Cpp library "unnamed_int_param.h"; fn F() { //@dump-sem-ir-begin @@ -211,10 +211,10 @@ fn F() { } // ============================================================================ -// int default +// int default param // ============================================================================ -// --- int_default.h +// --- int_default_param.h auto foo(int a = 0) -> void; @@ -222,7 +222,7 @@ auto foo(int a = 0) -> void; library "[[@TEST_NAME]]"; -import Cpp library "int_default.h"; +import Cpp library "int_default_param.h"; fn F() { //@dump-sem-ir-begin @@ -235,11 +235,11 @@ fn F() { //@dump-sem-ir-end } -// --- import_int_default_sucessful_call.carbon +// --- import_int_default_param_sucessful_call.carbon library "[[@TEST_NAME]]"; -import Cpp library "int_default.h"; +import Cpp library "int_default_param.h"; fn F() { //@dump-sem-ir-begin @@ -248,54 +248,54 @@ fn F() { } // ============================================================================ -// const int +// const int param // ============================================================================ -// --- const_int.h +// --- const_int_param.h auto foo(const int a) -> void; -// --- fail_todo_import_const_int.carbon +// --- fail_todo_import_const_int_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "const_int.h"; +import Cpp library "const_int_param.h"; fn F() { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_const_int.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `Core.IntLiteral` to `const i32` [ConversionFailure] + // CHECK:STDERR: fail_todo_import_const_int_param.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `Core.IntLiteral` to `const i32` [ConversionFailure] // CHECK:STDERR: Cpp.foo(1); // CHECK:STDERR: ^ - // CHECK:STDERR: fail_todo_import_const_int.carbon:[[@LINE+5]]:11: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(const i32)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: fail_todo_import_const_int_param.carbon:[[@LINE+5]]:11: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(const i32)` [MissingImplInMemberAccessNote] // CHECK:STDERR: Cpp.foo(1); // CHECK:STDERR: ^ - // CHECK:STDERR: fail_todo_import_const_int.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_todo_import_const_int_param.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(1); //@dump-sem-ir-end } // ============================================================================ -// int reference +// int reference param // ============================================================================ -// --- int_ref.h +// --- int_ref_param.h auto foo(int& a) -> int; -// --- fail_todo_import_int_ref.carbon +// --- fail_todo_import_int_ref_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "int_ref.h"; +import Cpp library "int_ref_param.h"; fn F() { var a: i32 = 1; //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_int_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: int &` [SemanticsTodo] + // CHECK:STDERR: fail_todo_import_int_ref_param.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: int &` [SemanticsTodo] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ - // CHECK:STDERR: fail_todo_import_int_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: fail_todo_import_int_ref_param.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: @@ -304,26 +304,26 @@ fn F() { } // ============================================================================ -// const int reference +// const int reference param // ============================================================================ -// --- const_int_ref.h +// --- const_int_ref_param.h auto foo(const int& a) -> int; -// --- fail_todo_import_const_int_ref.carbon +// --- fail_todo_import_const_int_ref_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "const_int_ref.h"; +import Cpp library "const_int_ref_param.h"; fn F() { var a : i32 = 1; //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_const_int_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: const int &` [SemanticsTodo] + // CHECK:STDERR: fail_todo_import_const_int_ref_param.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: const int &` [SemanticsTodo] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ - // CHECK:STDERR: fail_todo_import_const_int_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: fail_todo_import_const_int_ref_param.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] // CHECK:STDERR: Cpp.foo(a); // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: @@ -332,18 +332,18 @@ fn F() { } // ============================================================================ -// int pointer +// int pointer param // ============================================================================ -// --- int_pointer.h +// --- int_pointer_param.h auto foo(int* _Nonnull a) -> void; -// --- import_int_pointer.carbon +// --- import_int_pointer_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "int_pointer.h"; +import Cpp library "int_pointer_param.h"; fn F() { var a: i32 = 1; @@ -353,35 +353,57 @@ fn F() { } // ============================================================================ -// const int pointer +// const int pointer param // ============================================================================ -// --- const_int_pointer.h +// --- const_int_pointer_param.h auto foo(const int* _Nonnull a) -> int; -// --- fail_todo_import_const_int_pointer.carbon +// --- fail_todo_import_const_int_pointer_param.carbon library "[[@TEST_NAME]]"; -import Cpp library "const_int_pointer.h"; +import Cpp library "const_int_pointer_param.h"; fn F() { var a : i32 = 1; //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_const_int_pointer.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32*` to `const i32*` [ConversionFailure] + // CHECK:STDERR: fail_todo_import_const_int_pointer_param.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32*` to `const i32*` [ConversionFailure] // CHECK:STDERR: Cpp.foo(&a); // CHECK:STDERR: ^~ - // CHECK:STDERR: fail_todo_import_const_int_pointer.carbon:[[@LINE+5]]:11: note: type `i32*` does not implement interface `Core.ImplicitAs(const i32*)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: fail_todo_import_const_int_pointer_param.carbon:[[@LINE+5]]:11: note: type `i32*` does not implement interface `Core.ImplicitAs(const i32*)` [MissingImplInMemberAccessNote] // CHECK:STDERR: Cpp.foo(&a); // CHECK:STDERR: ^~ - // CHECK:STDERR: fail_todo_import_const_int_pointer.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: fail_todo_import_const_int_pointer_param.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: Cpp.foo(&a); //@dump-sem-ir-end } -// CHECK:STDOUT: --- import_int_max.carbon +// ============================================================================ +// int return +// ============================================================================ + +// --- int_return.h + +auto foo_int() -> int; + +// --- import_int_return.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "int_return.h"; + +fn Carbon_foo(val: i32); + +fn F() { + //@dump-sem-ir-begin + Carbon_foo(Cpp.foo_int()); + //@dump-sem-ir-end +} + +// CHECK:STDOUT: --- import_int_param_max.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -436,7 +458,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_int_min.carbon +// CHECK:STDOUT: --- import_int_param_min.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -508,7 +530,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_signed_int.carbon +// CHECK:STDOUT: --- import_signed_int_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -563,7 +585,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_signed.carbon +// CHECK:STDOUT: --- import_signed_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -618,7 +640,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_int32_t.carbon +// CHECK:STDOUT: --- import_int32_t_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -673,7 +695,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_ints.carbon +// CHECK:STDOUT: --- import_int_params.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -740,7 +762,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_multiple_ints.carbon +// CHECK:STDOUT: --- import_multiple_int_params.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -842,7 +864,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_unnamed_int.carbon +// CHECK:STDOUT: --- import_unnamed_int_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -923,7 +945,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_int_default_sucessful_call.carbon +// CHECK:STDOUT: --- import_int_default_param_sucessful_call.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -978,7 +1000,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_const_int.carbon +// CHECK:STDOUT: --- fail_todo_import_const_int_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -1012,7 +1034,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_int_ref.carbon +// CHECK:STDOUT: --- fail_todo_import_int_ref_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] @@ -1035,7 +1057,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_const_int_ref.carbon +// CHECK:STDOUT: --- fail_todo_import_const_int_ref_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] @@ -1058,7 +1080,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- import_int_pointer.carbon +// CHECK:STDOUT: --- import_int_pointer_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] @@ -1092,7 +1114,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_const_int_pointer.carbon +// CHECK:STDOUT: --- fail_todo_import_const_int_pointer_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] @@ -1128,3 +1150,39 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: --- import_int_return.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] +// CHECK:STDOUT: %Carbon_foo.type: type = fn_type @Carbon_foo [concrete] +// CHECK:STDOUT: %Carbon_foo: %Carbon_foo.type = struct_value () [concrete] +// CHECK:STDOUT: %foo_int.type: type = fn_type @foo_int [concrete] +// CHECK:STDOUT: %foo_int: %foo_int.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo_int = %foo_int.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: %foo_int.decl: %foo_int.type = fn_decl @foo_int [concrete = constants.%foo_int] { +// CHECK:STDOUT: +// CHECK:STDOUT: } { +// CHECK:STDOUT: +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %Carbon_foo.ref: %Carbon_foo.type = name_ref Carbon_foo, file.%Carbon_foo.decl [concrete = constants.%Carbon_foo] +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %foo_int.ref: %foo_int.type = name_ref foo_int, imports.%foo_int.decl [concrete = constants.%foo_int] +// CHECK:STDOUT: %foo_int.call: init %i32 = call %foo_int.ref() +// CHECK:STDOUT: %.loc10_26.1: %i32 = value_of_initializer %foo_int.call +// CHECK:STDOUT: %.loc10_26.2: %i32 = converted %foo_int.call, %.loc10_26.1 +// CHECK:STDOUT: %Carbon_foo.call: init %empty_tuple.type = call %Carbon_foo.ref(%.loc10_26.2) +// CHECK:STDOUT: +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/function/return.carbon b/toolchain/check/testdata/interop/cpp/function/return.carbon index dbcd9ba1141d..0e4869f8aa1a 100644 --- a/toolchain/check/testdata/interop/cpp/function/return.carbon +++ b/toolchain/check/testdata/interop/cpp/function/return.carbon @@ -10,48 +10,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/return.carbon -// ============================================================================ -// short -// ============================================================================ - -// --- short.h - -auto foo_short() -> short; - -// --- import_short.carbon - -library "[[@TEST_NAME]]"; - -import Cpp library "short.h"; - -fn F() { - //@dump-sem-ir-begin - let x: i16 = Cpp.foo_short(); - //@dump-sem-ir-end -} - -// ============================================================================ -// int -// ============================================================================ - -// --- int.h - -auto foo_int() -> int; - -// --- import_int.carbon - -library "[[@TEST_NAME]]"; - -import Cpp library "int.h"; - -fn Carbon_foo(val: i32); - -fn F() { - //@dump-sem-ir-begin - Carbon_foo(Cpp.foo_int()); - //@dump-sem-ir-end -} - // ============================================================================ // Multiple function with a return value // ============================================================================ @@ -77,109 +35,6 @@ fn F() { //@dump-sem-ir-end } -// ============================================================================ -// float -// ============================================================================ - -// --- float.h - -auto foo_float() -> float; - -// --- fail_todo_import_float.carbon - -library "[[@TEST_NAME]]"; - -import Cpp library "float.h"; - -fn F() { - //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_import_float.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: return type: float` [SemanticsTodo] - // CHECK:STDERR: Cpp.foo_float(); - // CHECK:STDERR: ^~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_import_float.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo_float` [InCppNameLookup] - // CHECK:STDERR: Cpp.foo_float(); - // CHECK:STDERR: ^~~~~~~~~~~~~ - // CHECK:STDERR: - Cpp.foo_float(); - //@dump-sem-ir-end -} - -// CHECK:STDOUT: --- import_short.carbon -// CHECK:STDOUT: -// CHECK:STDOUT: constants { -// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] -// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] -// CHECK:STDOUT: %pattern_type.2f8: type = pattern_type %i16 [concrete] -// CHECK:STDOUT: %foo_short.type: type = fn_type @foo_short [concrete] -// CHECK:STDOUT: %foo_short: %foo_short.type = struct_value () [concrete] -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: imports { -// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo_short = %foo_short.decl -// CHECK:STDOUT: import Cpp//... -// CHECK:STDOUT: } -// CHECK:STDOUT: %foo_short.decl: %foo_short.type = fn_decl @foo_short [concrete = constants.%foo_short] { -// CHECK:STDOUT: -// CHECK:STDOUT: } { -// CHECK:STDOUT: -// CHECK:STDOUT: } -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: fn @F() { -// CHECK:STDOUT: !entry: -// CHECK:STDOUT: name_binding_decl { -// CHECK:STDOUT: %x.patt: %pattern_type.2f8 = binding_pattern x [concrete] -// CHECK:STDOUT: } -// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %foo_short.ref: %foo_short.type = name_ref foo_short, imports.%foo_short.decl [concrete = constants.%foo_short] -// CHECK:STDOUT: %foo_short.call: init %i16 = call %foo_short.ref() -// CHECK:STDOUT: %.loc8_10: type = splice_block %i16 [concrete = constants.%i16] { -// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] -// CHECK:STDOUT: } -// CHECK:STDOUT: %.loc8_30.1: %i16 = value_of_initializer %foo_short.call -// CHECK:STDOUT: %.loc8_30.2: %i16 = converted %foo_short.call, %.loc8_30.1 -// CHECK:STDOUT: %x: %i16 = bind_name x, %.loc8_30.2 -// CHECK:STDOUT: -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: --- import_int.carbon -// CHECK:STDOUT: -// CHECK:STDOUT: constants { -// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] -// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] -// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] -// CHECK:STDOUT: %Carbon_foo.type: type = fn_type @Carbon_foo [concrete] -// CHECK:STDOUT: %Carbon_foo: %Carbon_foo.type = struct_value () [concrete] -// CHECK:STDOUT: %foo_int.type: type = fn_type @foo_int [concrete] -// CHECK:STDOUT: %foo_int: %foo_int.type = struct_value () [concrete] -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: imports { -// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo_int = %foo_int.decl -// CHECK:STDOUT: import Cpp//... -// CHECK:STDOUT: } -// CHECK:STDOUT: %foo_int.decl: %foo_int.type = fn_decl @foo_int [concrete = constants.%foo_int] { -// CHECK:STDOUT: -// CHECK:STDOUT: } { -// CHECK:STDOUT: -// CHECK:STDOUT: } -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: fn @F() { -// CHECK:STDOUT: !entry: -// CHECK:STDOUT: %Carbon_foo.ref: %Carbon_foo.type = name_ref Carbon_foo, file.%Carbon_foo.decl [concrete = constants.%Carbon_foo] -// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %foo_int.ref: %foo_int.type = name_ref foo_int, imports.%foo_int.decl [concrete = constants.%foo_int] -// CHECK:STDOUT: %foo_int.call: init %i32 = call %foo_int.ref() -// CHECK:STDOUT: %.loc10_26.1: %i32 = value_of_initializer %foo_int.call -// CHECK:STDOUT: %.loc10_26.2: %i32 = converted %foo_int.call, %.loc10_26.1 -// CHECK:STDOUT: %Carbon_foo.call: init %empty_tuple.type = call %Carbon_foo.ref(%.loc10_26.2) -// CHECK:STDOUT: -// CHECK:STDOUT: } -// CHECK:STDOUT: // CHECK:STDOUT: --- import_multiple.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { @@ -235,22 +90,3 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_import_float.carbon -// CHECK:STDOUT: -// CHECK:STDOUT: constants { -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: imports { -// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo_float = -// CHECK:STDOUT: import Cpp//... -// CHECK:STDOUT: } -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: fn @F() { -// CHECK:STDOUT: !entry: -// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %foo_float.ref: = name_ref foo_float, [concrete = ] -// CHECK:STDOUT: -// CHECK:STDOUT: } -// CHECK:STDOUT: