From 446e0f45db697afffe60df0f6a6921edceaadfba Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Wed, 30 Apr 2025 13:29:42 +0000 Subject: [PATCH 1/5] Add support for C++ type short --- toolchain/check/import_cpp.cpp | 27 +- .../testdata/interop/cpp/function_decl.carbon | 701 ++++++++++++++++++ 2 files changed, 720 insertions(+), 8 deletions(-) diff --git a/toolchain/check/import_cpp.cpp b/toolchain/check/import_cpp.cpp index ac53968d9d14c..401a7f6c2c28e 100644 --- a/toolchain/check/import_cpp.cpp +++ b/toolchain/check/import_cpp.cpp @@ -310,16 +310,27 @@ static auto MakeIntType(Context& context, IntId size_id) -> TypeExpr { return ExprAsType(context, Parse::NodeId::None, type_inst_id); } -// Maps a C++ type to a Carbon type. Currently only 32-bit `int` is supported. +// Maps a C++ type to a Carbon type. Currently only 32-bit `int` and `short` are +// supported. // TODO: Support more types. static auto MapType(Context& context, clang::QualType type) -> TypeExpr { const auto* builtin_type = dyn_cast(type); - if (builtin_type && builtin_type->getKind() == clang::BuiltinType::Int && - context.ast_context().getTypeSize(type) == 32) { - return MakeIntType(context, context.ints().Add(32)); + if (!builtin_type) { + return {.inst_id = SemIR::ErrorInst::TypeInstId, + .type_id = SemIR::ErrorInst::TypeId}; + } + switch (builtin_type->getKind()) { + case clang::BuiltinType::Short: + return MakeIntType(context, context.ints().Add(16)); + case clang::BuiltinType::Int: + if (context.ast_context().getTypeSize(type) == 32) { + return MakeIntType(context, context.ints().Add(32)); + } + [[fallthrough]]; + default: + return {.inst_id = SemIR::ErrorInst::TypeInstId, + .type_id = SemIR::ErrorInst::TypeId}; } - return {.inst_id = SemIR::ErrorInst::TypeInstId, - .type_id = SemIR::ErrorInst::TypeId}; } // Returns a block id for the explicit parameters of the given function @@ -466,8 +477,8 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id, return decl_id; } -// Imports a namespace declaration from Clang to Carbon. If successful, returns -// the new Carbon namespace declaration `InstId`. +// Imports a namespace declaration from Clang to Carbon. If successful, +// returns the new Carbon namespace declaration `InstId`. static auto ImportNamespaceDecl(Context& context, SemIR::NameScopeId parent_scope_id, SemIR::NameId name_id, diff --git a/toolchain/check/testdata/interop/cpp/function_decl.carbon b/toolchain/check/testdata/interop/cpp/function_decl.carbon index dc4867097bd8b..e288852de810a 100644 --- a/toolchain/check/testdata/interop/cpp/function_decl.carbon +++ b/toolchain/check/testdata/interop/cpp/function_decl.carbon @@ -8,6 +8,22 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function_decl.carbon +// --- short_return_function_decl.h + +auto foo_short() -> short; + +// --- import_short_return_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_return_function_decl.h"; + +fn Carbon_foo(val: i16); + +fn F() { + Carbon_foo(Cpp.foo_short()); +} + // --- int_return_function_decl.h auto foo_int() -> int; @@ -178,6 +194,108 @@ fn F() { Cpp.foo(&a); } +// --- short_param_function_decl.h + +auto foo(short a) -> void; + +// --- import_short_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + Cpp.foo(a); +} + +// --- short_int_param_function_decl.h + +auto foo(short int a) -> void; + +// --- import_short_int_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_int_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + Cpp.foo(a); +} + +// --- signed_short_param_function_decl.h + +auto foo(signed short a) -> void; + +// --- import_signed_short_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "signed_short_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + Cpp.foo(a); +} + +// --- signed_short_int_param_function_decl.h + +auto foo(signed short int a) -> void; + +// --- import_signed_short_int_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "signed_short_int_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + Cpp.foo(a); +} + +// --- int16_t_param_function_decl.h + +namespace std { + typedef signed short int int16_t; +} // namespace std + +auto foo(std::int16_t a) -> void; + +// --- import_int16_t_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "int16_t_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + Cpp.foo(a); +} + +// --- int32_arg_short_param_function_decl.h + +auto foo(short a) -> void; + +// --- fail_int32_arg_short_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "int32_arg_short_param_function_decl.h"; + +fn F() { + var a: i32 = 1; + // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32` to `i16` [ConversionFailure] + // CHECK:STDERR: Cpp.foo(a); + // CHECK:STDERR: ^ + // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+5]]:11: note: type `i32` does not implement interface `Core.ImplicitAs(i16)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: Cpp.foo(a); + // CHECK:STDERR: ^ + // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: + Cpp.foo(a); +} + // --- unsupported_primitive_type_param_function_decl.h auto foo(float a) -> void; @@ -220,6 +338,77 @@ fn F() { Cpp.foo(1, 2.0); } +// CHECK:STDOUT: --- import_short_return_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %pattern_type.2f8: type = pattern_type %i16 [concrete] +// CHECK:STDOUT: %Carbon_foo.type: type = fn_type @Carbon_foo [concrete] +// CHECK:STDOUT: %Carbon_foo: %Carbon_foo.type = struct_value () [concrete] +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [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: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo_short = @F.%foo_short.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .Carbon_foo = %Carbon_foo.decl +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_return_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %Carbon_foo.decl: %Carbon_foo.type = fn_decl @Carbon_foo [concrete = constants.%Carbon_foo] { +// CHECK:STDOUT: %val.patt: %pattern_type.2f8 = binding_pattern val +// CHECK:STDOUT: %val.param_patt: %pattern_type.2f8 = value_param_pattern %val.patt, call_param0 +// CHECK:STDOUT: } { +// CHECK:STDOUT: %val.param: %i16 = value_param call_param0 +// CHECK:STDOUT: %.loc6: 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: %val: %i16 = bind_name val, %val.param +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @Carbon_foo(%val.param: %i16); +// 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: %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: %foo_short.decl: %foo_short.type = fn_decl @foo_short [concrete = constants.%foo_short] {} {} +// CHECK:STDOUT: %foo_short.ref: %foo_short.type = name_ref foo_short, %foo_short.decl [concrete = constants.%foo_short] +// CHECK:STDOUT: %foo_short.call: init %i16 = call %foo_short.ref() +// CHECK:STDOUT: %.loc9_28.1: %i16 = value_of_initializer %foo_short.call +// CHECK:STDOUT: %.loc9_28.2: %i16 = converted %foo_short.call, %.loc9_28.1 +// CHECK:STDOUT: %Carbon_foo.call: init %empty_tuple.type = call %Carbon_foo.ref(%.loc9_28.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo_short(); +// CHECK:STDOUT: // CHECK:STDOUT: --- import_int_return_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { @@ -954,6 +1143,518 @@ fn F() { // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// 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: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt +// CHECK:STDOUT: } +// CHECK:STDOUT: %a.var: ref %i16 = var a +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: assign %a.var, %.loc7_3.2 +// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a +// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_int_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// 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: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_int_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt +// CHECK:STDOUT: } +// CHECK:STDOUT: %a.var: ref %i16 = var a +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: assign %a.var, %.loc7_3.2 +// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a +// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_signed_short_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// 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: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "signed_short_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt +// CHECK:STDOUT: } +// CHECK:STDOUT: %a.var: ref %i16 = var a +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: assign %a.var, %.loc7_3.2 +// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a +// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_signed_short_int_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// 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: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "signed_short_int_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt +// CHECK:STDOUT: } +// CHECK:STDOUT: %a.var: ref %i16 = var a +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: assign %a.var, %.loc7_3.2 +// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a +// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_int16_t_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// 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: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "int16_t_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt +// CHECK:STDOUT: } +// CHECK:STDOUT: %a.var: ref %i16 = var a +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: assign %a.var, %.loc7_3.2 +// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a +// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_int32_arg_short_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] +// CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete] +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete] +// CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.c75: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete] +// CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete] +// CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete] +// CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.956 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.956, @Convert.2(%int_32) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "int32_arg_short_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: name_binding_decl { +// CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.7ce = var_pattern %a.patt +// CHECK:STDOUT: } +// CHECK:STDOUT: %a.var: ref %i32 = var a +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956] +// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: %.loc7_3.2: init %i32 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: assign %a.var, %.loc7_3.2 +// CHECK:STDOUT: %.loc7_10: type = splice_block %i32 [concrete = constants.%i32] { +// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32] +// CHECK:STDOUT: } +// CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// 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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i32 = name_ref a, %a +// CHECK:STDOUT: %.loc16: %i16 = converted %a.ref, [concrete = ] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref() +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: // CHECK:STDOUT: --- fail_import_unsupported_primitive_type_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { From 72045c0773f4f79d9ae7bbbe2cf3e78c38aa51a8 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Mon, 5 May 2025 13:35:57 +0000 Subject: [PATCH 2/5] Apply review comments --- toolchain/check/import_cpp.cpp | 16 +- .../testdata/interop/cpp/function_decl.carbon | 223 +++++++++++++++--- 2 files changed, 204 insertions(+), 35 deletions(-) diff --git a/toolchain/check/import_cpp.cpp b/toolchain/check/import_cpp.cpp index 401a7f6c2c28e..ab94c12322722 100644 --- a/toolchain/check/import_cpp.cpp +++ b/toolchain/check/import_cpp.cpp @@ -310,8 +310,8 @@ static auto MakeIntType(Context& context, IntId size_id) -> TypeExpr { return ExprAsType(context, Parse::NodeId::None, type_inst_id); } -// Maps a C++ type to a Carbon type. Currently only 32-bit `int` and `short` are -// supported. +// Maps a C++ type to a Carbon type. Currently only 32-bit `int` and 16-bit +// `short` are supported. // TODO: Support more types. static auto MapType(Context& context, clang::QualType type) -> TypeExpr { const auto* builtin_type = dyn_cast(type); @@ -321,16 +321,20 @@ static auto MapType(Context& context, clang::QualType type) -> TypeExpr { } switch (builtin_type->getKind()) { case clang::BuiltinType::Short: - return MakeIntType(context, context.ints().Add(16)); + if (context.ast_context().getTypeSize(type) == 16) { + return MakeIntType(context, context.ints().Add(16)); + } + break; case clang::BuiltinType::Int: if (context.ast_context().getTypeSize(type) == 32) { return MakeIntType(context, context.ints().Add(32)); } - [[fallthrough]]; + break; default: - return {.inst_id = SemIR::ErrorInst::TypeInstId, - .type_id = SemIR::ErrorInst::TypeId}; + break; } + return {.inst_id = SemIR::ErrorInst::TypeInstId, + .type_id = SemIR::ErrorInst::TypeId}; } // Returns a block id for the explicit parameters of the given function diff --git a/toolchain/check/testdata/interop/cpp/function_decl.carbon b/toolchain/check/testdata/interop/cpp/function_decl.carbon index e288852de810a..4c824bcf7f871 100644 --- a/toolchain/check/testdata/interop/cpp/function_decl.carbon +++ b/toolchain/check/testdata/interop/cpp/function_decl.carbon @@ -205,8 +205,40 @@ library "[[@TEST_NAME]]"; import Cpp library "short_param_function_decl.h"; fn F() { - var a: i16 = 1; - Cpp.foo(a); + Cpp.foo(1 as i16); +} + +// --- short_max_param_function_decl.h + +auto foo(short a) -> void; + +// --- import_short_max_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_max_param_function_decl.h"; + +fn F() { + Cpp.foo(0x7FFF); +} + +// --- overflow_short_max_param_function_decl.h + +auto foo(short a) -> void; + +// --- fail_overflow_short_max_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "overflow_short_max_param_function_decl.h"; + +fn F() { + // CHECK:STDERR: fail_overflow_short_max_param_function_decl.carbon:[[@LINE+5]]:11: error: integer value 32768 too large for type `i16` [IntTooLargeForType] + // CHECK:STDERR: Cpp.foo(0x8000); + // CHECK:STDERR: ^~~~~~ + // CHECK:STDERR: fail_overflow_short_max_param_function_decl.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: + Cpp.foo(0x8000); } // --- short_int_param_function_decl.h @@ -1151,8 +1183,83 @@ fn F() { // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] // 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.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %As.type.a96: type = facet_type <@As, @As(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.be5: type = fn_type @Convert.1, @As(%i16) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.0ef: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.172: type = fn_type @Convert.5, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.489: %Convert.type.172 = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.a96 = facet_value Core.IntLiteral, (%As.impl_witness.0ef) [concrete] +// CHECK:STDOUT: %.91d: type = fn_type_with_self_type %Convert.type.be5, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.489 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.489, @Convert.5(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .As = %Core.As +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %impl.elem0: %.91d = impl_witness_access constants.%As.impl_witness.0ef, element0 [concrete = constants.%Convert.489] +// CHECK:STDOUT: %bound_method.loc7_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_13.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.2: %i16 = converted %int_1, %.loc7_13.1 [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_13.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_max_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32767.f4b: Core.IntLiteral = int_value 32767 [concrete] // CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] // CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] @@ -1161,12 +1268,10 @@ fn F() { // CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] // CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] -// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_32767.f4b, %Convert.d0a [concrete] // CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] -// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] -// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] -// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] -// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_32767.f4b, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_32767.faa: %i16 = int_value 32767 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { @@ -1190,39 +1295,99 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "short_param_function_decl.h" +// CHECK:STDOUT: import Cpp "short_max_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @F() { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: name_binding_decl { -// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a -// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt -// CHECK:STDOUT: } -// CHECK:STDOUT: %a.var: ref %i16 = var a -// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// 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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_32767: Core.IntLiteral = int_value 32767 [concrete = constants.%int_32767.f4b] // CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] -// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %bound_method.loc7_11.1: = bound_method %int_32767, %impl.elem0 [concrete = constants.%Convert.bound] // CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] -// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] -// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] -// CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { -// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %bound_method.loc7_11.2: = bound_method %int_32767, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_11.2(%int_32767) [concrete = constants.%int_32767.faa] +// CHECK:STDOUT: %.loc7_11.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_32767.faa] +// CHECK:STDOUT: %.loc7_11.2: %i16 = converted %int_32767, %.loc7_11.1 [concrete = constants.%int_32767.faa] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_11.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_overflow_short_max_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32768.4d0: Core.IntLiteral = int_value 32768 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_32768.4d0, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_32768.4d0, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_32768.e7f: %i16 = int_value 32768 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } -// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "overflow_short_max_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] -// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a -// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: %int_32768: Core.IntLiteral = int_value 32768 [concrete = constants.%int_32768.4d0] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc12_11.1: = bound_method %int_32768, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc12_11.2: = bound_method %int_32768, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc12_11.2(%int_32768) [concrete = constants.%int_32768.e7f] +// CHECK:STDOUT: %.loc12_11.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_32768.e7f] +// CHECK:STDOUT: %.loc12_11.2: %i16 = converted %int_32768, %.loc12_11.1 [concrete = constants.%int_32768.e7f] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc12_11.2) // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: From c49d2fed3553c14972fd77fd81bfc58e008a0583 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Tue, 6 May 2025 11:29:42 +0000 Subject: [PATCH 3/5] Address new review comments, add more tests --- toolchain/check/import_cpp.cpp | 8 +- .../testdata/interop/cpp/function_decl.carbon | 1105 +++++++++++++---- 2 files changed, 871 insertions(+), 242 deletions(-) diff --git a/toolchain/check/import_cpp.cpp b/toolchain/check/import_cpp.cpp index ab94c12322722..517f2ae124fb1 100644 --- a/toolchain/check/import_cpp.cpp +++ b/toolchain/check/import_cpp.cpp @@ -310,8 +310,7 @@ static auto MakeIntType(Context& context, IntId size_id) -> TypeExpr { return ExprAsType(context, Parse::NodeId::None, type_inst_id); } -// Maps a C++ type to a Carbon type. Currently only 32-bit `int` and 16-bit -// `short` are supported. +// Maps a C++ type to a Carbon type. // TODO: Support more types. static auto MapType(Context& context, clang::QualType type) -> TypeExpr { const auto* builtin_type = dyn_cast(type); @@ -319,6 +318,7 @@ static auto MapType(Context& context, clang::QualType type) -> TypeExpr { return {.inst_id = SemIR::ErrorInst::TypeInstId, .type_id = SemIR::ErrorInst::TypeId}; } + // TODO: Refactor to avoid duplication. switch (builtin_type->getKind()) { case clang::BuiltinType::Short: if (context.ast_context().getTypeSize(type) == 16) { @@ -481,8 +481,8 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id, return decl_id; } -// Imports a namespace declaration from Clang to Carbon. If successful, -// returns the new Carbon namespace declaration `InstId`. +// Imports a namespace declaration from Clang to Carbon. If successful, returns +// the new Carbon namespace declaration `InstId`. static auto ImportNamespaceDecl(Context& context, SemIR::NameScopeId parent_scope_id, SemIR::NameId name_id, diff --git a/toolchain/check/testdata/interop/cpp/function_decl.carbon b/toolchain/check/testdata/interop/cpp/function_decl.carbon index 4c824bcf7f871..68b8d3b676d00 100644 --- a/toolchain/check/testdata/interop/cpp/function_decl.carbon +++ b/toolchain/check/testdata/interop/cpp/function_decl.carbon @@ -18,10 +18,8 @@ library "[[@TEST_NAME]]"; import Cpp library "short_return_function_decl.h"; -fn Carbon_foo(val: i16); - fn F() { - Carbon_foo(Cpp.foo_short()); + let x: i16 = Cpp.foo_short(); } // --- int_return_function_decl.h @@ -208,6 +206,67 @@ fn F() { Cpp.foo(1 as i16); } +// --- short_int_param_function_decl.h + +auto foo(short int a) -> void; + +// --- import_short_int_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_int_param_function_decl.h"; + +fn F() { + Cpp.foo(1 as i16); +} + +// --- signed_short_param_function_decl.h + +auto foo(signed short a) -> void; + +// --- import_signed_short_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "signed_short_param_function_decl.h"; + +fn F() { + Cpp.foo(1 as i16); +} + +// --- signed_short_int_param_function_decl.h + +auto foo(signed short int a) -> void; + +// --- import_signed_short_int_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "signed_short_int_param_function_decl.h"; + +fn F() { + Cpp.foo(1 as i16); +} + +// --- int16_t_param_function_decl.h + +namespace std { + // Mimicing Clang's definition for int16_t: https://github.com/llvm/llvm-project/blob/fd800487382e2ee3944493d58a961b6f48290243/clang/lib/Headers/stdint.h#L245 + typedef short int16_t; +} // namespace std + +auto foo(std::int16_t a) -> void; + +// --- import_int16_t_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "int16_t_param_function_decl.h"; + +fn F() { + Cpp.foo(1 as i16); +} + // --- short_max_param_function_decl.h auto foo(short a) -> void; @@ -241,93 +300,164 @@ fn F() { Cpp.foo(0x8000); } -// --- short_int_param_function_decl.h +// --- short_min_param_function_decl.h -auto foo(short int a) -> void; +auto foo(short a) -> void; -// --- import_short_int_param_function_decl.carbon +// --- import_short_min_param_function_decl.carbon library "[[@TEST_NAME]]"; -import Cpp library "short_int_param_function_decl.h"; +import Cpp library "short_min_param_function_decl.h"; fn F() { - var a: i16 = 1; - Cpp.foo(a); + Cpp.foo(-0x8000); } -// --- signed_short_param_function_decl.h +// --- overflow_short_min_param_function_decl.h -auto foo(signed short a) -> void; +auto foo(short a) -> void; -// --- import_signed_short_param_function_decl.carbon +// --- fail_overflow_short_min_param_function_decl.carbon library "[[@TEST_NAME]]"; -import Cpp library "signed_short_param_function_decl.h"; +import Cpp library "overflow_short_min_param_function_decl.h"; fn F() { - var a: i16 = 1; - Cpp.foo(a); + // CHECK:STDERR: fail_overflow_short_min_param_function_decl.carbon:[[@LINE+5]]:11: error: integer value -32769 too large for type `i16` [IntTooLargeForType] + // CHECK:STDERR: Cpp.foo(-0x8001); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: fail_overflow_short_min_param_function_decl.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: + Cpp.foo(-0x8001); } -// --- signed_short_int_param_function_decl.h +// --- int32_arg_short_param_function_decl.h -auto foo(signed short int a) -> void; +auto foo(short a) -> void; -// --- import_signed_short_int_param_function_decl.carbon +// --- fail_int32_arg_short_param_function_decl.carbon library "[[@TEST_NAME]]"; -import Cpp library "signed_short_int_param_function_decl.h"; +import Cpp library "int32_arg_short_param_function_decl.h"; fn F() { - var a: i16 = 1; + var a: i32 = 1; + // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32` to `i16` [ConversionFailure] + // CHECK:STDERR: Cpp.foo(a); + // CHECK:STDERR: ^ + // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+5]]:11: note: type `i32` does not implement interface `Core.ImplicitAs(i16)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: Cpp.foo(a); + // CHECK:STDERR: ^ + // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: Cpp.foo(a); } -// --- int16_t_param_function_decl.h +// --- short_const_param_function_decl.h -namespace std { - typedef signed short int int16_t; -} // namespace std +auto foo(const short a) -> void; -auto foo(std::int16_t a) -> void; +// --- import_short_const_param_function_decl.carbon -// --- import_int16_t_param_function_decl.carbon +library "[[@TEST_NAME]]"; + +import Cpp library "short_const_param_function_decl.h"; + +fn F() { + Cpp.foo(1 as i16); +} + +// --- short_ref_param_function_decl.h + +auto foo(short& a) -> void; + +// --- fail_todo_short_ref_param_function_decl.carbon library "[[@TEST_NAME]]"; -import Cpp library "int16_t_param_function_decl.h"; +import Cpp library "short_ref_param_function_decl.h"; fn F() { var a: i16 = 1; + // CHECK:STDERR: fail_todo_short_ref_param_function_decl.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: short &` [SemanticsTodo] + // CHECK:STDERR: Cpp.foo(a); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: fail_todo_short_ref_param_function_decl.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: Cpp.foo(a); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: Cpp.foo(a); } -// --- int32_arg_short_param_function_decl.h +// --- short_const_ref_param_function_decl.h -auto foo(short a) -> void; +auto foo(const short& a) -> void; -// --- fail_int32_arg_short_param_function_decl.carbon +// --- fail_todo_short_const_ref_param_function_decl.carbon library "[[@TEST_NAME]]"; -import Cpp library "int32_arg_short_param_function_decl.h"; +import Cpp library "short_const_ref_param_function_decl.h"; fn F() { - var a: i32 = 1; - // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32` to `i16` [ConversionFailure] + var a: i16 = 1; + // CHECK:STDERR: fail_todo_short_const_ref_param_function_decl.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: const short &` [SemanticsTodo] // CHECK:STDERR: Cpp.foo(a); - // CHECK:STDERR: ^ - // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+5]]:11: note: type `i32` does not implement interface `Core.ImplicitAs(i16)` [MissingImplInMemberAccessNote] + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: fail_todo_short_const_ref_param_function_decl.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] // CHECK:STDERR: Cpp.foo(a); - // CHECK:STDERR: ^ - // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon: note: initializing function parameter [InCallToFunctionParam] + // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: Cpp.foo(a); } +// --- short_pointer_param_function_decl.h + +auto foo(short* a) -> void; + +// --- fail_todo_short_pointer_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_pointer_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + // CHECK:STDERR: fail_todo_short_pointer_param_function_decl.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: short *` [SemanticsTodo] + // CHECK:STDERR: Cpp.foo(&a); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: fail_todo_short_pointer_param_function_decl.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: Cpp.foo(&a); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: + Cpp.foo(&a); +} + +// --- short_const_pointer_param_function_decl.h + +auto foo(const short* a) -> void; + +// --- fail_todo_short_const_pointer_param_function_decl.carbon + +library "[[@TEST_NAME]]"; + +import Cpp library "short_const_pointer_param_function_decl.h"; + +fn F() { + var a: i16 = 1; + // CHECK:STDERR: fail_todo_short_const_pointer_param_function_decl.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: parameter type: const short *` [SemanticsTodo] + // CHECK:STDERR: Cpp.foo(&a); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: fail_todo_short_const_pointer_param_function_decl.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup] + // CHECK:STDERR: Cpp.foo(&a); + // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: + Cpp.foo(&a); +} + // --- unsupported_primitive_type_param_function_decl.h auto foo(float a) -> void; @@ -373,14 +503,11 @@ fn F() { // CHECK:STDOUT: --- import_short_return_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] -// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] // CHECK:STDOUT: %pattern_type.2f8: type = pattern_type %i16 [concrete] -// CHECK:STDOUT: %Carbon_foo.type: type = fn_type @Carbon_foo [concrete] -// CHECK:STDOUT: %Carbon_foo: %Carbon_foo.type = struct_value () [concrete] -// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] -// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] // CHECK:STDOUT: %foo_short.type: type = fn_type @foo_short [concrete] // CHECK:STDOUT: %foo_short: %foo_short.type = struct_value () [concrete] // CHECK:STDOUT: } @@ -401,41 +528,33 @@ fn F() { // CHECK:STDOUT: package: = namespace [concrete] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Cpp = imports.%Cpp -// CHECK:STDOUT: .Carbon_foo = %Carbon_foo.decl // CHECK:STDOUT: .F = %F.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { // CHECK:STDOUT: import Cpp "short_return_function_decl.h" // CHECK:STDOUT: } -// CHECK:STDOUT: %Carbon_foo.decl: %Carbon_foo.type = fn_decl @Carbon_foo [concrete = constants.%Carbon_foo] { -// CHECK:STDOUT: %val.patt: %pattern_type.2f8 = binding_pattern val -// CHECK:STDOUT: %val.param_patt: %pattern_type.2f8 = value_param_pattern %val.patt, call_param0 -// CHECK:STDOUT: } { -// CHECK:STDOUT: %val.param: %i16 = value_param call_param0 -// CHECK:STDOUT: %.loc6: 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: %val: %i16 = bind_name val, %val.param -// CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: fn @Carbon_foo(%val.param: %i16); -// 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: name_binding_decl { +// CHECK:STDOUT: %x.patt: %pattern_type.2f8 = binding_pattern x +// CHECK:STDOUT: } // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] // CHECK:STDOUT: %foo_short.decl: %foo_short.type = fn_decl @foo_short [concrete = constants.%foo_short] {} {} // CHECK:STDOUT: %foo_short.ref: %foo_short.type = name_ref foo_short, %foo_short.decl [concrete = constants.%foo_short] // CHECK:STDOUT: %foo_short.call: init %i16 = call %foo_short.ref() -// CHECK:STDOUT: %.loc9_28.1: %i16 = value_of_initializer %foo_short.call -// CHECK:STDOUT: %.loc9_28.2: %i16 = converted %foo_short.call, %.loc9_28.1 -// CHECK:STDOUT: %Carbon_foo.call: init %empty_tuple.type = call %Carbon_foo.ref(%.loc9_28.2) +// CHECK:STDOUT: %.loc7_9: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: } +// CHECK:STDOUT: %.loc7_29.1: ref %i16 = temporary_storage +// CHECK:STDOUT: %.loc7_29.2: ref %i16 = temporary %.loc7_29.1, %foo_short.call +// CHECK:STDOUT: %x: ref %i16 = bind_name x, %.loc7_29.2 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: @@ -1249,7 +1368,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: fn @foo(); // CHECK:STDOUT: -// CHECK:STDOUT: --- import_short_max_param_function_decl.carbon +// CHECK:STDOUT: --- import_short_int_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] @@ -1259,25 +1378,25 @@ fn F() { // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] -// CHECK:STDOUT: %int_32767.f4b: Core.IntLiteral = int_value 32767 [concrete] -// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] -// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] -// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] -// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] -// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] -// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] -// CHECK:STDOUT: %Convert.bound: = bound_method %int_32767.f4b, %Convert.d0a [concrete] -// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] -// CHECK:STDOUT: %bound_method: = bound_method %int_32767.f4b, %Convert.specific_fn [concrete] -// CHECK:STDOUT: %int_32767.faa: %i16 = int_value 32767 [concrete] +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %As.type.a96: type = facet_type <@As, @As(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.be5: type = fn_type @Convert.1, @As(%i16) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.0ef: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.172: type = fn_type @Convert.5, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.489: %Convert.type.172 = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.a96 = facet_value Core.IntLiteral, (%As.impl_witness.0ef) [concrete] +// CHECK:STDOUT: %.91d: type = fn_type_with_self_type %Convert.type.be5, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.489 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.489, @Convert.5(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { // CHECK:STDOUT: .Int = %Core.Int -// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: .As = %Core.As // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } @@ -1295,7 +1414,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "short_max_param_function_decl.h" +// CHECK:STDOUT: import Cpp "short_int_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1303,25 +1422,27 @@ fn F() { // CHECK:STDOUT: fn @F() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] -// CHECK:STDOUT: %int_32767: Core.IntLiteral = int_value 32767 [concrete = constants.%int_32767.f4b] -// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] -// CHECK:STDOUT: %bound_method.loc7_11.1: = bound_method %int_32767, %impl.elem0 [concrete = constants.%Convert.bound] -// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc7_11.2: = bound_method %int_32767, %specific_fn [concrete = constants.%bound_method] -// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_11.2(%int_32767) [concrete = constants.%int_32767.faa] -// CHECK:STDOUT: %.loc7_11.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_32767.faa] -// CHECK:STDOUT: %.loc7_11.2: %i16 = converted %int_32767, %.loc7_11.1 [concrete = constants.%int_32767.faa] -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_11.2) +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %impl.elem0: %.91d = impl_witness_access constants.%As.impl_witness.0ef, element0 [concrete = constants.%Convert.489] +// CHECK:STDOUT: %bound_method.loc7_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_13.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.2: %i16 = converted %int_1, %.loc7_13.1 [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_13.2) // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @foo(); // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_overflow_short_max_param_function_decl.carbon +// CHECK:STDOUT: --- import_signed_short_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] @@ -1331,24 +1452,489 @@ fn F() { // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] -// CHECK:STDOUT: %int_32768.4d0: Core.IntLiteral = int_value 32768 [concrete] -// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] -// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] -// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] -// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] -// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] -// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] -// CHECK:STDOUT: %Convert.bound: = bound_method %int_32768.4d0, %Convert.d0a [concrete] -// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] -// CHECK:STDOUT: %bound_method: = bound_method %int_32768.4d0, %Convert.specific_fn [concrete] -// CHECK:STDOUT: %int_32768.e7f: %i16 = int_value 32768 [concrete] -// CHECK:STDOUT: } -// CHECK:STDOUT: -// CHECK:STDOUT: imports { -// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %As.type.a96: type = facet_type <@As, @As(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.be5: type = fn_type @Convert.1, @As(%i16) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.0ef: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.172: type = fn_type @Convert.5, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.489: %Convert.type.172 = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.a96 = facet_value Core.IntLiteral, (%As.impl_witness.0ef) [concrete] +// CHECK:STDOUT: %.91d: type = fn_type_with_self_type %Convert.type.be5, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.489 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.489, @Convert.5(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .As = %Core.As +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "signed_short_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %impl.elem0: %.91d = impl_witness_access constants.%As.impl_witness.0ef, element0 [concrete = constants.%Convert.489] +// CHECK:STDOUT: %bound_method.loc7_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_13.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.2: %i16 = converted %int_1, %.loc7_13.1 [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_13.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_signed_short_int_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %As.type.a96: type = facet_type <@As, @As(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.be5: type = fn_type @Convert.1, @As(%i16) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.0ef: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.172: type = fn_type @Convert.5, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.489: %Convert.type.172 = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.a96 = facet_value Core.IntLiteral, (%As.impl_witness.0ef) [concrete] +// CHECK:STDOUT: %.91d: type = fn_type_with_self_type %Convert.type.be5, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.489 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.489, @Convert.5(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .As = %Core.As +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "signed_short_int_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %impl.elem0: %.91d = impl_witness_access constants.%As.impl_witness.0ef, element0 [concrete = constants.%Convert.489] +// CHECK:STDOUT: %bound_method.loc7_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_13.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.2: %i16 = converted %int_1, %.loc7_13.1 [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_13.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_int16_t_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %As.type.a96: type = facet_type <@As, @As(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.be5: type = fn_type @Convert.1, @As(%i16) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.0ef: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.172: type = fn_type @Convert.5, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.489: %Convert.type.172 = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.a96 = facet_value Core.IntLiteral, (%As.impl_witness.0ef) [concrete] +// CHECK:STDOUT: %.91d: type = fn_type_with_self_type %Convert.type.be5, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.489 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.489, @Convert.5(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .As = %Core.As +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "int16_t_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %impl.elem0: %.91d = impl_witness_access constants.%As.impl_witness.0ef, element0 [concrete = constants.%Convert.489] +// CHECK:STDOUT: %bound_method.loc7_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_13.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.2: %i16 = converted %int_1, %.loc7_13.1 [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_13.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_max_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32767.f4b: Core.IntLiteral = int_value 32767 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_32767.f4b, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_32767.f4b, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_32767.faa: %i16 = int_value 32767 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_max_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_32767: Core.IntLiteral = int_value 32767 [concrete = constants.%int_32767.f4b] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_11.1: = bound_method %int_32767, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_11.2: = bound_method %int_32767, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_11.2(%int_32767) [concrete = constants.%int_32767.faa] +// CHECK:STDOUT: %.loc7_11.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_32767.faa] +// CHECK:STDOUT: %.loc7_11.2: %i16 = converted %int_32767, %.loc7_11.1 [concrete = constants.%int_32767.faa] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_11.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_overflow_short_max_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32768.4d0: Core.IntLiteral = int_value 32768 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_32768.4d0, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_32768.4d0, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_32768.e7f: %i16 = int_value 32768 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "overflow_short_max_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_32768: Core.IntLiteral = int_value 32768 [concrete = constants.%int_32768.4d0] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc12_11.1: = bound_method %int_32768, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc12_11.2: = bound_method %int_32768, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc12_11.2(%int_32768) [concrete = constants.%int_32768.e7f] +// CHECK:STDOUT: %.loc12_11.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_32768.e7f] +// CHECK:STDOUT: %.loc12_11.2: %i16 = converted %int_32768, %.loc12_11.1 [concrete = constants.%int_32768.e7f] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc12_11.2) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_min_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32768: Core.IntLiteral = int_value 32768 [concrete] +// CHECK:STDOUT: %Negate.type: type = facet_type <@Negate> [concrete] +// CHECK:STDOUT: %Op.type.e42: type = fn_type @Op.1 [concrete] +// CHECK:STDOUT: %Negate.impl_witness_table.e09 = impl_witness_table (imports.%Core.import_ref.c15), @impl.8cb [concrete] +// CHECK:STDOUT: %Negate.impl_witness.561: = impl_witness %Negate.impl_witness_table.e09 [concrete] +// CHECK:STDOUT: %Negate.facet: %Negate.type = facet_value Core.IntLiteral, (%Negate.impl_witness.561) [concrete] +// CHECK:STDOUT: %.63a: type = fn_type_with_self_type %Op.type.e42, %Negate.facet [concrete] +// CHECK:STDOUT: %Op.type.1be: type = fn_type @Op.2 [concrete] +// CHECK:STDOUT: %Op.bba: %Op.type.1be = struct_value () [concrete] +// CHECK:STDOUT: %Op.bound: = bound_method %int_32768, %Op.bba [concrete] +// CHECK:STDOUT: %int_-32768.882: Core.IntLiteral = int_value -32768 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_-32768.882, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_-32768.882, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_-32768.7e5: %i16 = int_value -32768 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .Negate = %Core.Negate +// CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_min_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %int_32768: Core.IntLiteral = int_value 32768 [concrete = constants.%int_32768] +// CHECK:STDOUT: %impl.elem0.loc7_11.1: %.63a = impl_witness_access constants.%Negate.impl_witness.561, element0 [concrete = constants.%Op.bba] +// CHECK:STDOUT: %bound_method.loc7_11.1: = bound_method %int_32768, %impl.elem0.loc7_11.1 [concrete = constants.%Op.bound] +// CHECK:STDOUT: %int.snegate: init Core.IntLiteral = call %bound_method.loc7_11.1(%int_32768) [concrete = constants.%int_-32768.882] +// CHECK:STDOUT: %impl.elem0.loc7_11.2: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc7_11.2: = bound_method %int.snegate, %impl.elem0.loc7_11.2 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0.loc7_11.2, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_11.3: = bound_method %int.snegate, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %.loc7_11.1: Core.IntLiteral = value_of_initializer %int.snegate [concrete = constants.%int_-32768.882] +// CHECK:STDOUT: %.loc7_11.2: Core.IntLiteral = converted %int.snegate, %.loc7_11.1 [concrete = constants.%int_-32768.882] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_11.3(%.loc7_11.2) [concrete = constants.%int_-32768.7e5] +// CHECK:STDOUT: %.loc7_11.3: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_-32768.7e5] +// CHECK:STDOUT: %.loc7_11.4: %i16 = converted %int.snegate, %.loc7_11.3 [concrete = constants.%int_-32768.7e5] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_11.4) +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_overflow_short_min_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_32769: Core.IntLiteral = int_value 32769 [concrete] +// CHECK:STDOUT: %Negate.type: type = facet_type <@Negate> [concrete] +// CHECK:STDOUT: %Op.type.e42: type = fn_type @Op.1 [concrete] +// CHECK:STDOUT: %Negate.impl_witness_table.e09 = impl_witness_table (imports.%Core.import_ref.c15), @impl.8cb [concrete] +// CHECK:STDOUT: %Negate.impl_witness.561: = impl_witness %Negate.impl_witness_table.e09 [concrete] +// CHECK:STDOUT: %Negate.facet: %Negate.type = facet_value Core.IntLiteral, (%Negate.impl_witness.561) [concrete] +// CHECK:STDOUT: %.63a: type = fn_type_with_self_type %Op.type.e42, %Negate.facet [concrete] +// CHECK:STDOUT: %Op.type.1be: type = fn_type @Op.2 [concrete] +// CHECK:STDOUT: %Op.bba: %Op.type.1be = struct_value () [concrete] +// CHECK:STDOUT: %Op.bound: = bound_method %int_32769, %Op.bba [concrete] +// CHECK:STDOUT: %int_-32769.5a5: Core.IntLiteral = int_value -32769 [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_-32769.5a5, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_-32769.5a5, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_-32769.883: %i16 = int_value -32769 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { // CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .Negate = %Core.Negate // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... @@ -1367,7 +1953,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "overflow_short_max_param_function_decl.h" +// CHECK:STDOUT: import Cpp "overflow_short_min_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1379,42 +1965,49 @@ fn F() { // CHECK:STDOUT: %i16: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] -// CHECK:STDOUT: %int_32768: Core.IntLiteral = int_value 32768 [concrete = constants.%int_32768.4d0] -// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] -// CHECK:STDOUT: %bound_method.loc12_11.1: = bound_method %int_32768, %impl.elem0 [concrete = constants.%Convert.bound] -// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc12_11.2: = bound_method %int_32768, %specific_fn [concrete = constants.%bound_method] -// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc12_11.2(%int_32768) [concrete = constants.%int_32768.e7f] -// CHECK:STDOUT: %.loc12_11.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_32768.e7f] -// CHECK:STDOUT: %.loc12_11.2: %i16 = converted %int_32768, %.loc12_11.1 [concrete = constants.%int_32768.e7f] -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc12_11.2) +// CHECK:STDOUT: %int_32769: Core.IntLiteral = int_value 32769 [concrete = constants.%int_32769] +// CHECK:STDOUT: %impl.elem0.loc12_11.1: %.63a = impl_witness_access constants.%Negate.impl_witness.561, element0 [concrete = constants.%Op.bba] +// CHECK:STDOUT: %bound_method.loc12_11.1: = bound_method %int_32769, %impl.elem0.loc12_11.1 [concrete = constants.%Op.bound] +// CHECK:STDOUT: %int.snegate: init Core.IntLiteral = call %bound_method.loc12_11.1(%int_32769) [concrete = constants.%int_-32769.5a5] +// CHECK:STDOUT: %impl.elem0.loc12_11.2: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %bound_method.loc12_11.2: = bound_method %int.snegate, %impl.elem0.loc12_11.2 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0.loc12_11.2, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc12_11.3: = bound_method %int.snegate, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %.loc12_11.1: Core.IntLiteral = value_of_initializer %int.snegate [concrete = constants.%int_-32769.5a5] +// CHECK:STDOUT: %.loc12_11.2: Core.IntLiteral = converted %int.snegate, %.loc12_11.1 [concrete = constants.%int_-32769.5a5] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc12_11.3(%.loc12_11.2) [concrete = constants.%int_-32769.883] +// CHECK:STDOUT: %.loc12_11.3: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_-32769.883] +// CHECK:STDOUT: %.loc12_11.4: %i16 = converted %int.snegate, %.loc12_11.3 [concrete = constants.%int_-32769.883] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc12_11.4) // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @foo(); // CHECK:STDOUT: -// CHECK:STDOUT: --- import_short_int_param_function_decl.carbon +// CHECK:STDOUT: --- fail_int32_arg_short_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] -// 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: %int_32: Core.IntLiteral = int_value 32 [concrete] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] +// CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete] // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] -// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] -// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] +// CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete] +// CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete] // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] -// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] -// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] -// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] -// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] -// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] -// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.c75: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete] +// CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete] +// CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete] +// CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.956 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.956, @Convert.2(%int_32) [concrete] // CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] -// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] // CHECK:STDOUT: } @@ -1440,7 +2033,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "short_int_param_function_decl.h" +// CHECK:STDOUT: import Cpp "int32_arg_short_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1448,41 +2041,114 @@ fn F() { // CHECK:STDOUT: fn @F() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: name_binding_decl { -// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a -// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt +// CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.7ce = var_pattern %a.patt // CHECK:STDOUT: } -// CHECK:STDOUT: %a.var: ref %i16 = var a +// CHECK:STDOUT: %a.var: ref %i32 = var a // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] -// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] +// CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956] // CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] -// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn] // CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] -// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] -// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: %.loc7_3.2: init %i32 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.5d2] // CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { -// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %.loc7_10: type = splice_block %i32 [concrete = constants.%i32] { +// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32] // CHECK:STDOUT: } -// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var +// CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var +// CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// 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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %a.ref: ref %i32 = name_ref a, %a +// CHECK:STDOUT: %.loc16: %i16 = converted %a.ref, [concrete = ] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref() +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @foo(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- import_short_const_param_function_decl.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %F.type: type = fn_type @F [concrete] +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] +// CHECK:STDOUT: %F: %F.type = struct_value () [concrete] +// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] +// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %As.type.a96: type = facet_type <@As, @As(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.be5: type = fn_type @Convert.1, @As(%i16) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.0ef: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.172: type = fn_type @Convert.5, @impl.686(%int_16) [concrete] +// CHECK:STDOUT: %Convert.489: %Convert.type.172 = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.a96 = facet_value Core.IntLiteral, (%As.impl_witness.0ef) [concrete] +// CHECK:STDOUT: %.91d: type = fn_type_with_self_type %Convert.type.be5, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.489 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.489, @Convert.5(%int_16) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: imports { +// CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { +// CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .As = %Core.As +// CHECK:STDOUT: import Core//prelude +// CHECK:STDOUT: import Core//prelude/... +// CHECK:STDOUT: } +// CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { +// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: import Cpp//... +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [concrete] { +// CHECK:STDOUT: .Core = imports.%Core +// CHECK:STDOUT: .Cpp = imports.%Cpp +// CHECK:STDOUT: .F = %F.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %Core.import = import Core +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { +// CHECK:STDOUT: import Cpp "short_const_param_function_decl.h" +// CHECK:STDOUT: } +// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} +// 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: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] // CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] -// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a -// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] +// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %impl.elem0: %.91d = impl_witness_access constants.%As.impl_witness.0ef, element0 [concrete = constants.%Convert.489] +// CHECK:STDOUT: %bound_method.loc7_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_16) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc7_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_13.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.1: %i16 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_13.2: %i16 = converted %int_1, %.loc7_13.1 [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc7_13.2) // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @foo(); // CHECK:STDOUT: -// CHECK:STDOUT: --- import_signed_short_param_function_decl.carbon +// CHECK:STDOUT: --- fail_todo_short_ref_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] -// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] @@ -1500,8 +2166,6 @@ fn F() { // CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] // CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] // CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] -// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] -// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { @@ -1512,7 +2176,7 @@ fn F() { // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: .foo = // CHECK:STDOUT: import Cpp//... // CHECK:STDOUT: } // CHECK:STDOUT: } @@ -1525,7 +2189,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "signed_short_param_function_decl.h" +// CHECK:STDOUT: import Cpp "short_ref_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1545,29 +2209,21 @@ fn F() { // CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] // CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] // CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { -// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %.loc7_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: %a: ref %i16 = bind_name a, %a.var // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] -// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} -// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %foo.ref: = name_ref foo, [concrete = ] // CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a -// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: fn @foo(); -// CHECK:STDOUT: -// CHECK:STDOUT: --- import_signed_short_int_param_function_decl.carbon +// CHECK:STDOUT: --- fail_todo_short_const_ref_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] -// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] @@ -1585,8 +2241,6 @@ fn F() { // CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] // CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] // CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] -// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] -// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { @@ -1597,7 +2251,7 @@ fn F() { // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: .foo = // CHECK:STDOUT: import Cpp//... // CHECK:STDOUT: } // CHECK:STDOUT: } @@ -1610,7 +2264,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "signed_short_int_param_function_decl.h" +// CHECK:STDOUT: import Cpp "short_const_ref_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1630,29 +2284,21 @@ fn F() { // CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] // CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] // CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { -// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %.loc7_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: %a: ref %i16 = bind_name a, %a.var // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] -// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} -// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %foo.ref: = name_ref foo, [concrete = ] // CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a -// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: fn @foo(); -// CHECK:STDOUT: -// CHECK:STDOUT: --- import_int16_t_param_function_decl.carbon +// CHECK:STDOUT: --- fail_todo_short_pointer_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] -// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] @@ -1670,8 +2316,7 @@ fn F() { // CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] // CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] // CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] -// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] -// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %ptr.251: type = ptr_type %i16 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { @@ -1682,7 +2327,7 @@ fn F() { // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: .foo = // CHECK:STDOUT: import Cpp//... // CHECK:STDOUT: } // CHECK:STDOUT: } @@ -1695,7 +2340,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "int16_t_param_function_decl.h" +// CHECK:STDOUT: import Cpp "short_pointer_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1715,50 +2360,40 @@ fn F() { // CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] // CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] // CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { -// CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] +// CHECK:STDOUT: %.loc7_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: %a: ref %i16 = bind_name a, %a.var // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %int_16.1: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] -// CHECK:STDOUT: %i16.1: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] -// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} -// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] +// CHECK:STDOUT: %foo.ref: = name_ref foo, [concrete = ] // CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a -// CHECK:STDOUT: %.loc8: %i16 = bind_value %a.ref -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref(%.loc8) +// CHECK:STDOUT: %addr: %ptr.251 = addr_of %a.ref // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: fn @foo(); -// CHECK:STDOUT: -// CHECK:STDOUT: --- fail_int32_arg_short_param_function_decl.carbon +// CHECK:STDOUT: --- fail_todo_short_const_pointer_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] -// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] -// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] -// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] -// CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete] +// 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: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] -// CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete] -// CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete] +// CHECK:STDOUT: %ImplicitAs.type.adb: type = facet_type <@ImplicitAs, @ImplicitAs(%i16)> [concrete] +// CHECK:STDOUT: %Convert.type.fa6: type = fn_type @Convert.1, @ImplicitAs(%i16) [concrete] // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness.c75: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete] -// CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete] -// CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete] -// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete] -// CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete] -// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.956 [concrete] -// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.956, @Convert.2(%int_32) [concrete] +// CHECK:STDOUT: %ImplicitAs.impl_witness.97b: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.type.33c: type = fn_type @Convert.2, @impl.4f9(%int_16) [concrete] +// CHECK:STDOUT: %Convert.d0a: %Convert.type.33c = struct_value () [concrete] +// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.adb = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.97b) [concrete] +// CHECK:STDOUT: %.236: type = fn_type_with_self_type %Convert.type.fa6, %ImplicitAs.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.d0a [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.d0a, @Convert.2(%int_16) [concrete] // CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] -// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete] -// CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] -// CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] -// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] -// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_1.f90: %i16 = int_value 1 [concrete] +// CHECK:STDOUT: %ptr.251: type = ptr_type %i16 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { @@ -1769,7 +2404,7 @@ fn F() { // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Cpp: = namespace file.%Cpp.import_cpp, [concrete] { -// CHECK:STDOUT: .foo = @F.%foo.decl +// CHECK:STDOUT: .foo = // CHECK:STDOUT: import Cpp//... // CHECK:STDOUT: } // CHECK:STDOUT: } @@ -1782,7 +2417,7 @@ fn F() { // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Cpp.import_cpp = import_cpp { -// CHECK:STDOUT: import Cpp "int32_arg_short_param_function_decl.h" +// CHECK:STDOUT: import Cpp "short_const_pointer_param_function_decl.h" // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {} // CHECK:STDOUT: } @@ -1790,36 +2425,30 @@ fn F() { // CHECK:STDOUT: fn @F() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: name_binding_decl { -// CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a -// CHECK:STDOUT: %.loc7_3.1: %pattern_type.7ce = var_pattern %a.patt +// CHECK:STDOUT: %a.patt: %pattern_type.2f8 = binding_pattern a +// CHECK:STDOUT: %.loc7_3.1: %pattern_type.2f8 = var_pattern %a.patt // CHECK:STDOUT: } -// CHECK:STDOUT: %a.var: ref %i32 = var a +// CHECK:STDOUT: %a.var: ref %i16 = var a // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] -// CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956] +// CHECK:STDOUT: %impl.elem0: %.236 = impl_witness_access constants.%ImplicitAs.impl_witness.97b, element0 [concrete = constants.%Convert.d0a] // CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] -// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_16) [concrete = constants.%Convert.specific_fn] // CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] -// CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.5d2] -// CHECK:STDOUT: %.loc7_3.2: init %i32 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: %int.convert_checked: init %i16 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.f90] +// CHECK:STDOUT: %.loc7_3.2: init %i16 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.f90] // CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i32 [concrete = constants.%i32] { -// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32] -// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32] +// CHECK:STDOUT: %.loc7_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: %a: ref %i32 = bind_name a, %a.var +// CHECK:STDOUT: %a: ref %i16 = bind_name a, %a.var // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// 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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} -// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] -// CHECK:STDOUT: %a.ref: ref %i32 = name_ref a, %a -// CHECK:STDOUT: %.loc16: %i16 = converted %a.ref, [concrete = ] -// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref() +// CHECK:STDOUT: %foo.ref: = name_ref foo, [concrete = ] +// CHECK:STDOUT: %a.ref: ref %i16 = name_ref a, %a +// CHECK:STDOUT: %addr: %ptr.251 = addr_of %a.ref // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: fn @foo(); -// CHECK:STDOUT: // CHECK:STDOUT: --- fail_import_unsupported_primitive_type_param_function_decl.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { From acf0d7fa79e855956c058902d2d2329f66c560f0 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Wed, 7 May 2025 12:26:41 +0000 Subject: [PATCH 4/5] Address nit comments --- .../testdata/interop/cpp/function_decl.carbon | 84 ++++++++----------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/toolchain/check/testdata/interop/cpp/function_decl.carbon b/toolchain/check/testdata/interop/cpp/function_decl.carbon index 68b8d3b676d00..13b0b52f8612e 100644 --- a/toolchain/check/testdata/interop/cpp/function_decl.carbon +++ b/toolchain/check/testdata/interop/cpp/function_decl.carbon @@ -251,7 +251,7 @@ fn F() { // --- int16_t_param_function_decl.h namespace std { - // Mimicing Clang's definition for int16_t: https://github.com/llvm/llvm-project/blob/fd800487382e2ee3944493d58a961b6f48290243/clang/lib/Headers/stdint.h#L245 + // Mimicking libc++ definition for int16_t: https://github.com/llvm/llvm-project/blob/fd800487382e2ee3944493d58a961b6f48290243/clang/lib/Headers/stdint.h#L245 typedef short int16_t; } // namespace std @@ -344,16 +344,15 @@ library "[[@TEST_NAME]]"; import Cpp library "int32_arg_short_param_function_decl.h"; fn F() { - var a: i32 = 1; // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+8]]:11: error: cannot implicitly convert expression of type `i32` to `i16` [ConversionFailure] - // CHECK:STDERR: Cpp.foo(a); - // CHECK:STDERR: ^ + // CHECK:STDERR: Cpp.foo(1 as i32); + // CHECK:STDERR: ^~~~~~~~ // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon:[[@LINE+5]]:11: note: type `i32` does not implement interface `Core.ImplicitAs(i16)` [MissingImplInMemberAccessNote] - // CHECK:STDERR: Cpp.foo(a); - // CHECK:STDERR: ^ + // CHECK:STDERR: Cpp.foo(1 as i32); + // CHECK:STDERR: ^~~~~~~~ // CHECK:STDERR: fail_int32_arg_short_param_function_decl.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: - Cpp.foo(a); + Cpp.foo(1 as i32); } // --- short_const_param_function_decl.h @@ -548,13 +547,13 @@ fn F() { // CHECK:STDOUT: %foo_short.decl: %foo_short.type = fn_decl @foo_short [concrete = constants.%foo_short] {} {} // CHECK:STDOUT: %foo_short.ref: %foo_short.type = name_ref foo_short, %foo_short.decl [concrete = constants.%foo_short] // CHECK:STDOUT: %foo_short.call: init %i16 = call %foo_short.ref() -// CHECK:STDOUT: %.loc7_9: type = splice_block %i16.loc7 [concrete = constants.%i16] { +// CHECK:STDOUT: %.loc7_10: type = splice_block %i16.loc7 [concrete = constants.%i16] { // CHECK:STDOUT: %int_16.loc7: Core.IntLiteral = int_value 16 [concrete = constants.%int_16] // CHECK:STDOUT: %i16.loc7: type = class_type @Int, @Int(constants.%int_16) [concrete = constants.%i16] // CHECK:STDOUT: } -// CHECK:STDOUT: %.loc7_29.1: ref %i16 = temporary_storage -// CHECK:STDOUT: %.loc7_29.2: ref %i16 = temporary %.loc7_29.1, %foo_short.call -// CHECK:STDOUT: %x: ref %i16 = bind_name x, %.loc7_29.2 +// CHECK:STDOUT: %.loc7_30.1: ref %i16 = temporary_storage +// CHECK:STDOUT: %.loc7_30.2: ref %i16 = temporary %.loc7_30.1, %foo_short.call +// CHECK:STDOUT: %x: ref %i16 = bind_name x, %.loc7_30.2 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: @@ -1990,31 +1989,31 @@ fn F() { // CHECK:STDOUT: %F.type: type = fn_type @F [concrete] // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] // CHECK:STDOUT: %F: %F.type = struct_value () [concrete] -// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] -// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] -// CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete] -// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] -// CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete] -// CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete] -// CHECK:STDOUT: %ImplicitAs.impl_witness.c75: = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete] -// CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete] -// CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete] -// CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete] -// CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete] -// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.956 [concrete] -// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.956, @Convert.2(%int_32) [concrete] -// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] -// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete] // CHECK:STDOUT: %int_16: Core.IntLiteral = int_value 16 [concrete] // CHECK:STDOUT: %i16: type = class_type @Int, @Int(%int_16) [concrete] // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] +// CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [concrete] +// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete] +// CHECK:STDOUT: %As.type.fd4: type = facet_type <@As, @As(%i32)> [concrete] +// CHECK:STDOUT: %Convert.type.99b: type = fn_type @Convert.1, @As(%i32) [concrete] +// CHECK:STDOUT: %As.impl_witness_table.eb4 = impl_witness_table (imports.%Core.import_ref.78a), @impl.686 [concrete] +// CHECK:STDOUT: %As.impl_witness.6b4: = impl_witness %As.impl_witness_table.eb4, @impl.686(%int_32) [concrete] +// CHECK:STDOUT: %Convert.type.4fd: type = fn_type @Convert.5, @impl.686(%int_32) [concrete] +// CHECK:STDOUT: %Convert.197: %Convert.type.4fd = struct_value () [concrete] +// CHECK:STDOUT: %As.facet: %As.type.fd4 = facet_value Core.IntLiteral, (%As.impl_witness.6b4) [concrete] +// CHECK:STDOUT: %.982: type = fn_type_with_self_type %Convert.type.99b, %As.facet [concrete] +// CHECK:STDOUT: %Convert.bound: = bound_method %int_1.5b8, %Convert.197 [concrete] +// CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.197, @Convert.5(%int_32) [concrete] +// CHECK:STDOUT: %bound_method: = bound_method %int_1.5b8, %Convert.specific_fn [concrete] +// CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [concrete] { // CHECK:STDOUT: .Int = %Core.Int +// CHECK:STDOUT: .As = %Core.As // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... @@ -2040,31 +2039,22 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: fn @F() { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: name_binding_decl { -// CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a -// CHECK:STDOUT: %.loc7_3.1: %pattern_type.7ce = var_pattern %a.patt -// CHECK:STDOUT: } -// CHECK:STDOUT: %a.var: ref %i32 = var a -// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] -// CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956] -// CHECK:STDOUT: %bound_method.loc7_3.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] -// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc7_3.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] -// CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc7_3.2(%int_1) [concrete = constants.%int_1.5d2] -// CHECK:STDOUT: %.loc7_3.2: init %i32 = converted %int_1, %int.convert_checked [concrete = constants.%int_1.5d2] -// CHECK:STDOUT: assign %a.var, %.loc7_3.2 -// CHECK:STDOUT: %.loc7_10: type = splice_block %i32 [concrete = constants.%i32] { -// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32] -// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32] -// CHECK:STDOUT: } -// CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var // CHECK:STDOUT: %Cpp.ref: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] // 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: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] -// CHECK:STDOUT: %a.ref: ref %i32 = name_ref a, %a -// CHECK:STDOUT: %.loc16: %i16 = converted %a.ref, [concrete = ] +// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8] +// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32] +// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32] +// CHECK:STDOUT: %impl.elem0: %.982 = impl_witness_access constants.%As.impl_witness.6b4, element0 [concrete = constants.%Convert.197] +// CHECK:STDOUT: %bound_method.loc15_13.1: = bound_method %int_1, %impl.elem0 [concrete = constants.%Convert.bound] +// CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Convert.5(constants.%int_32) [concrete = constants.%Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc15_13.2: = bound_method %int_1, %specific_fn [concrete = constants.%bound_method] +// CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc15_13.2(%int_1) [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: %.loc15_13.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: %.loc15_13.2: %i32 = converted %int_1, %.loc15_13.1 [concrete = constants.%int_1.5d2] +// CHECK:STDOUT: %.loc15_13.3: %i16 = converted %.loc15_13.2, [concrete = ] // CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref() // CHECK:STDOUT: return // CHECK:STDOUT: } From 8220d6c77255c00cb993f485243caf03c927e641 Mon Sep 17 00:00:00 2001 From: Ivana Ivanovska Date: Thu, 8 May 2025 08:24:18 +0000 Subject: [PATCH 5/5] Fix link to int16_t definition --- toolchain/check/testdata/interop/cpp/function_decl.carbon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/check/testdata/interop/cpp/function_decl.carbon b/toolchain/check/testdata/interop/cpp/function_decl.carbon index 13b0b52f8612e..387ddf9ea7e0a 100644 --- a/toolchain/check/testdata/interop/cpp/function_decl.carbon +++ b/toolchain/check/testdata/interop/cpp/function_decl.carbon @@ -251,8 +251,8 @@ fn F() { // --- int16_t_param_function_decl.h namespace std { - // Mimicking libc++ definition for int16_t: https://github.com/llvm/llvm-project/blob/fd800487382e2ee3944493d58a961b6f48290243/clang/lib/Headers/stdint.h#L245 - typedef short int16_t; + // Mimicking glibc definition for int16_t: https://codebrowser.dev/glibc/glibc/posix/bits/types.h.html#__int16_t + typedef signed short int int16_t; } // namespace std auto foo(std::int16_t a) -> void;