diff --git a/toolchain/check/call.cpp b/toolchain/check/call.cpp index 94853016a248..0a6ac94cf648 100644 --- a/toolchain/check/call.cpp +++ b/toolchain/check/call.cpp @@ -300,6 +300,9 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id, return SemIR::ErrorInst::InstId; } if (callee_function.cpp_overload_set_id.has_value()) { + auto self_id = callee_function.self_id; + // TODO: Pass self_id into overload resolution so that it's taken into + // account when selecting the overload. auto resolved_fn_id = PerformCppOverloadResolution( context, loc_id, callee_function.cpp_overload_set_id, arg_ids); if (!resolved_fn_id) { @@ -311,6 +314,10 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id, return SemIR::ErrorInst::InstId; } CARBON_CHECK(!callee_function.cpp_overload_set_id.has_value()); + + // Preserve the `self` argument from the original callee. + CARBON_CHECK(!callee_function.self_id.has_value()); + callee_function.self_id = self_id; } if (callee_function.function_id.has_value()) { return PerformCallToFunction(context, loc_id, callee_id, callee_function, diff --git a/toolchain/check/member_access.cpp b/toolchain/check/member_access.cpp index 0751bb5ec551..d33586e59207 100644 --- a/toolchain/check/member_access.cpp +++ b/toolchain/check/member_access.cpp @@ -45,14 +45,34 @@ static auto GetClassElementIndex(Context& context, SemIR::InstId element_id) CARBON_FATAL("Unexpected value {0} in class element name", element_inst); } -// Returns whether `function_id` is an instance method, that is, whether it has -// an implicit `self` parameter. +// Returns whether `function_id` is an instance method: in other words, whether +// it has an implicit `self` parameter. static auto IsInstanceMethod(const SemIR::File& sem_ir, SemIR::FunctionId function_id) -> bool { const auto& function = sem_ir.functions().Get(function_id); return function.self_param_id.has_value(); } +// Returns whether the callee function is an instance method, either because +// it's a Carbon instance method or because it's a C++ overload set that might +// contain an instance method. +static auto IsInstanceMethod(const SemIR::File& sem_ir, + const SemIR::CalleeFunction& callee) -> bool { + if (callee.function_id.has_value()) { + return IsInstanceMethod(sem_ir, callee.function_id); + } + if (callee.cpp_overload_set_id.has_value()) { + // For now, treat all C++ overload sets as potentially containing instance + // methods. Overload resolution will handle the case where we actually + // found a static method. + // TODO: Consider returning `false` if there are no non-instance methods in + // the overload set. This would cause us to reject + // `instance.(Class.StaticMethod)()` like we do in pure Carbon code. + return true; + } + return false; +} + // Return whether `type_id`, the type of an associated entity, is for an // instance member (currently true only for instance methods). static auto IsInstanceType(Context& context, SemIR::TypeId type_id) -> bool { @@ -372,10 +392,9 @@ static auto PerformInstanceBinding(Context& context, SemIR::LocId loc_id, SemIR::InstId member_id) -> SemIR::InstId { // If the member is a function, check whether it's an instance method. if (auto callee = SemIR::GetCalleeFunction(context.sem_ir(), member_id); - callee.function_id.has_value()) { - if (!IsInstanceMethod(context.sem_ir(), callee.function_id) || - callee.self_id.has_value()) { - // Found a static member function or an already-bound method. + IsInstanceMethod(context.sem_ir(), callee)) { + if (callee.self_id.has_value()) { + // Found an already-bound method. return member_id; } diff --git a/toolchain/check/testdata/interop/cpp/class/access.carbon b/toolchain/check/testdata/interop/cpp/class/access.carbon index 2aa6bece01ba..b7727162533a 100644 --- a/toolchain/check/testdata/interop/cpp/class/access.carbon +++ b/toolchain/check/testdata/interop/cpp/class/access.carbon @@ -161,7 +161,7 @@ struct S { auto foo() -> void; }; -// --- fail_todo_5891_import_function_member_public.carbon +// --- import_function_member_public.carbon library "[[@TEST_NAME]]"; @@ -169,11 +169,6 @@ import Cpp library "function_member_public.h"; fn F(s: Cpp.S*) { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_5891_import_function_member_public.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: s->foo(); - // CHECK:STDERR: ^~~~~~~~ - // CHECK:STDERR: fail_todo_5891_import_function_member_public.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: s->foo(); //@dump-sem-ir-end } @@ -432,7 +427,7 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_5891_import_function_member_public.carbon +// CHECK:STDOUT: --- import_function_member_public.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %S: type = class_type @S [concrete] @@ -456,10 +451,11 @@ fn F() { // CHECK:STDOUT: fn @F(%s.param: %ptr.5c7) { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %s.ref: %ptr.5c7 = name_ref s, %s -// CHECK:STDOUT: %.loc13: ref %S = deref %s.ref +// CHECK:STDOUT: %.loc8: ref %S = deref %s.ref // CHECK:STDOUT: %foo.ref: %.177 = name_ref foo, imports.%.dcb [concrete = constants.%empty_struct] -// CHECK:STDOUT: -// CHECK:STDOUT: %S.foo.call: init %empty_tuple.type = call imports.%S.foo.decl() +// CHECK:STDOUT: %bound_method: = bound_method %.loc8, %foo.ref +// CHECK:STDOUT: %addr: %ptr.5c7 = addr_of %.loc8 +// CHECK:STDOUT: %S.foo.call: init %empty_tuple.type = call imports.%S.foo.decl(%addr) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/class/base.carbon b/toolchain/check/testdata/interop/cpp/class/base.carbon index ef4e1b7aa93b..9c66caf8c355 100644 --- a/toolchain/check/testdata/interop/cpp/class/base.carbon +++ b/toolchain/check/testdata/interop/cpp/class/base.carbon @@ -10,8 +10,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/base.carbon -// TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891. - // --- derived_to_base_conversion.h class Base {}; @@ -103,7 +101,7 @@ struct Derived : Base { void g() const; }; -// --- fail_todo_5891_use_base_method.carbon +// --- use_base_method.carbon library "[[@TEST_NAME]]"; @@ -111,26 +109,12 @@ import Cpp library "base_method.h"; fn CallDirect(d: Cpp.Derived) { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_5891_use_base_method.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: d.f(); - // CHECK:STDERR: ^~~~~ - // CHECK:STDERR: fail_todo_5891_use_base_method.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: d.f(); //@dump-sem-ir-end } fn CallQualified(d: Cpp.Derived) { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_5891_use_base_method.carbon:[[@LINE+9]]:3: error: member name of type `` in compound member access is not an instance member or an interface member [CompoundMemberAccessDoesNotUseBase] - // CHECK:STDERR: d.(Cpp.Base.g)(); - // CHECK:STDERR: ^~~~~~~~~~~~~~ - // CHECK:STDERR: - // CHECK:STDERR: fail_todo_5891_use_base_method.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: d.(Cpp.Base.g)(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_base_method.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: d.(Cpp.Base.g)(); //@dump-sem-ir-end } @@ -472,7 +456,7 @@ class V { // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call to %return // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_5891_use_base_method.carbon +// CHECK:STDOUT: --- use_base_method.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete] @@ -517,23 +501,33 @@ class V { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d // CHECK:STDOUT: %f.ref: %.5b0 = name_ref f, imports.%.e54 [concrete = constants.%empty_struct.3f3] -// CHECK:STDOUT: %addr: %ptr.fb2 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc13_7.1: %ptr.a97 = as_compatible %addr [concrete = ] -// CHECK:STDOUT: %.loc13_7.2: %ptr.a97 = converted %addr, %.loc13_7.1 [concrete = ] -// CHECK:STDOUT: %f__carbon_thunk.call: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%.loc13_7.2) +// CHECK:STDOUT: %bound_method: = bound_method %d.ref, %f.ref +// CHECK:STDOUT: %.loc8_3.1: ref %Base = class_element_access %d.ref, element0 +// CHECK:STDOUT: %.loc8_3.2: ref %Base = converted %d.ref, %.loc8_3.1 +// CHECK:STDOUT: %.loc8_3.3: %Base = bind_value %.loc8_3.2 +// CHECK:STDOUT: %.loc8_3.4: ref %Base = value_as_ref %.loc8_3.3 +// CHECK:STDOUT: %addr: %ptr.fb2 = addr_of %.loc8_3.4 +// CHECK:STDOUT: %.loc8_7.1: %ptr.a97 = as_compatible %addr +// CHECK:STDOUT: %.loc8_7.2: %ptr.a97 = converted %addr, %.loc8_7.1 +// CHECK:STDOUT: %f__carbon_thunk.call: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%.loc8_7.2) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @CallQualified(%d.param: %Derived) { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d -// CHECK:STDOUT: %Cpp.ref.loc28: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %Cpp.ref.loc14: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base] // CHECK:STDOUT: %g.ref: %.7c6 = name_ref g, imports.%.362 [concrete = constants.%empty_struct.49e] -// CHECK:STDOUT: %addr: %ptr.fb2 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc28_18.1: %ptr.a97 = as_compatible %addr [concrete = ] -// CHECK:STDOUT: %.loc28_18.2: %ptr.a97 = converted %addr, %.loc28_18.1 [concrete = ] -// CHECK:STDOUT: %g__carbon_thunk.call: init %empty_tuple.type = call imports.%g__carbon_thunk.decl(%.loc28_18.2) +// CHECK:STDOUT: %bound_method: = bound_method %d.ref, %g.ref +// CHECK:STDOUT: %.loc14_3.1: ref %Base = class_element_access %d.ref, element0 +// CHECK:STDOUT: %.loc14_3.2: ref %Base = converted %d.ref, %.loc14_3.1 +// CHECK:STDOUT: %.loc14_3.3: %Base = bind_value %.loc14_3.2 +// CHECK:STDOUT: %.loc14_3.4: ref %Base = value_as_ref %.loc14_3.3 +// CHECK:STDOUT: %addr: %ptr.fb2 = addr_of %.loc14_3.4 +// CHECK:STDOUT: %.loc14_18.1: %ptr.a97 = as_compatible %addr +// CHECK:STDOUT: %.loc14_18.2: %ptr.a97 = converted %addr, %.loc14_18.1 +// CHECK:STDOUT: %g__carbon_thunk.call: init %empty_tuple.type = call imports.%g__carbon_thunk.decl(%.loc14_18.2) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/class/method.carbon b/toolchain/check/testdata/interop/cpp/class/method.carbon index 016ce470f322..bcbd30fe275b 100644 --- a/toolchain/check/testdata/interop/cpp/class/method.carbon +++ b/toolchain/check/testdata/interop/cpp/class/method.carbon @@ -11,8 +11,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/method.carbon -// TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891. - // --- object_param_qualifiers.h struct HasQualifiers { @@ -27,7 +25,7 @@ struct HasQualifiers { void const_ref_ref_this() const&&; }; -// --- fail_todo_5891_use_object_param_qualifiers.carbon +// --- use_object_param_qualifiers.carbon library "[[@TEST_NAME]]"; @@ -35,90 +33,60 @@ import Cpp library "object_param_qualifiers.h"; fn F(v: Cpp.HasQualifiers, p: Cpp.HasQualifiers*) { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: v.const_this(); - // CHECK:STDERR: ^~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: v.const_this(); - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: v.const_ref_this(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: v.const_ref_this(); - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: p->plain(); - // CHECK:STDERR: ^~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: p->plain(); - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: p->ref_this(); - // CHECK:STDERR: ^~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: p->ref_this(); - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: p->const_this(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: p->const_this(); - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: p->const_ref_this(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_use_object_param_qualifiers.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: p->const_ref_this(); //@dump-sem-ir-end } -// --- fail_bad_5891_object_param_qualifiers_by_value.carbon +// --- fail_bad_object_param_qualifiers_by_value.carbon library "[[@TEST_NAME]]"; import Cpp library "object_param_qualifiers.h"; fn Value(v: Cpp.HasQualifiers) { - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+5]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef] // CHECK:STDERR: v.plain(); - // CHECK:STDERR: ^~~~~~~~~ - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon: note: calling function declared here [InCallToFunction] + // CHECK:STDERR: ^ + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: v.plain(); // TODO: This should remain invalid once we support `volatile`. - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: volatile struct HasQualifiers` [SemanticsTodo] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: volatile struct HasQualifiers` [SemanticsTodo] // CHECK:STDERR: v.volatile_this(); // CHECK:STDERR: ^~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in call to Cpp function here [InCallToCppFunction] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in call to Cpp function here [InCallToCppFunction] // CHECK:STDERR: v.volatile_this(); // CHECK:STDERR: ^~~~~~~~~~~~~~~~~ // CHECK:STDERR: v.volatile_this(); - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+5]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef] // CHECK:STDERR: v.ref_this(); - // CHECK:STDERR: ^~~~~~~~~~~~ - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon: note: calling function declared here [InCallToFunction] + // CHECK:STDERR: ^ + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon: note: initializing function parameter [InCallToFunctionParam] // CHECK:STDERR: v.ref_this(); - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: struct HasQualifiers &&` [SemanticsTodo] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: struct HasQualifiers &&` [SemanticsTodo] // CHECK:STDERR: v.ref_ref_this(); // CHECK:STDERR: ^~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in call to Cpp function here [InCallToCppFunction] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in call to Cpp function here [InCallToCppFunction] // CHECK:STDERR: v.ref_ref_this(); // CHECK:STDERR: ^~~~~~~~~~~~~~~~ // CHECK:STDERR: v.ref_ref_this(); - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: const struct HasQualifiers &&` [SemanticsTodo] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: const struct HasQualifiers &&` [SemanticsTodo] // CHECK:STDERR: v.const_ref_ref_this(); // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_bad_5891_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in call to Cpp function here [InCallToCppFunction] + // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in call to Cpp function here [InCallToCppFunction] // CHECK:STDERR: v.const_ref_ref_this(); // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~ // CHECK:STDERR: @@ -180,7 +148,7 @@ struct ExplicitObjectParam { void H(this Another); }; -// --- fail_todo_5891_call_explicit_object_param.carbon +// --- call_explicit_object_param.carbon library "[[@TEST_NAME]]"; @@ -188,36 +156,13 @@ import Cpp library "explicit_object_param.h"; fn Call(e: Cpp.ExplicitObjectParam, n: i32, a: Cpp.Another) { //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: e.F(); - // CHECK:STDERR: ^~~~~ - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: e.F(); - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon:[[@LINE+9]]:3: error: member name of type `` in compound member access is not an instance member or an interface member [CompoundMemberAccessDoesNotUseBase] - // CHECK:STDERR: n.(Cpp.ExplicitObjectParam.G)(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: n.(Cpp.ExplicitObjectParam.G)(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: n.(Cpp.ExplicitObjectParam.G)(); - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon:[[@LINE+9]]:3: error: member name of type `` in compound member access is not an instance member or an interface member [CompoundMemberAccessDoesNotUseBase] - // CHECK:STDERR: a.(Cpp.ExplicitObjectParam.H)(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: a.(Cpp.ExplicitObjectParam.H)(); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_call_explicit_object_param.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: a.(Cpp.ExplicitObjectParam.H)(); //@dump-sem-ir-end } -// CHECK:STDOUT: --- fail_todo_5891_use_object_param_qualifiers.carbon +// CHECK:STDOUT: --- use_object_param_qualifiers.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %HasQualifiers: type = class_type @HasQualifiers [concrete] @@ -272,46 +217,58 @@ fn Call(e: Cpp.ExplicitObjectParam, n: i32, a: Cpp.Another) { // CHECK:STDOUT: // CHECK:STDOUT: fn @F(%v.param: %HasQualifiers, %p.param: %ptr.ec3) { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: %v.ref.loc13: %HasQualifiers = name_ref v, %v -// CHECK:STDOUT: %const_this.ref.loc13: %.602 = name_ref const_this, imports.%.ce8 [concrete = constants.%empty_struct.63b] -// CHECK:STDOUT: %addr.loc13: %ptr.ec3 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc13_16.1: %ptr.2cb = as_compatible %addr.loc13 [concrete = ] -// CHECK:STDOUT: %.loc13_16.2: %ptr.2cb = converted %addr.loc13, %.loc13_16.1 [concrete = ] -// CHECK:STDOUT: %const_this__carbon_thunk.call.loc13: init %empty_tuple.type = call imports.%const_this__carbon_thunk.decl(%.loc13_16.2) -// CHECK:STDOUT: %v.ref.loc19: %HasQualifiers = name_ref v, %v -// CHECK:STDOUT: %const_ref_this.ref.loc19: %.bf0 = name_ref const_ref_this, imports.%.667 [concrete = constants.%empty_struct.4f2] -// CHECK:STDOUT: %addr.loc19: %ptr.ec3 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc19_20.1: %ptr.2cb = as_compatible %addr.loc19 [concrete = ] -// CHECK:STDOUT: %.loc19_20.2: %ptr.2cb = converted %addr.loc19, %.loc19_20.1 [concrete = ] -// CHECK:STDOUT: %const_ref_this__carbon_thunk.call.loc19: init %empty_tuple.type = call imports.%const_ref_this__carbon_thunk.decl(%.loc19_20.2) -// CHECK:STDOUT: %p.ref.loc26: %ptr.ec3 = name_ref p, %p -// CHECK:STDOUT: %.loc26: ref %HasQualifiers = deref %p.ref.loc26 +// CHECK:STDOUT: %v.ref.loc8: %HasQualifiers = name_ref v, %v +// CHECK:STDOUT: %const_this.ref.loc8: %.602 = name_ref const_this, imports.%.ce8 [concrete = constants.%empty_struct.63b] +// CHECK:STDOUT: %bound_method.loc8: = bound_method %v.ref.loc8, %const_this.ref.loc8 +// CHECK:STDOUT: %.loc8_3: ref %HasQualifiers = value_as_ref %v.ref.loc8 +// CHECK:STDOUT: %addr.loc8: %ptr.ec3 = addr_of %.loc8_3 +// CHECK:STDOUT: %.loc8_16.1: %ptr.2cb = as_compatible %addr.loc8 +// CHECK:STDOUT: %.loc8_16.2: %ptr.2cb = converted %addr.loc8, %.loc8_16.1 +// CHECK:STDOUT: %const_this__carbon_thunk.call.loc8: init %empty_tuple.type = call imports.%const_this__carbon_thunk.decl(%.loc8_16.2) +// CHECK:STDOUT: %v.ref.loc9: %HasQualifiers = name_ref v, %v +// CHECK:STDOUT: %const_ref_this.ref.loc9: %.bf0 = name_ref const_ref_this, imports.%.667 [concrete = constants.%empty_struct.4f2] +// CHECK:STDOUT: %bound_method.loc9: = bound_method %v.ref.loc9, %const_ref_this.ref.loc9 +// CHECK:STDOUT: %.loc9_3: ref %HasQualifiers = value_as_ref %v.ref.loc9 +// CHECK:STDOUT: %addr.loc9: %ptr.ec3 = addr_of %.loc9_3 +// CHECK:STDOUT: %.loc9_20.1: %ptr.2cb = as_compatible %addr.loc9 +// CHECK:STDOUT: %.loc9_20.2: %ptr.2cb = converted %addr.loc9, %.loc9_20.1 +// CHECK:STDOUT: %const_ref_this__carbon_thunk.call.loc9: init %empty_tuple.type = call imports.%const_ref_this__carbon_thunk.decl(%.loc9_20.2) +// CHECK:STDOUT: %p.ref.loc11: %ptr.ec3 = name_ref p, %p +// CHECK:STDOUT: %.loc11: ref %HasQualifiers = deref %p.ref.loc11 // CHECK:STDOUT: %plain.ref: %.64b = name_ref plain, imports.%.646 [concrete = constants.%empty_struct.a83] -// CHECK:STDOUT: -// CHECK:STDOUT: %HasQualifiers.plain.call: init %empty_tuple.type = call imports.%HasQualifiers.plain.decl() -// CHECK:STDOUT: %p.ref.loc32: %ptr.ec3 = name_ref p, %p -// CHECK:STDOUT: %.loc32: ref %HasQualifiers = deref %p.ref.loc32 +// CHECK:STDOUT: %bound_method.loc11: = bound_method %.loc11, %plain.ref +// CHECK:STDOUT: %addr.loc11: %ptr.ec3 = addr_of %.loc11 +// CHECK:STDOUT: %HasQualifiers.plain.call: init %empty_tuple.type = call imports.%HasQualifiers.plain.decl(%addr.loc11) +// CHECK:STDOUT: %p.ref.loc12: %ptr.ec3 = name_ref p, %p +// CHECK:STDOUT: %.loc12: ref %HasQualifiers = deref %p.ref.loc12 // CHECK:STDOUT: %ref_this.ref: %.352 = name_ref ref_this, imports.%.145 [concrete = constants.%empty_struct.f58] -// CHECK:STDOUT: -// CHECK:STDOUT: %HasQualifiers.ref_this.call: init %empty_tuple.type = call imports.%HasQualifiers.ref_this.decl() -// CHECK:STDOUT: %p.ref.loc38: %ptr.ec3 = name_ref p, %p -// CHECK:STDOUT: %.loc38_4: ref %HasQualifiers = deref %p.ref.loc38 -// CHECK:STDOUT: %const_this.ref.loc38: %.602 = name_ref const_this, imports.%.ce8 [concrete = constants.%empty_struct.63b] -// CHECK:STDOUT: %addr.loc38: %ptr.ec3 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc38_17.1: %ptr.2cb = as_compatible %addr.loc38 [concrete = ] -// CHECK:STDOUT: %.loc38_17.2: %ptr.2cb = converted %addr.loc38, %.loc38_17.1 [concrete = ] -// CHECK:STDOUT: %const_this__carbon_thunk.call.loc38: init %empty_tuple.type = call imports.%const_this__carbon_thunk.decl(%.loc38_17.2) -// CHECK:STDOUT: %p.ref.loc44: %ptr.ec3 = name_ref p, %p -// CHECK:STDOUT: %.loc44_4: ref %HasQualifiers = deref %p.ref.loc44 -// CHECK:STDOUT: %const_ref_this.ref.loc44: %.bf0 = name_ref const_ref_this, imports.%.667 [concrete = constants.%empty_struct.4f2] -// CHECK:STDOUT: %addr.loc44: %ptr.ec3 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc44_21.1: %ptr.2cb = as_compatible %addr.loc44 [concrete = ] -// CHECK:STDOUT: %.loc44_21.2: %ptr.2cb = converted %addr.loc44, %.loc44_21.1 [concrete = ] -// CHECK:STDOUT: %const_ref_this__carbon_thunk.call.loc44: init %empty_tuple.type = call imports.%const_ref_this__carbon_thunk.decl(%.loc44_21.2) +// CHECK:STDOUT: %bound_method.loc12: = bound_method %.loc12, %ref_this.ref +// CHECK:STDOUT: %addr.loc12: %ptr.ec3 = addr_of %.loc12 +// CHECK:STDOUT: %HasQualifiers.ref_this.call: init %empty_tuple.type = call imports.%HasQualifiers.ref_this.decl(%addr.loc12) +// CHECK:STDOUT: %p.ref.loc13: %ptr.ec3 = name_ref p, %p +// CHECK:STDOUT: %.loc13_4.1: ref %HasQualifiers = deref %p.ref.loc13 +// CHECK:STDOUT: %const_this.ref.loc13: %.602 = name_ref const_this, imports.%.ce8 [concrete = constants.%empty_struct.63b] +// CHECK:STDOUT: %bound_method.loc13: = bound_method %.loc13_4.1, %const_this.ref.loc13 +// CHECK:STDOUT: %.loc13_4.2: %HasQualifiers = bind_value %.loc13_4.1 +// CHECK:STDOUT: %.loc13_4.3: ref %HasQualifiers = value_as_ref %.loc13_4.2 +// CHECK:STDOUT: %addr.loc13: %ptr.ec3 = addr_of %.loc13_4.3 +// CHECK:STDOUT: %.loc13_17.1: %ptr.2cb = as_compatible %addr.loc13 +// CHECK:STDOUT: %.loc13_17.2: %ptr.2cb = converted %addr.loc13, %.loc13_17.1 +// CHECK:STDOUT: %const_this__carbon_thunk.call.loc13: init %empty_tuple.type = call imports.%const_this__carbon_thunk.decl(%.loc13_17.2) +// CHECK:STDOUT: %p.ref.loc14: %ptr.ec3 = name_ref p, %p +// CHECK:STDOUT: %.loc14_4.1: ref %HasQualifiers = deref %p.ref.loc14 +// CHECK:STDOUT: %const_ref_this.ref.loc14: %.bf0 = name_ref const_ref_this, imports.%.667 [concrete = constants.%empty_struct.4f2] +// CHECK:STDOUT: %bound_method.loc14: = bound_method %.loc14_4.1, %const_ref_this.ref.loc14 +// CHECK:STDOUT: %.loc14_4.2: %HasQualifiers = bind_value %.loc14_4.1 +// CHECK:STDOUT: %.loc14_4.3: ref %HasQualifiers = value_as_ref %.loc14_4.2 +// CHECK:STDOUT: %addr.loc14: %ptr.ec3 = addr_of %.loc14_4.3 +// CHECK:STDOUT: %.loc14_21.1: %ptr.2cb = as_compatible %addr.loc14 +// CHECK:STDOUT: %.loc14_21.2: %ptr.2cb = converted %addr.loc14, %.loc14_21.1 +// CHECK:STDOUT: %const_ref_this__carbon_thunk.call.loc14: init %empty_tuple.type = call imports.%const_ref_this__carbon_thunk.decl(%.loc14_21.2) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: --- fail_todo_5891_call_explicit_object_param.carbon +// CHECK:STDOUT: --- call_explicit_object_param.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %ExplicitObjectParam: type = class_type @ExplicitObjectParam [concrete] @@ -367,19 +324,24 @@ fn Call(e: Cpp.ExplicitObjectParam, n: i32, a: Cpp.Another) { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %e.ref: %ExplicitObjectParam = name_ref e, %e // CHECK:STDOUT: %F.ref: %.3e2 = name_ref F, imports.%.037 [concrete = constants.%empty_struct.48d] -// CHECK:STDOUT: %addr.loc13: %ptr.7f5 = addr_of [concrete = ] -// CHECK:STDOUT: %F__carbon_thunk.call: init %empty_tuple.type = call imports.%F__carbon_thunk.decl(%addr.loc13) +// CHECK:STDOUT: %bound_method.loc8: = bound_method %e.ref, %F.ref +// CHECK:STDOUT: %.loc8: ref %ExplicitObjectParam = value_as_ref %e.ref +// CHECK:STDOUT: %addr.loc8: %ptr.7f5 = addr_of %.loc8 +// CHECK:STDOUT: %F__carbon_thunk.call: init %empty_tuple.type = call imports.%F__carbon_thunk.decl(%addr.loc8) // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n -// CHECK:STDOUT: %Cpp.ref.loc23: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %ExplicitObjectParam.ref.loc23: type = name_ref ExplicitObjectParam, imports.%ExplicitObjectParam.decl [concrete = constants.%ExplicitObjectParam] +// CHECK:STDOUT: %Cpp.ref.loc9: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %ExplicitObjectParam.ref.loc9: type = name_ref ExplicitObjectParam, imports.%ExplicitObjectParam.decl [concrete = constants.%ExplicitObjectParam] // CHECK:STDOUT: %G.ref: %.d44 = name_ref G, imports.%.151 [concrete = constants.%empty_struct.a7c] -// CHECK:STDOUT: %ExplicitObjectParam.G.call: init %empty_tuple.type = call imports.%ExplicitObjectParam.G.decl() +// CHECK:STDOUT: %bound_method.loc9: = bound_method %n.ref, %G.ref +// CHECK:STDOUT: %ExplicitObjectParam.G.call: init %empty_tuple.type = call imports.%ExplicitObjectParam.G.decl(%n.ref) // CHECK:STDOUT: %a.ref: %Another = name_ref a, %a -// CHECK:STDOUT: %Cpp.ref.loc33: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %ExplicitObjectParam.ref.loc33: type = name_ref ExplicitObjectParam, imports.%ExplicitObjectParam.decl [concrete = constants.%ExplicitObjectParam] +// CHECK:STDOUT: %Cpp.ref.loc10: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %ExplicitObjectParam.ref.loc10: type = name_ref ExplicitObjectParam, imports.%ExplicitObjectParam.decl [concrete = constants.%ExplicitObjectParam] // CHECK:STDOUT: %H.ref: %.9fb = name_ref H, imports.%.34a [concrete = constants.%empty_struct.b14] -// CHECK:STDOUT: %addr.loc33: %ptr.289 = addr_of [concrete = ] -// CHECK:STDOUT: %H__carbon_thunk.call: init %empty_tuple.type = call imports.%H__carbon_thunk.decl(%addr.loc33) +// CHECK:STDOUT: %bound_method.loc10: = bound_method %a.ref, %H.ref +// CHECK:STDOUT: %.loc10: ref %Another = value_as_ref %a.ref +// CHECK:STDOUT: %addr.loc10: %ptr.289 = addr_of %.loc10 +// CHECK:STDOUT: %H__carbon_thunk.call: init %empty_tuple.type = call imports.%H__carbon_thunk.decl(%addr.loc10) // CHECK:STDOUT: // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/class/struct.carbon b/toolchain/check/testdata/interop/cpp/class/struct.carbon index e52d96278aca..e1fcaed70581 100644 --- a/toolchain/check/testdata/interop/cpp/class/struct.carbon +++ b/toolchain/check/testdata/interop/cpp/class/struct.carbon @@ -514,6 +514,7 @@ fn MyF(bar: Cpp.Bar*); // CHECK:STDOUT: %bar.ref: %ptr.f68 = name_ref bar, %bar // CHECK:STDOUT: %.loc15: ref %Bar = deref %bar.ref // CHECK:STDOUT: %f.ref: %.2e2 = name_ref f, imports.%.6e0 [concrete = constants.%empty_struct] +// CHECK:STDOUT: %bound_method: = bound_method %.loc15, %f.ref // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/class/template.carbon b/toolchain/check/testdata/interop/cpp/class/template.carbon index 5b270d7e2515..404cbae1859e 100644 --- a/toolchain/check/testdata/interop/cpp/class/template.carbon +++ b/toolchain/check/testdata/interop/cpp/class/template.carbon @@ -10,8 +10,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/template.carbon -// TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891. - // --- class_template.h struct Base {}; @@ -24,7 +22,7 @@ template struct A : Base { using Aint = A; using Along = A; -// --- fail_todo_5891_use_class_template.carbon +// --- use_class_template.carbon library "[[@TEST_NAME]]"; @@ -33,11 +31,6 @@ import Cpp library "class_template.h"; fn F(x: Cpp.Aint) -> i32 { // Trigger instantiation through name lookup. //@dump-sem-ir-begin - // CHECK:STDERR: fail_todo_5891_use_class_template.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: x.f(); - // CHECK:STDERR: ^~~~~ - // CHECK:STDERR: fail_todo_5891_use_class_template.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: x.f(); return x.n; //@dump-sem-ir-end @@ -87,7 +80,7 @@ var x: Cpp.XY.r#type = 0; var y: Cpp.Xint.r#type = 0; //@dump-sem-ir-end -// CHECK:STDOUT: --- fail_todo_5891_use_class_template.carbon +// CHECK:STDOUT: --- use_class_template.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %A.0bedf0.1: type = class_type @A.1 [concrete] @@ -143,36 +136,38 @@ var y: Cpp.Xint.r#type = 0; // CHECK:STDOUT: // CHECK:STDOUT: fn @F(%x.param: %A.0bedf0.1) -> %i32 { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: %x.ref.loc14: %A.0bedf0.1 = name_ref x, %x +// CHECK:STDOUT: %x.ref.loc9: %A.0bedf0.1 = name_ref x, %x // CHECK:STDOUT: %f.ref: %.658 = name_ref f, imports.%.d46 [concrete = constants.%empty_struct] -// CHECK:STDOUT: %addr: %ptr.270828.1 = addr_of [concrete = ] -// CHECK:STDOUT: %.loc14_7.1: %ptr.703 = as_compatible %addr [concrete = ] -// CHECK:STDOUT: %.loc14_7.2: %ptr.703 = converted %addr, %.loc14_7.1 [concrete = ] -// CHECK:STDOUT: %f__carbon_thunk.call: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%.loc14_7.2) -// CHECK:STDOUT: %x.ref.loc15: %A.0bedf0.1 = name_ref x, %x +// CHECK:STDOUT: %bound_method.loc9: = bound_method %x.ref.loc9, %f.ref +// CHECK:STDOUT: %.loc9_3: ref %A.0bedf0.1 = value_as_ref %x.ref.loc9 +// CHECK:STDOUT: %addr: %ptr.270828.1 = addr_of %.loc9_3 +// CHECK:STDOUT: %.loc9_7.1: %ptr.703 = as_compatible %addr +// CHECK:STDOUT: %.loc9_7.2: %ptr.703 = converted %addr, %.loc9_7.1 +// CHECK:STDOUT: %f__carbon_thunk.call: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%.loc9_7.2) +// CHECK:STDOUT: %x.ref.loc10: %A.0bedf0.1 = name_ref x, %x // CHECK:STDOUT: %n.ref: %A.elem.c3f = name_ref n, @A.1.%.2 [concrete = @A.1.%.2] -// CHECK:STDOUT: %.loc15_11.1: ref %i32 = class_element_access %x.ref.loc15, element1 -// CHECK:STDOUT: %.loc15_11.2: %i32 = bind_value %.loc15_11.1 +// CHECK:STDOUT: %.loc10_11.1: ref %i32 = class_element_access %x.ref.loc10, element1 +// CHECK:STDOUT: %.loc10_11.2: %i32 = bind_value %.loc10_11.1 // CHECK:STDOUT: %impl.elem0: %.7fa = impl_witness_access constants.%Copy.impl_witness.a32, element0 [concrete = constants.%Int.as.Copy.impl.Op.f59] -// CHECK:STDOUT: %bound_method.loc15_11.1: = bound_method %.loc15_11.2, %impl.elem0 +// CHECK:STDOUT: %bound_method.loc10_11.1: = bound_method %.loc10_11.2, %impl.elem0 // CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn] -// CHECK:STDOUT: %bound_method.loc15_11.2: = bound_method %.loc15_11.2, %specific_fn -// CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc15_11.2(%.loc15_11.2) +// CHECK:STDOUT: %bound_method.loc10_11.2: = bound_method %.loc10_11.2, %specific_fn +// CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc10_11.2(%.loc10_11.2) // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call to %return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @G(%p.param: %ptr.270828.2) -> %ptr.fb2 { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %p.ref: %ptr.270828.2 = name_ref p, %p -// CHECK:STDOUT: %.loc22_11.1: ref %A.0bedf0.2 = deref %p.ref -// CHECK:STDOUT: %.loc22_11.2: ref %Base = class_element_access %.loc22_11.1, element0 -// CHECK:STDOUT: %addr: %ptr.fb2 = addr_of %.loc22_11.2 -// CHECK:STDOUT: %.loc22_11.3: %ptr.fb2 = converted %p.ref, %addr +// CHECK:STDOUT: %.loc17_11.1: ref %A.0bedf0.2 = deref %p.ref +// CHECK:STDOUT: %.loc17_11.2: ref %Base = class_element_access %.loc17_11.1, element0 +// CHECK:STDOUT: %addr: %ptr.fb2 = addr_of %.loc17_11.2 +// CHECK:STDOUT: %.loc17_11.3: %ptr.fb2 = converted %p.ref, %addr // CHECK:STDOUT: %impl.elem0: %.e43 = impl_witness_access constants.%Copy.impl_witness.fe1, element0 [concrete = constants.%ptr.as.Copy.impl.Op.07b] -// CHECK:STDOUT: %bound_method.loc22_11.1: = bound_method %.loc22_11.3, %impl.elem0 +// CHECK:STDOUT: %bound_method.loc17_11.1: = bound_method %.loc17_11.3, %impl.elem0 // CHECK:STDOUT: %specific_fn: = specific_function %impl.elem0, @ptr.as.Copy.impl.Op(constants.%Base) [concrete = constants.%ptr.as.Copy.impl.Op.specific_fn] -// CHECK:STDOUT: %bound_method.loc22_11.2: = bound_method %.loc22_11.3, %specific_fn -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.call: init %ptr.fb2 = call %bound_method.loc22_11.2(%.loc22_11.3) +// CHECK:STDOUT: %bound_method.loc17_11.2: = bound_method %.loc17_11.3, %specific_fn +// CHECK:STDOUT: %ptr.as.Copy.impl.Op.call: init %ptr.fb2 = call %bound_method.loc17_11.2(%.loc17_11.3) // CHECK:STDOUT: return %ptr.as.Copy.impl.Op.call to %return // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/interop/cpp/enum/anonymous.carbon b/toolchain/check/testdata/interop/cpp/enum/anonymous.carbon index e37a506ab8ba..aec87d9be2c8 100644 --- a/toolchain/check/testdata/interop/cpp/enum/anonymous.carbon +++ b/toolchain/check/testdata/interop/cpp/enum/anonymous.carbon @@ -10,8 +10,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/enum/anonymous.carbon -// TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891. - // --- anon.h enum { a, b, c }; @@ -25,7 +23,7 @@ class C { void F(decltype(d)); }; -// --- fail_todo_5891_copy_enum.carbon +// --- copy_enum.carbon library "[[@TEST_NAME]]"; @@ -35,16 +33,11 @@ import Cpp library "anon.h"; fn G() { Cpp.F(Cpp.b); - // CHECK:STDERR: fail_todo_5891_copy_enum.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: Cpp.C.C().F(Cpp.C.e); - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_copy_enum.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: Cpp.C.C().F(Cpp.C.e); } //@dump-sem-ir-end -// CHECK:STDOUT: --- fail_todo_5891_copy_enum.carbon +// CHECK:STDOUT: --- copy_enum.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %G.type: type = fn_type @G [concrete] @@ -122,33 +115,34 @@ fn G() { // CHECK:STDOUT: %.loc8_12.2: ref %.4f0 = temporary %.loc8_12.1, %b.ref // CHECK:STDOUT: %addr.loc8_14: %ptr.793 = addr_of %.loc8_12.2 // CHECK:STDOUT: %F__carbon_thunk.call.loc8: init %empty_tuple.type = call imports.%F__carbon_thunk.decl.e1b8ec.1(%addr.loc8_14) -// CHECK:STDOUT: %Cpp.ref.loc15_3: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %C.ref.loc15_6: type = name_ref C, imports.%C.decl [concrete = constants.%C] -// CHECK:STDOUT: %C.ref.loc15_8: %.d40 = name_ref C, imports.%.40b [concrete = constants.%empty_struct.e73] -// CHECK:STDOUT: %.loc15_11.1: ref %C = temporary_storage -// CHECK:STDOUT: %addr.loc15_11.1: %ptr.d9e = addr_of %.loc15_11.1 -// CHECK:STDOUT: %C__carbon_thunk.call: init %empty_tuple.type = call imports.%C__carbon_thunk.decl(%addr.loc15_11.1) -// CHECK:STDOUT: %.loc15_11.2: init %C = in_place_init %C__carbon_thunk.call, %.loc15_11.1 -// CHECK:STDOUT: %.loc15_11.3: ref %C = temporary %.loc15_11.1, %.loc15_11.2 -// CHECK:STDOUT: %F.ref.loc15: %.9a3 = name_ref F, imports.%.951 [concrete = constants.%empty_struct.acc] -// CHECK:STDOUT: %Cpp.ref.loc15_15: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] -// CHECK:STDOUT: %C.ref.loc15_18: type = name_ref C, imports.%C.decl [concrete = constants.%C] +// CHECK:STDOUT: %Cpp.ref.loc10_3: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %C.ref.loc10_6: type = name_ref C, imports.%C.decl [concrete = constants.%C] +// CHECK:STDOUT: %C.ref.loc10_8: %.d40 = name_ref C, imports.%.40b [concrete = constants.%empty_struct.e73] +// CHECK:STDOUT: %.loc10_11.1: ref %C = temporary_storage +// CHECK:STDOUT: %addr.loc10_11.1: %ptr.d9e = addr_of %.loc10_11.1 +// CHECK:STDOUT: %C__carbon_thunk.call: init %empty_tuple.type = call imports.%C__carbon_thunk.decl(%addr.loc10_11.1) +// CHECK:STDOUT: %.loc10_11.2: init %C = in_place_init %C__carbon_thunk.call, %.loc10_11.1 +// CHECK:STDOUT: %.loc10_11.3: ref %C = temporary %.loc10_11.1, %.loc10_11.2 +// CHECK:STDOUT: %F.ref.loc10: %.9a3 = name_ref F, imports.%.951 [concrete = constants.%empty_struct.acc] +// CHECK:STDOUT: %bound_method.loc10_12: = bound_method %.loc10_11.3, %F.ref.loc10 +// CHECK:STDOUT: %Cpp.ref.loc10_15: = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] +// CHECK:STDOUT: %C.ref.loc10_18: type = name_ref C, imports.%C.decl [concrete = constants.%C] // CHECK:STDOUT: %e.ref: %.bb7 = name_ref e, imports.%int_1.1d6 [concrete = constants.%int_1.1d6] +// CHECK:STDOUT: %addr.loc10_11.2: %ptr.d9e = addr_of %.loc10_11.3 +// CHECK:STDOUT: %.loc10_20.1: ref %.bb7 = temporary_storage +// CHECK:STDOUT: %.loc10_20.2: ref %.bb7 = temporary %.loc10_20.1, %e.ref +// CHECK:STDOUT: %addr.loc10_22: %ptr.73d = addr_of %.loc10_20.2 +// CHECK:STDOUT: %F__carbon_thunk.call.loc10: init %empty_tuple.type = call imports.%F__carbon_thunk.decl.e1b8ec.2(%addr.loc10_11.2, %addr.loc10_22) +// CHECK:STDOUT: %T.as.Destroy.impl.Op.bound.loc10_20: = bound_method %.loc10_20.2, constants.%T.as.Destroy.impl.Op.bd3 // CHECK:STDOUT: -// CHECK:STDOUT: %.loc15_20.1: ref %.bb7 = temporary_storage -// CHECK:STDOUT: %.loc15_20.2: ref %.bb7 = temporary %.loc15_20.1, %e.ref -// CHECK:STDOUT: %addr.loc15_22: %ptr.73d = addr_of %.loc15_20.2 -// CHECK:STDOUT: %F__carbon_thunk.call.loc15: init %empty_tuple.type = call imports.%F__carbon_thunk.decl.e1b8ec.2(, %addr.loc15_22) -// CHECK:STDOUT: %T.as.Destroy.impl.Op.bound.loc15_20: = bound_method %.loc15_20.2, constants.%T.as.Destroy.impl.Op.bd3 +// CHECK:STDOUT: %bound_method.loc10_20: = bound_method %.loc10_20.2, %T.as.Destroy.impl.Op.specific_fn.1 +// CHECK:STDOUT: %addr.loc10_20: %ptr.73d = addr_of %.loc10_20.2 +// CHECK:STDOUT: %T.as.Destroy.impl.Op.call.loc10_20: init %empty_tuple.type = call %bound_method.loc10_20(%addr.loc10_20) +// CHECK:STDOUT: %T.as.Destroy.impl.Op.bound.loc10_11: = bound_method %.loc10_11.3, constants.%T.as.Destroy.impl.Op.a28 // CHECK:STDOUT: -// CHECK:STDOUT: %bound_method.loc15_20: = bound_method %.loc15_20.2, %T.as.Destroy.impl.Op.specific_fn.1 -// CHECK:STDOUT: %addr.loc15_20: %ptr.73d = addr_of %.loc15_20.2 -// CHECK:STDOUT: %T.as.Destroy.impl.Op.call.loc15_20: init %empty_tuple.type = call %bound_method.loc15_20(%addr.loc15_20) -// CHECK:STDOUT: %T.as.Destroy.impl.Op.bound.loc15_11: = bound_method %.loc15_11.3, constants.%T.as.Destroy.impl.Op.a28 -// CHECK:STDOUT: -// CHECK:STDOUT: %bound_method.loc15_11: = bound_method %.loc15_11.3, %T.as.Destroy.impl.Op.specific_fn.2 -// CHECK:STDOUT: %addr.loc15_11.2: %ptr.d9e = addr_of %.loc15_11.3 -// CHECK:STDOUT: %T.as.Destroy.impl.Op.call.loc15_11: init %empty_tuple.type = call %bound_method.loc15_11(%addr.loc15_11.2) +// CHECK:STDOUT: %bound_method.loc10_11: = bound_method %.loc10_11.3, %T.as.Destroy.impl.Op.specific_fn.2 +// CHECK:STDOUT: %addr.loc10_11.3: %ptr.d9e = addr_of %.loc10_11.3 +// CHECK:STDOUT: %T.as.Destroy.impl.Op.call.loc10_11: init %empty_tuple.type = call %bound_method.loc10_11(%addr.loc10_11.3) // CHECK:STDOUT: %T.as.Destroy.impl.Op.bound.loc8: = bound_method %.loc8_12.2, constants.%T.as.Destroy.impl.Op.dda // CHECK:STDOUT: // CHECK:STDOUT: %bound_method.loc8: = bound_method %.loc8_12.2, %T.as.Destroy.impl.Op.specific_fn.3 diff --git a/toolchain/lower/testdata/interop/cpp/base.carbon b/toolchain/lower/testdata/interop/cpp/base.carbon index 4c9cb9026db0..5a1a20199e7e 100644 --- a/toolchain/lower/testdata/interop/cpp/base.carbon +++ b/toolchain/lower/testdata/interop/cpp/base.carbon @@ -10,8 +10,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/base.carbon -// TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891. - // --- structs.h struct A { @@ -50,17 +48,119 @@ fn AccessVal(b: Cpp.B) -> i32 { return b.a; } -// --- fail_todo_5891_call_method.carbon +// --- call_method.carbon library "[[@TEST_NAME]]"; import Cpp library "structs.h"; fn Call(b: Cpp.B*) { - // CHECK:STDERR: fail_todo_5891_call_method.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: b->f(); - // CHECK:STDERR: ^~~~~~ - // CHECK:STDERR: fail_todo_5891_call_method.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: b->f(); } + +// CHECK:STDOUT: ; ModuleID = 'convert.carbon' +// CHECK:STDOUT: source_filename = "convert.carbon" +// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu" +// CHECK:STDOUT: +// CHECK:STDOUT: define ptr @_CConvertPtr.Main(ptr %p) !dbg !7 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %.loc7_11.2.base = getelementptr inbounds nuw [8 x i8], ptr %p, i32 0, i32 0, !dbg !10 +// CHECK:STDOUT: ret ptr %.loc7_11.2.base, !dbg !10 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: declare void @_CAcceptVal.Main(ptr) +// CHECK:STDOUT: +// CHECK:STDOUT: define void @_CConvertVal.Main(ptr %b) !dbg !11 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %.loc13_13.1.base = getelementptr inbounds nuw [8 x i8], ptr %b, i32 0, i32 0, !dbg !12 +// CHECK:STDOUT: call void @_CAcceptVal.Main(ptr %.loc13_13.1.base), !dbg !13 +// CHECK:STDOUT: ret void, !dbg !14 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} +// CHECK:STDOUT: !llvm.dbg.cu = !{!5} +// CHECK:STDOUT: +// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5} +// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3} +// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4} +// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0} +// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2} +// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +// CHECK:STDOUT: !6 = !DIFile(filename: "convert.carbon", directory: "") +// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "ConvertPtr", linkageName: "_CConvertPtr.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !8 = !DISubroutineType(types: !9) +// CHECK:STDOUT: !9 = !{} +// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 3, scope: !7) +// CHECK:STDOUT: !11 = distinct !DISubprogram(name: "ConvertVal", linkageName: "_CConvertVal.Main", scope: null, file: !6, line: 12, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !12 = !DILocation(line: 13, column: 13, scope: !11) +// CHECK:STDOUT: !13 = !DILocation(line: 13, column: 3, scope: !11) +// CHECK:STDOUT: !14 = !DILocation(line: 12, column: 1, scope: !11) +// CHECK:STDOUT: ; ModuleID = 'access_field.carbon' +// CHECK:STDOUT: source_filename = "access_field.carbon" +// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu" +// CHECK:STDOUT: +// CHECK:STDOUT: define i32 @_CAccessVal.Main(ptr %b) !dbg !7 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %.loc7_11.1.base = getelementptr inbounds nuw [8 x i8], ptr %b, i32 0, i32 0, !dbg !10 +// CHECK:STDOUT: %.loc7_11.3.a = getelementptr inbounds nuw [4 x i8], ptr %.loc7_11.1.base, i32 0, i32 0, !dbg !10 +// CHECK:STDOUT: %.loc7_11.4 = load i32, ptr %.loc7_11.3.a, align 4, !dbg !10 +// CHECK:STDOUT: ret i32 %.loc7_11.4, !dbg !11 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} +// CHECK:STDOUT: !llvm.dbg.cu = !{!5} +// CHECK:STDOUT: +// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5} +// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3} +// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4} +// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0} +// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2} +// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +// CHECK:STDOUT: !6 = !DIFile(filename: "access_field.carbon", directory: "") +// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "AccessVal", linkageName: "_CAccessVal.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !8 = !DISubroutineType(types: !9) +// CHECK:STDOUT: !9 = !{} +// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !7) +// CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !7) +// CHECK:STDOUT: ; ModuleID = 'call_method.carbon' +// CHECK:STDOUT: source_filename = "call_method.carbon" +// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu" +// CHECK:STDOUT: +// CHECK:STDOUT: $_ZN1A1fEv = comdat any +// CHECK:STDOUT: +// CHECK:STDOUT: define void @_CCall.Main(ptr %b) !dbg !7 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %.loc7_4.3.base = getelementptr inbounds nuw [8 x i8], ptr %b, i32 0, i32 0, !dbg !10 +// CHECK:STDOUT: call void @_ZN1A1fEv(ptr %.loc7_4.3.base), !dbg !10 +// CHECK:STDOUT: ret void, !dbg !11 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone +// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN1A1fEv(ptr nonnull align 4 dereferenceable(4) %this) #0 comdat align 2 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %this.addr = alloca ptr, align 8 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8 +// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 +// CHECK:STDOUT: ret void +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: +// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} +// CHECK:STDOUT: !llvm.dbg.cu = !{!5} +// CHECK:STDOUT: +// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5} +// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3} +// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4} +// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0} +// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2} +// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +// CHECK:STDOUT: !6 = !DIFile(filename: "call_method.carbon", directory: "") +// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !8 = !DISubroutineType(types: !9) +// CHECK:STDOUT: !9 = !{} +// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 3, scope: !7) +// CHECK:STDOUT: !11 = !DILocation(line: 6, column: 1, scope: !7) diff --git a/toolchain/lower/testdata/interop/cpp/method.carbon b/toolchain/lower/testdata/interop/cpp/method.carbon index 1e71456b14ab..209f9379727e 100644 --- a/toolchain/lower/testdata/interop/cpp/method.carbon +++ b/toolchain/lower/testdata/interop/cpp/method.carbon @@ -11,8 +11,6 @@ // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/method.carbon -// TODO: Tests marked as `fail_todo_5891_` to fixed as a follow-up of https://github.com/carbon-language/carbon-lang/pull/5891. - // --- methods.h struct A { @@ -21,33 +19,23 @@ struct A { int n; }; -// --- fail_todo_5891_call_by_val.carbon +// --- call_by_val.carbon library "[[@TEST_NAME]]"; import Cpp library "methods.h"; fn UseVal(a: Cpp.A) -> i32 { - // CHECK:STDERR: fail_todo_5891_call_by_val.carbon:[[@LINE+5]]:10: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: return a.by_val(); - // CHECK:STDERR: ^~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_call_by_val.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: return a.by_val(); } -// --- fail_todo_5891_call_by_ref.carbon +// --- call_by_ref.carbon library "[[@TEST_NAME]]"; import Cpp library "methods.h"; fn UseVal(a: Cpp.A*) -> i32 { - // CHECK:STDERR: fail_todo_5891_call_by_ref.carbon:[[@LINE+5]]:10: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: return a->by_ref(); - // CHECK:STDERR: ^~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_call_by_ref.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: return a->by_ref(); } @@ -58,23 +46,191 @@ struct NeedThunk { void Explicit(this NeedThunk, signed char c); }; -// --- fail_todo_5891_call_thunk.carbon +// --- call_thunk.carbon library "[[@TEST_NAME]]"; import Cpp library "thunk.h"; fn Call(n: Cpp.NeedThunk) { - // CHECK:STDERR: fail_todo_5891_call_thunk.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: n.Implicit(1); - // CHECK:STDERR: ^~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_call_thunk.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: n.Implicit(1); - // CHECK:STDERR: fail_todo_5891_call_thunk.carbon:[[@LINE+5]]:3: error: missing object argument in method call [MissingObjectInMethodCall] - // CHECK:STDERR: n.Explicit(1); - // CHECK:STDERR: ^~~~~~~~~~~~~ - // CHECK:STDERR: fail_todo_5891_call_thunk.carbon: note: calling function declared here [InCallToFunction] - // CHECK:STDERR: n.Explicit(1); } + +// CHECK:STDOUT: ; ModuleID = 'call_by_val.carbon' +// CHECK:STDOUT: source_filename = "call_by_val.carbon" +// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu" +// CHECK:STDOUT: +// CHECK:STDOUT: %struct.A = type { i32 } +// CHECK:STDOUT: +// CHECK:STDOUT: $_ZNK1A6by_valEv = comdat any +// CHECK:STDOUT: +// CHECK:STDOUT: define i32 @_CUseVal.Main(ptr %a) !dbg !7 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %by_val__carbon_thunk.call = call i32 @_ZNK1A6by_valEv.carbon_thunk(ptr %a), !dbg !10 +// CHECK:STDOUT: ret i32 %by_val__carbon_thunk.call, !dbg !11 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone +// CHECK:STDOUT: define linkonce_odr dso_local i32 @_ZNK1A6by_valEv(ptr nonnull align 4 dereferenceable(4) %this) #0 comdat align 2 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %this.addr = alloca ptr, align 8 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8 +// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 +// CHECK:STDOUT: %n = getelementptr inbounds nuw %struct.A, ptr %this1, i32 0, i32 0 +// CHECK:STDOUT: %0 = load i32, ptr %n, align 4 +// CHECK:STDOUT: ret i32 %0 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress +// CHECK:STDOUT: define dso_local i32 @_ZNK1A6by_valEv.carbon_thunk(ptr %this) #1 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %this.addr = alloca ptr, align 8 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8 +// CHECK:STDOUT: %0 = load ptr, ptr %this.addr, align 8 +// CHECK:STDOUT: %call = call i32 @_ZNK1A6by_valEv(ptr nonnull align 4 dereferenceable(4) %0) +// CHECK:STDOUT: ret i32 %call +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: +// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} +// CHECK:STDOUT: !llvm.dbg.cu = !{!5} +// CHECK:STDOUT: +// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5} +// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3} +// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4} +// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0} +// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2} +// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +// CHECK:STDOUT: !6 = !DIFile(filename: "call_by_val.carbon", directory: "") +// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "UseVal", linkageName: "_CUseVal.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !8 = !DISubroutineType(types: !9) +// CHECK:STDOUT: !9 = !{} +// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !7) +// CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !7) +// CHECK:STDOUT: ; ModuleID = 'call_by_ref.carbon' +// CHECK:STDOUT: source_filename = "call_by_ref.carbon" +// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu" +// CHECK:STDOUT: +// CHECK:STDOUT: %struct.A = type { i32 } +// CHECK:STDOUT: +// CHECK:STDOUT: $_ZN1A6by_refEv = comdat any +// CHECK:STDOUT: +// CHECK:STDOUT: define i32 @_CUseVal.Main(ptr %a) !dbg !7 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %A.by_ref.call = call i32 @_ZN1A6by_refEv(ptr %a), !dbg !10 +// CHECK:STDOUT: ret i32 %A.by_ref.call, !dbg !11 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone +// CHECK:STDOUT: define linkonce_odr dso_local i32 @_ZN1A6by_refEv(ptr nonnull align 4 dereferenceable(4) %this) #0 comdat align 2 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %this.addr = alloca ptr, align 8 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8 +// CHECK:STDOUT: %this1 = load ptr, ptr %this.addr, align 8 +// CHECK:STDOUT: %n = getelementptr inbounds nuw %struct.A, ptr %this1, i32 0, i32 0 +// CHECK:STDOUT: %0 = load i32, ptr %n, align 4 +// CHECK:STDOUT: ret i32 %0 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: attributes #0 = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: +// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} +// CHECK:STDOUT: !llvm.dbg.cu = !{!5} +// CHECK:STDOUT: +// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5} +// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3} +// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4} +// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0} +// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2} +// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +// CHECK:STDOUT: !6 = !DIFile(filename: "call_by_ref.carbon", directory: "") +// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "UseVal", linkageName: "_CUseVal.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !8 = !DISubroutineType(types: !9) +// CHECK:STDOUT: !9 = !{} +// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 10, scope: !7) +// CHECK:STDOUT: !11 = !DILocation(line: 7, column: 3, scope: !7) +// CHECK:STDOUT: ; ModuleID = 'call_thunk.carbon' +// CHECK:STDOUT: source_filename = "call_thunk.carbon" +// CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +// CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu" +// CHECK:STDOUT: +// CHECK:STDOUT: %struct.NeedThunk = type { i8 } +// CHECK:STDOUT: +// CHECK:STDOUT: define void @_CCall.Main(ptr %n) !dbg !7 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %.loc7_14.3.temp = alloca i8, align 1, !dbg !10 +// CHECK:STDOUT: %.loc8_14.3.temp = alloca i8, align 1, !dbg !11 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_14.3.temp), !dbg !10 +// CHECK:STDOUT: store i8 1, ptr %.loc7_14.3.temp, align 1, !dbg !10 +// CHECK:STDOUT: call void @_ZNK9NeedThunk8ImplicitEa.carbon_thunk(ptr %n, ptr %.loc7_14.3.temp), !dbg !12 +// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc8_14.3.temp), !dbg !11 +// CHECK:STDOUT: store i8 1, ptr %.loc8_14.3.temp, align 1, !dbg !11 +// CHECK:STDOUT: call void @_ZNH9NeedThunk8ExplicitES_a.carbon_thunk(ptr %n, ptr %.loc8_14.3.temp), !dbg !13 +// CHECK:STDOUT: ret void, !dbg !14 +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: declare void @_ZNK9NeedThunk8ImplicitEa(ptr, i8) +// CHECK:STDOUT: +// CHECK:STDOUT: declare void @_ZNH9NeedThunk8ExplicitES_a(ptr, i8) +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) +// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #0 +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress +// CHECK:STDOUT: define dso_local void @_ZNK9NeedThunk8ImplicitEa.carbon_thunk(ptr %this, ptr %c) #1 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %this.addr = alloca ptr, align 8 +// CHECK:STDOUT: %c.addr = alloca ptr, align 8 +// CHECK:STDOUT: store ptr %this, ptr %this.addr, align 8 +// CHECK:STDOUT: store ptr %c, ptr %c.addr, align 8 +// CHECK:STDOUT: %0 = load ptr, ptr %this.addr, align 8 +// CHECK:STDOUT: %1 = load ptr, ptr %c.addr, align 8 +// CHECK:STDOUT: %2 = load i8, ptr %1, align 1 +// CHECK:STDOUT: call void @_ZNK9NeedThunk8ImplicitEa(ptr nonnull align 1 dereferenceable(1) %0, i8 signext %2) +// CHECK:STDOUT: ret void +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress +// CHECK:STDOUT: define dso_local void @_ZNH9NeedThunk8ExplicitES_a.carbon_thunk(ptr %0, ptr %c) #1 { +// CHECK:STDOUT: entry: +// CHECK:STDOUT: %.addr = alloca ptr, align 8 +// CHECK:STDOUT: %c.addr = alloca ptr, align 8 +// CHECK:STDOUT: %agg.tmp = alloca %struct.NeedThunk, align 1 +// CHECK:STDOUT: store ptr %0, ptr %.addr, align 8 +// CHECK:STDOUT: store ptr %c, ptr %c.addr, align 8 +// CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8 +// CHECK:STDOUT: %2 = load ptr, ptr %c.addr, align 8 +// CHECK:STDOUT: %3 = load i8, ptr %2, align 1 +// CHECK:STDOUT: call void @_ZNH9NeedThunk8ExplicitES_a(i8 signext %3) +// CHECK:STDOUT: ret void +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: ; uselistorder directives +// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 } +// CHECK:STDOUT: +// CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } +// CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +// CHECK:STDOUT: +// CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4} +// CHECK:STDOUT: !llvm.dbg.cu = !{!5} +// CHECK:STDOUT: +// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5} +// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3} +// CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4} +// CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0} +// CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2} +// CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +// CHECK:STDOUT: !6 = !DIFile(filename: "call_thunk.carbon", directory: "") +// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "Call", linkageName: "_CCall.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5) +// CHECK:STDOUT: !8 = !DISubroutineType(types: !9) +// CHECK:STDOUT: !9 = !{} +// CHECK:STDOUT: !10 = !DILocation(line: 7, column: 14, scope: !7) +// CHECK:STDOUT: !11 = !DILocation(line: 8, column: 14, scope: !7) +// CHECK:STDOUT: !12 = !DILocation(line: 7, column: 3, scope: !7) +// CHECK:STDOUT: !13 = !DILocation(line: 8, column: 3, scope: !7) +// CHECK:STDOUT: !14 = !DILocation(line: 6, column: 1, scope: !7)