Просмотр исходного кода

Basic support for calling class methods imported from C++. (#5796)

Create a `self` parameter when importing a C++ non-static member
function. That seems to be all we need to get basic method calls
working! For now, `const` methods have by-value self parameters, and
non-`const` methods get an `addr self: Self*` parameter.
Richard Smith 9 месяцев назад
Родитель
Сommit
f204bdf094

+ 102 - 12
toolchain/check/import_cpp.cpp

@@ -27,6 +27,7 @@
 #include "toolchain/check/convert.h"
 #include "toolchain/check/diagnostic_helpers.h"
 #include "toolchain/check/eval.h"
+#include "toolchain/check/function.h"
 #include "toolchain/check/import.h"
 #include "toolchain/check/inst.h"
 #include "toolchain/check/literal.h"
@@ -805,6 +806,87 @@ static auto MapType(Context& context, SemIR::LocId loc_id, clang::QualType type)
   return mapped;
 }
 
+// Returns a block for the implicit parameters of the given function
+// declaration. Because function templates are not yet supported, this currently
+// only contains the `self` parameter. On error, produces a diagnostic and
+// returns None.
+static auto MakeImplicitParamPatternsBlockId(
+    Context& context, SemIR::LocId loc_id,
+    const clang::FunctionDecl& clang_decl) -> SemIR::InstBlockId {
+  const auto* method_decl = dyn_cast<clang::CXXMethodDecl>(&clang_decl);
+  if (!method_decl || method_decl->isStatic()) {
+    return SemIR::InstBlockId::Empty;
+  }
+
+  // Build a `self` parameter from the object parameter.
+  BeginSubpattern(context);
+
+  // Perform some special-case mapping for the object parameter:
+  //
+  //  - If it's a const reference to T, produce a by-value `self: T` parameter.
+  //  - If it's a non-const reference to T, produce an `addr self: T*`
+  //    parameter.
+  //  - Otherwise, map it directly, which will currently fail for `&&`-qualified
+  //    methods.
+  //
+  // TODO: Some of this mapping should be performed for all parameters.
+  clang::QualType param_type =
+      method_decl->getFunctionObjectParameterReferenceType();
+  bool addr_self = false;
+  if (param_type->isLValueReferenceType()) {
+    param_type = param_type.getNonReferenceType();
+    if (param_type.isConstQualified()) {
+      // TODO: Consider only doing this if `const` is the only qualifier. For
+      // now, any other qualifier will fail when mapping the type.
+      auto split_type = param_type.getSplitUnqualifiedType();
+      split_type.Quals.removeConst();
+      param_type = method_decl->getASTContext().getQualifiedType(split_type);
+    } else {
+      addr_self = true;
+    }
+  }
+
+  auto [type_inst_id, type_id] = MapType(context, loc_id, param_type);
+  SemIR::ExprRegionId type_expr_region_id =
+      EndSubpatternAsExpr(context, type_inst_id);
+
+  if (!type_id.has_value()) {
+    context.TODO(loc_id,
+                 llvm::formatv("Unsupported: object parameter type: {0}",
+                               param_type.getAsString()));
+    return SemIR::InstBlockId::None;
+  }
+
+  if (addr_self) {
+    type_id = GetPointerType(context, type_inst_id);
+  }
+
+  SemIR::InstId pattern_id =
+      // TODO: Fill in a location once available.
+      AddBindingPattern(context, SemIR::LocId::None, SemIR::NameId::SelfValue,
+                        type_id, type_expr_region_id, /*is_generic*/ false,
+                        /*is_template*/ false)
+          .pattern_id;
+
+  // TODO: Fill in a location once available.
+  pattern_id = AddPatternInst<SemIR::ValueParamPattern>(
+      context, SemIR::LocId::None,
+      {.type_id = context.insts().Get(pattern_id).type_id(),
+       .subpattern_id = pattern_id,
+       .index = SemIR::CallParamIndex::None});
+
+  // If we're building `addr self: Self*`, do that now.
+  if (addr_self) {
+    // TODO: Fill in a location once available.
+    pattern_id = AddPatternInst<SemIR::AddrPattern>(
+        context, SemIR::LocId::None,
+        {.type_id = GetPatternType(context, SemIR::AutoType::TypeId),
+         .inner_id = pattern_id});
+  }
+
+  return context.inst_blocks().Add({pattern_id});
+}
+
 // Returns a block id for the explicit parameters of the given function
 // declaration. If the function declaration has no parameters, it returns
 // `SemIR::InstBlockId::Empty`. In the case of an unsupported parameter type, it
@@ -909,6 +991,7 @@ namespace {
 // Represents the parameter patterns block id, the return slot pattern id and
 // the call parameters block id for a function declaration.
 struct FunctionParamsInsts {
+  SemIR::InstBlockId implicit_param_patterns_id;
   SemIR::InstBlockId param_patterns_id;
   SemIR::InstId return_slot_pattern_id;
   SemIR::InstBlockId call_params_id;
@@ -927,6 +1010,16 @@ struct FunctionParamsInsts {
 static auto CreateFunctionParamsInsts(Context& context, SemIR::LocId loc_id,
                                       const clang::FunctionDecl* clang_decl)
     -> std::optional<FunctionParamsInsts> {
+  if (isa<clang::CXXConstructorDecl, clang::CXXDestructorDecl>(clang_decl)) {
+    context.TODO(loc_id, "Unsupported: Constructor/Destructor");
+    return std::nullopt;
+  }
+
+  auto implicit_param_patterns_id =
+      MakeImplicitParamPatternsBlockId(context, loc_id, *clang_decl);
+  if (!implicit_param_patterns_id.has_value()) {
+    return std::nullopt;
+  }
   auto param_patterns_id =
       MakeParamPatternsBlockId(context, loc_id, *clang_decl);
   if (!param_patterns_id.has_value()) {
@@ -937,12 +1030,12 @@ static auto CreateFunctionParamsInsts(Context& context, SemIR::LocId loc_id,
     return std::nullopt;
   }
 
-  // TODO: Add support for implicit parameters.
-  auto call_params_id = CalleePatternMatch(
-      context, /*implicit_param_patterns_id=*/SemIR::InstBlockId::None,
-      param_patterns_id, return_slot_pattern_id);
+  auto call_params_id =
+      CalleePatternMatch(context, implicit_param_patterns_id, param_patterns_id,
+                         return_slot_pattern_id);
 
-  return {{.param_patterns_id = param_patterns_id,
+  return {{.implicit_param_patterns_id = implicit_param_patterns_id,
+           .param_patterns_id = param_patterns_id,
            .return_slot_pattern_id = return_slot_pattern_id,
            .call_params_id = call_params_id}};
 }
@@ -959,11 +1052,6 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
     MarkFailedDecl(context, clang_decl);
     return SemIR::ErrorInst::InstId;
   }
-  if (!clang_decl->isGlobal()) {
-    context.TODO(loc_id, "Unsupported: Non-global function");
-    MarkFailedDecl(context, clang_decl);
-    return SemIR::ErrorInst::InstId;
-  }
   if (clang_decl->getTemplatedKind() != clang::FunctionDecl::TK_NonTemplate) {
     context.TODO(loc_id, "Unsupported: Template function");
     MarkFailedDecl(context, clang_decl);
@@ -999,7 +1087,8 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
        .first_param_node_id = Parse::NodeId::None,
        .last_param_node_id = Parse::NodeId::None,
        .pattern_block_id = pattern_block_id,
-       .implicit_param_patterns_id = SemIR::InstBlockId::Empty,
+       .implicit_param_patterns_id =
+           function_params_insts->implicit_param_patterns_id,
        .param_patterns_id = function_params_insts->param_patterns_id,
        .is_extern = false,
        .extern_library_id = SemIR::LibraryNameId::None,
@@ -1009,7 +1098,8 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
       {.call_params_id = function_params_insts->call_params_id,
        .return_slot_pattern_id = function_params_insts->return_slot_pattern_id,
        .virtual_modifier = SemIR::FunctionFields::VirtualModifier::None,
-       .self_param_id = SemIR::InstId::None,
+       .self_param_id = FindSelfPattern(
+           context, function_params_insts->implicit_param_patterns_id),
        .clang_decl_id = context.sem_ir().clang_decls().Add(
            {.decl = clang_decl, .inst_id = decl_id})}};
 

+ 2 - 74
toolchain/check/testdata/interop/cpp/class.carbon → toolchain/check/testdata/interop/cpp/class/class.carbon

@@ -6,9 +6,9 @@
 //
 // AUTOUPDATE
 // TIP: To test this file alone, run:
-// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class.carbon
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/class.carbon
 // TIP: To dump output, run:
-// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class.carbon
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/class.carbon
 
 // ============================================================================
 // Declaration
@@ -116,36 +116,6 @@ fn MyF() {
   Cpp.Bar.foo();
 }
 
-// ============================================================================
-// Public member function
-// ============================================================================
-
-// --- public_member_function.h
-
-class Bar {
- public:
-  auto foo() -> void;
-};
-
-// --- fail_todo_import_public_member_function.carbon
-
-library "[[@TEST_NAME]]";
-
-import Cpp library "public_member_function.h";
-
-//@dump-sem-ir-begin
-fn MyF(bar : Cpp.Bar*) {
-  // CHECK:STDERR: fail_todo_import_public_member_function.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: Non-global function` [SemanticsTodo]
-  // CHECK:STDERR:   bar->foo();
-  // CHECK:STDERR:   ^~~~~~~~
-  // CHECK:STDERR: fail_todo_import_public_member_function.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
-  // CHECK:STDERR:   bar->foo();
-  // CHECK:STDERR:   ^~~~~~~~
-  // CHECK:STDERR:
-  bar->foo();
-}
-//@dump-sem-ir-end
-
 // ============================================================================
 // Public static data member
 // ============================================================================
@@ -516,48 +486,6 @@ fn MyF(bar: Cpp.Bar*);
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_import_public_member_function.carbon
-// CHECK:STDOUT:
-// CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %Bar: type = class_type @Bar [concrete]
-// CHECK:STDOUT:   %ptr.f68: type = ptr_type %Bar [concrete]
-// CHECK:STDOUT:   %pattern_type: type = pattern_type %ptr.f68 [concrete]
-// CHECK:STDOUT:   %MyF.type: type = fn_type @MyF [concrete]
-// CHECK:STDOUT:   %MyF: %MyF.type = struct_value () [concrete]
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: imports {
-// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
-// CHECK:STDOUT:     .Bar = %Bar.decl
-// CHECK:STDOUT:     import Cpp//...
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %Bar.decl: type = class_decl @Bar [concrete = constants.%Bar] {} {}
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: file {
-// CHECK:STDOUT:   %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {
-// CHECK:STDOUT:     %bar.patt: %pattern_type = binding_pattern bar [concrete]
-// CHECK:STDOUT:     %bar.param_patt: %pattern_type = value_param_pattern %bar.patt, call_param0 [concrete]
-// CHECK:STDOUT:   } {
-// CHECK:STDOUT:     %bar.param: %ptr.f68 = value_param call_param0
-// CHECK:STDOUT:     %.loc7: type = splice_block %ptr [concrete = constants.%ptr.f68] {
-// CHECK:STDOUT:       %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
-// CHECK:STDOUT:       <elided>
-// CHECK:STDOUT:       %Bar.ref: type = name_ref Bar, imports.%Bar.decl [concrete = constants.%Bar]
-// CHECK:STDOUT:       %ptr: type = ptr_type %Bar.ref [concrete = constants.%ptr.f68]
-// CHECK:STDOUT:     }
-// CHECK:STDOUT:     %bar: %ptr.f68 = bind_name bar, %bar.param
-// CHECK:STDOUT:   }
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: fn @MyF(%bar.param: %ptr.f68) {
-// CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %bar.ref: %ptr.f68 = name_ref bar, %bar
-// CHECK:STDOUT:   %.loc15: ref %Bar = deref %bar.ref
-// CHECK:STDOUT:   %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
-// CHECK:STDOUT:   return
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: --- fail_todo_import_public_static_data_member.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {

+ 604 - 0
toolchain/check/testdata/interop/cpp/class/method.carbon

@@ -0,0 +1,604 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
+// EXTRA-ARGS: --dump-sem-ir-ranges=ignore
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/method.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/method.carbon
+
+// --- object_param_qualifiers.h
+
+struct HasQualifiers {
+  void plain();
+  void const_this() const;
+  void volatile_this() volatile;
+
+  void ref_this() &;
+  void const_ref_this() const&;
+
+  void ref_ref_this() &&;
+  void const_ref_ref_this() const&&;
+};
+
+// --- use_object_param_qualifiers.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp library "object_param_qualifiers.h";
+
+fn F(v: Cpp.HasQualifiers, p: Cpp.HasQualifiers*) {
+  //@dump-sem-ir-begin
+  v.const_this();
+  v.const_ref_this();
+
+  p->plain();
+  p->ref_this();
+  p->const_this();
+  p->const_ref_this();
+  //@dump-sem-ir-end
+}
+
+// --- 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_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_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_object_param_qualifiers_by_value.carbon:[[@LINE+12]]:3: error: semantics TODO: `Unsupported: qualified type: volatile struct HasQualifiers` [SemanticsTodo]
+  // CHECK:STDERR:   v.volatile_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon:[[@LINE+9]]:3: note: in `Cpp` name lookup for `volatile_this` [InCppNameLookup]
+  // CHECK:STDERR:   v.volatile_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  // 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.volatile_this();
+  // CHECK:STDERR:   ^
+  // CHECK:STDERR: fail_bad_object_param_qualifiers_by_value.carbon: note: initializing function parameter [InCallToFunctionParam]
+  // CHECK:STDERR:
+  v.volatile_this();
+
+  // 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_object_param_qualifiers_by_value.carbon: note: initializing function parameter [InCallToFunctionParam]
+  // CHECK:STDERR:
+  v.ref_this();
+
+  // 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_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `ref_ref_this` [InCppNameLookup]
+  // CHECK:STDERR:   v.ref_ref_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  v.ref_ref_this();
+
+  // 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_object_param_qualifiers_by_value.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `const_ref_ref_this` [InCppNameLookup]
+  // CHECK:STDERR:   v.const_ref_ref_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  v.const_ref_ref_this();
+}
+
+// --- fail_todo_bad_object_param_qualifiers_by_ref.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp library "object_param_qualifiers.h";
+
+fn Ref(p: Cpp.HasQualifiers*) {
+  // TODO: This should eventually be accepted if we support `volatile`.
+  // CHECK:STDERR: fail_todo_bad_object_param_qualifiers_by_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: qualified type: volatile struct HasQualifiers` [SemanticsTodo]
+  // CHECK:STDERR:   p->volatile_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_todo_bad_object_param_qualifiers_by_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `volatile_this` [InCppNameLookup]
+  // CHECK:STDERR:   p->volatile_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  p->volatile_this();
+}
+
+// --- fail_bad_object_param_qualifiers_ref_ref.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp library "object_param_qualifiers.h";
+
+fn Ref(p: Cpp.HasQualifiers*) {
+  // CHECK:STDERR: fail_bad_object_param_qualifiers_ref_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: struct HasQualifiers &&` [SemanticsTodo]
+  // CHECK:STDERR:   p->ref_ref_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_bad_object_param_qualifiers_ref_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `ref_ref_this` [InCppNameLookup]
+  // CHECK:STDERR:   p->ref_ref_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  p->ref_ref_this();
+
+  // CHECK:STDERR: fail_bad_object_param_qualifiers_ref_ref.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: object parameter type: const struct HasQualifiers &&` [SemanticsTodo]
+  // CHECK:STDERR:   p->const_ref_ref_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR: fail_bad_object_param_qualifiers_ref_ref.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `const_ref_ref_this` [InCppNameLookup]
+  // CHECK:STDERR:   p->const_ref_ref_this();
+  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:
+  p->const_ref_ref_this();
+}
+
+// CHECK:STDOUT: --- use_object_param_qualifiers.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %HasQualifiers: type = class_type @HasQualifiers [concrete]
+// CHECK:STDOUT:   %empty_struct_type: type = struct_type {} [concrete]
+// CHECK:STDOUT:   %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
+// CHECK:STDOUT:   %pattern_type.e15: type = pattern_type %HasQualifiers [concrete]
+// CHECK:STDOUT:   %ptr.ec3: type = ptr_type %HasQualifiers [concrete]
+// CHECK:STDOUT:   %pattern_type.bc1: type = pattern_type %ptr.ec3 [concrete]
+// 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:   %const_this.type: type = fn_type @const_this [concrete]
+// CHECK:STDOUT:   %const_this: %const_this.type = struct_value () [concrete]
+// CHECK:STDOUT:   %const_ref_this.type: type = fn_type @const_ref_this [concrete]
+// CHECK:STDOUT:   %const_ref_this: %const_ref_this.type = struct_value () [concrete]
+// CHECK:STDOUT:   %pattern_type.f6d: type = pattern_type auto [concrete]
+// CHECK:STDOUT:   %plain.type: type = fn_type @plain [concrete]
+// CHECK:STDOUT:   %plain: %plain.type = struct_value () [concrete]
+// CHECK:STDOUT:   %ref_this.type: type = fn_type @ref_this [concrete]
+// CHECK:STDOUT:   %ref_this: %ref_this.type = struct_value () [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [concrete] {
+// CHECK:STDOUT:     import Core//prelude
+// CHECK:STDOUT:     import Core//prelude/...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .HasQualifiers = %HasQualifiers.decl
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %HasQualifiers.decl: type = class_decl @HasQualifiers [concrete = constants.%HasQualifiers] {} {}
+// CHECK:STDOUT:   %const_this.decl: %const_this.type = fn_decl @const_this [concrete = constants.%const_this] {
+// CHECK:STDOUT:     %self.patt: %pattern_type.e15 = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: %pattern_type.e15 = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: %HasQualifiers = value_param call_param0
+// CHECK:STDOUT:     %self: %HasQualifiers = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %const_ref_this.decl: %const_ref_this.type = fn_decl @const_ref_this [concrete = constants.%const_ref_this] {
+// CHECK:STDOUT:     %self.patt: %pattern_type.e15 = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: %pattern_type.e15 = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: %HasQualifiers = value_param call_param0
+// CHECK:STDOUT:     %self: %HasQualifiers = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %plain.decl: %plain.type = fn_decl @plain [concrete = constants.%plain] {
+// CHECK:STDOUT:     %self.patt: %pattern_type.bc1 = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: %pattern_type.bc1 = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: %ptr.ec3 = value_param call_param0
+// CHECK:STDOUT:     %self: %ptr.ec3 = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %ref_this.decl: %ref_this.type = fn_decl @ref_this [concrete = constants.%ref_this] {
+// CHECK:STDOUT:     %self.patt: %pattern_type.bc1 = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: %pattern_type.bc1 = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: %ptr.ec3 = value_param call_param0
+// CHECK:STDOUT:     %self: %ptr.ec3 = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = 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 "object_param_qualifiers.h"
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
+// CHECK:STDOUT:     %v.patt: %pattern_type.e15 = binding_pattern v [concrete]
+// CHECK:STDOUT:     %v.param_patt: %pattern_type.e15 = value_param_pattern %v.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %p.patt: %pattern_type.bc1 = binding_pattern p [concrete]
+// CHECK:STDOUT:     %p.param_patt: %pattern_type.bc1 = value_param_pattern %p.patt, call_param1 [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %v.param: %HasQualifiers = value_param call_param0
+// CHECK:STDOUT:     %.loc6_12: type = splice_block %HasQualifiers.ref.loc6_12 [concrete = constants.%HasQualifiers] {
+// CHECK:STDOUT:       %Cpp.ref.loc6_9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:       %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
+// CHECK:STDOUT:       %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
+// CHECK:STDOUT:       %HasQualifiers.ref.loc6_12: type = name_ref HasQualifiers, imports.%HasQualifiers.decl [concrete = constants.%HasQualifiers]
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:     %v: %HasQualifiers = bind_name v, %v.param
+// CHECK:STDOUT:     %p.param: %ptr.ec3 = value_param call_param1
+// CHECK:STDOUT:     %.loc6_48: type = splice_block %ptr [concrete = constants.%ptr.ec3] {
+// CHECK:STDOUT:       %Cpp.ref.loc6_31: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:       %HasQualifiers.ref.loc6_34: type = name_ref HasQualifiers, imports.%HasQualifiers.decl [concrete = constants.%HasQualifiers]
+// CHECK:STDOUT:       %ptr: type = ptr_type %HasQualifiers.ref.loc6_34 [concrete = constants.%ptr.ec3]
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:     %p: %ptr.ec3 = bind_name p, %p.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @HasQualifiers {
+// CHECK:STDOUT:   complete_type_witness = @F.%complete_type
+// CHECK:STDOUT:
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%HasQualifiers
+// CHECK:STDOUT:   .const_this = imports.%const_this.decl
+// CHECK:STDOUT:   .const_ref_this = imports.%const_ref_this.decl
+// CHECK:STDOUT:   .plain = imports.%plain.decl
+// CHECK:STDOUT:   .ref_this = imports.%ref_this.decl
+// CHECK:STDOUT:   import Cpp//...
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @F(%v.param: %HasQualifiers, %p.param: %ptr.ec3) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %v.ref.loc8: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %const_this.ref.loc8: %const_this.type = name_ref const_this, imports.%const_this.decl [concrete = constants.%const_this]
+// CHECK:STDOUT:   %const_this.bound.loc8: <bound method> = bound_method %v.ref.loc8, %const_this.ref.loc8
+// CHECK:STDOUT:   %const_this.call.loc8: init %empty_tuple.type = call %const_this.bound.loc8(%v.ref.loc8)
+// CHECK:STDOUT:   %v.ref.loc9: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %const_ref_this.ref.loc9: %const_ref_this.type = name_ref const_ref_this, imports.%const_ref_this.decl [concrete = constants.%const_ref_this]
+// CHECK:STDOUT:   %const_ref_this.bound.loc9: <bound method> = bound_method %v.ref.loc9, %const_ref_this.ref.loc9
+// CHECK:STDOUT:   %const_ref_this.call.loc9: init %empty_tuple.type = call %const_ref_this.bound.loc9(%v.ref.loc9)
+// CHECK:STDOUT:   %p.ref.loc11: %ptr.ec3 = name_ref p, %p
+// CHECK:STDOUT:   %.loc11: ref %HasQualifiers = deref %p.ref.loc11
+// CHECK:STDOUT:   %plain.ref: %plain.type = name_ref plain, imports.%plain.decl [concrete = constants.%plain]
+// CHECK:STDOUT:   %plain.bound: <bound method> = bound_method %.loc11, %plain.ref
+// CHECK:STDOUT:   %addr.loc11: %ptr.ec3 = addr_of %.loc11
+// CHECK:STDOUT:   %plain.call: init %empty_tuple.type = call %plain.bound(%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: %ref_this.type = name_ref ref_this, imports.%ref_this.decl [concrete = constants.%ref_this]
+// CHECK:STDOUT:   %ref_this.bound: <bound method> = bound_method %.loc12, %ref_this.ref
+// CHECK:STDOUT:   %addr.loc12: %ptr.ec3 = addr_of %.loc12
+// CHECK:STDOUT:   %ref_this.call: init %empty_tuple.type = call %ref_this.bound(%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: %const_this.type = name_ref const_this, imports.%const_this.decl [concrete = constants.%const_this]
+// CHECK:STDOUT:   %const_this.bound.loc13: <bound method> = bound_method %.loc13_4.1, %const_this.ref.loc13
+// CHECK:STDOUT:   %.loc13_4.2: %HasQualifiers = bind_value %.loc13_4.1
+// CHECK:STDOUT:   %const_this.call.loc13: init %empty_tuple.type = call %const_this.bound.loc13(%.loc13_4.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: %const_ref_this.type = name_ref const_ref_this, imports.%const_ref_this.decl [concrete = constants.%const_ref_this]
+// CHECK:STDOUT:   %const_ref_this.bound.loc14: <bound method> = bound_method %.loc14_4.1, %const_ref_this.ref.loc14
+// CHECK:STDOUT:   %.loc14_4.2: %HasQualifiers = bind_value %.loc14_4.1
+// CHECK:STDOUT:   %const_ref_this.call.loc14: init %empty_tuple.type = call %const_ref_this.bound.loc14(%.loc14_4.2)
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @const_this(%self.param: %HasQualifiers);
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @const_ref_this(%self.param: %HasQualifiers);
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @plain(%self.param: %ptr.ec3);
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @ref_this(%self.param: %ptr.ec3);
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_bad_object_param_qualifiers_by_value.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %HasQualifiers: type = class_type @HasQualifiers [concrete]
+// CHECK:STDOUT:   %empty_struct_type: type = struct_type {} [concrete]
+// CHECK:STDOUT:   %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
+// CHECK:STDOUT:   %pattern_type.e15: type = pattern_type %HasQualifiers [concrete]
+// CHECK:STDOUT:   %Value.type: type = fn_type @Value [concrete]
+// CHECK:STDOUT:   %empty_tuple.type: type = tuple_type () [concrete]
+// CHECK:STDOUT:   %Value: %Value.type = struct_value () [concrete]
+// CHECK:STDOUT:   %ptr.ec3: type = ptr_type %HasQualifiers [concrete]
+// CHECK:STDOUT:   %pattern_type.bc1: type = pattern_type %ptr.ec3 [concrete]
+// CHECK:STDOUT:   %pattern_type.f6d: type = pattern_type auto [concrete]
+// CHECK:STDOUT:   %plain.type: type = fn_type @plain [concrete]
+// CHECK:STDOUT:   %plain: %plain.type = struct_value () [concrete]
+// CHECK:STDOUT:   %volatile_this.type: type = fn_type @volatile_this [concrete]
+// CHECK:STDOUT:   %volatile_this: %volatile_this.type = struct_value () [concrete]
+// CHECK:STDOUT:   %ref_this.type: type = fn_type @ref_this [concrete]
+// CHECK:STDOUT:   %ref_this: %ref_this.type = struct_value () [concrete]
+// CHECK:STDOUT:   %Destroy.type: type = facet_type <@Destroy> [concrete]
+// CHECK:STDOUT:   %Op.type.e02: type = fn_type @Op.2, @Destroy.impl(%HasQualifiers) [concrete]
+// CHECK:STDOUT:   %Op.b7c: %Op.type.e02 = struct_value () [concrete]
+// CHECK:STDOUT:   %Op.specific_fn: <specific function> = specific_function %Op.b7c, @Op.2(%HasQualifiers) [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [concrete] {
+// CHECK:STDOUT:     .Destroy = %Core.Destroy
+// CHECK:STDOUT:     import Core//prelude
+// CHECK:STDOUT:     import Core//prelude/...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .HasQualifiers = %HasQualifiers.decl
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %HasQualifiers.decl: type = class_decl @HasQualifiers [concrete = constants.%HasQualifiers] {} {}
+// CHECK:STDOUT:   %plain.decl: %plain.type = fn_decl @plain [concrete = constants.%plain] {
+// CHECK:STDOUT:     %self.patt: %pattern_type.bc1 = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: %pattern_type.bc1 = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: %ptr.ec3 = value_param call_param0
+// CHECK:STDOUT:     %self: %ptr.ec3 = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %volatile_this.decl: %volatile_this.type = fn_decl @volatile_this [concrete = constants.%volatile_this] {
+// CHECK:STDOUT:     %self.patt: <error> = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: <error> = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: <error> = value_param call_param0
+// CHECK:STDOUT:     %self: <error> = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %ref_this.decl: %ref_this.type = fn_decl @ref_this [concrete = constants.%ref_this] {
+// CHECK:STDOUT:     %self.patt: %pattern_type.bc1 = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: %pattern_type.bc1 = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: %ptr.ec3 = value_param call_param0
+// CHECK:STDOUT:     %self: %ptr.ec3 = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [concrete] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .Cpp = imports.%Cpp
+// CHECK:STDOUT:     .Value = %Value.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %Cpp.import_cpp = import_cpp {
+// CHECK:STDOUT:     import Cpp "object_param_qualifiers.h"
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Value.decl: %Value.type = fn_decl @Value [concrete = constants.%Value] {
+// CHECK:STDOUT:     %v.patt: %pattern_type.e15 = binding_pattern v [concrete]
+// CHECK:STDOUT:     %v.param_patt: %pattern_type.e15 = value_param_pattern %v.patt, call_param0 [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %v.param: %HasQualifiers = value_param call_param0
+// CHECK:STDOUT:     %.loc6: type = splice_block %HasQualifiers.ref [concrete = constants.%HasQualifiers] {
+// CHECK:STDOUT:       %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:       %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
+// CHECK:STDOUT:       %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
+// CHECK:STDOUT:       %HasQualifiers.ref: type = name_ref HasQualifiers, imports.%HasQualifiers.decl [concrete = constants.%HasQualifiers]
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:     %v: %HasQualifiers = bind_name v, %v.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @HasQualifiers {
+// CHECK:STDOUT:   complete_type_witness = @Value.%complete_type
+// CHECK:STDOUT:
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%HasQualifiers
+// CHECK:STDOUT:   .plain = imports.%plain.decl
+// CHECK:STDOUT:   .volatile_this = imports.%volatile_this.decl
+// CHECK:STDOUT:   .ref_this = imports.%ref_this.decl
+// CHECK:STDOUT:   .ref_ref_this = <error>
+// CHECK:STDOUT:   .const_ref_ref_this = <error>
+// CHECK:STDOUT:   import Cpp//...
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Value(%v.param: %HasQualifiers) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %v.ref.loc12: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %plain.ref: %plain.type = name_ref plain, imports.%plain.decl [concrete = constants.%plain]
+// CHECK:STDOUT:   %plain.bound: <bound method> = bound_method %v.ref.loc12, %plain.ref
+// CHECK:STDOUT:   %.loc12: ref %HasQualifiers = temporary_storage
+// CHECK:STDOUT:   %addr.loc12_3.1: %ptr.ec3 = addr_of %.loc12
+// CHECK:STDOUT:   %plain.call: init %empty_tuple.type = call %plain.bound(%addr.loc12_3.1)
+// CHECK:STDOUT:   %v.ref.loc27: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %volatile_this.ref: %volatile_this.type = name_ref volatile_this, imports.%volatile_this.decl [concrete = constants.%volatile_this]
+// CHECK:STDOUT:   %volatile_this.bound: <bound method> = bound_method %v.ref.loc27, %volatile_this.ref
+// CHECK:STDOUT:   %.loc27: ref %HasQualifiers = temporary_storage
+// CHECK:STDOUT:   %addr.loc27_3.1: %ptr.ec3 = addr_of %.loc27
+// CHECK:STDOUT:   %volatile_this.call: init %empty_tuple.type = call %volatile_this.bound(<error>)
+// CHECK:STDOUT:   %v.ref.loc34: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %ref_this.ref: %ref_this.type = name_ref ref_this, imports.%ref_this.decl [concrete = constants.%ref_this]
+// CHECK:STDOUT:   %ref_this.bound: <bound method> = bound_method %v.ref.loc34, %ref_this.ref
+// CHECK:STDOUT:   %.loc34: ref %HasQualifiers = temporary_storage
+// CHECK:STDOUT:   %addr.loc34_3.1: %ptr.ec3 = addr_of %.loc34
+// CHECK:STDOUT:   %ref_this.call: init %empty_tuple.type = call %ref_this.bound(%addr.loc34_3.1)
+// CHECK:STDOUT:   %v.ref.loc43: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %ref_ref_this.ref: <error> = name_ref ref_ref_this, <error> [concrete = <error>]
+// CHECK:STDOUT:   %v.ref.loc52: %HasQualifiers = name_ref v, %v
+// CHECK:STDOUT:   %const_ref_ref_this.ref: <error> = name_ref const_ref_ref_this, <error> [concrete = <error>]
+// CHECK:STDOUT:   %Op.bound.loc34: <bound method> = bound_method %.loc34, constants.%Op.b7c
+// CHECK:STDOUT:   %Op.specific_fn.1: <specific function> = specific_function constants.%Op.b7c, @Op.2(constants.%HasQualifiers) [concrete = constants.%Op.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc34: <bound method> = bound_method %.loc34, %Op.specific_fn.1
+// CHECK:STDOUT:   %addr.loc34_3.2: %ptr.ec3 = addr_of %.loc34
+// CHECK:STDOUT:   %no_op.loc34: init %empty_tuple.type = call %bound_method.loc34(%addr.loc34_3.2)
+// CHECK:STDOUT:   %Op.bound.loc27: <bound method> = bound_method %.loc27, constants.%Op.b7c
+// CHECK:STDOUT:   %Op.specific_fn.2: <specific function> = specific_function constants.%Op.b7c, @Op.2(constants.%HasQualifiers) [concrete = constants.%Op.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc27: <bound method> = bound_method %.loc27, %Op.specific_fn.2
+// CHECK:STDOUT:   %addr.loc27_3.2: %ptr.ec3 = addr_of %.loc27
+// CHECK:STDOUT:   %no_op.loc27: init %empty_tuple.type = call %bound_method.loc27(%addr.loc27_3.2)
+// CHECK:STDOUT:   %Op.bound.loc12: <bound method> = bound_method %.loc12, constants.%Op.b7c
+// CHECK:STDOUT:   %Op.specific_fn.3: <specific function> = specific_function constants.%Op.b7c, @Op.2(constants.%HasQualifiers) [concrete = constants.%Op.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc12: <bound method> = bound_method %.loc12, %Op.specific_fn.3
+// CHECK:STDOUT:   %addr.loc12_3.2: %ptr.ec3 = addr_of %.loc12
+// CHECK:STDOUT:   %no_op.loc12: init %empty_tuple.type = call %bound_method.loc12(%addr.loc12_3.2)
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @plain(%self.param: %ptr.ec3);
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @volatile_this(%self.param: <error>);
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @ref_this(%self.param: %ptr.ec3);
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_todo_bad_object_param_qualifiers_by_ref.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %HasQualifiers: type = class_type @HasQualifiers [concrete]
+// CHECK:STDOUT:   %empty_struct_type: type = struct_type {} [concrete]
+// CHECK:STDOUT:   %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
+// CHECK:STDOUT:   %ptr.ec3: type = ptr_type %HasQualifiers [concrete]
+// CHECK:STDOUT:   %pattern_type.bc1: type = pattern_type %ptr.ec3 [concrete]
+// CHECK:STDOUT:   %Ref.type: type = fn_type @Ref [concrete]
+// CHECK:STDOUT:   %empty_tuple.type: type = tuple_type () [concrete]
+// CHECK:STDOUT:   %Ref: %Ref.type = struct_value () [concrete]
+// CHECK:STDOUT:   %pattern_type.f6d: type = pattern_type auto [concrete]
+// CHECK:STDOUT:   %volatile_this.type: type = fn_type @volatile_this [concrete]
+// CHECK:STDOUT:   %volatile_this: %volatile_this.type = struct_value () [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [concrete] {
+// CHECK:STDOUT:     import Core//prelude
+// CHECK:STDOUT:     import Core//prelude/...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .HasQualifiers = %HasQualifiers.decl
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %HasQualifiers.decl: type = class_decl @HasQualifiers [concrete = constants.%HasQualifiers] {} {}
+// CHECK:STDOUT:   %volatile_this.decl: %volatile_this.type = fn_decl @volatile_this [concrete = constants.%volatile_this] {
+// CHECK:STDOUT:     %self.patt: <error> = binding_pattern self [concrete]
+// CHECK:STDOUT:     %self.param_patt: <error> = value_param_pattern %self.patt, call_param0 [concrete]
+// CHECK:STDOUT:     %.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %self.param: <error> = value_param call_param0
+// CHECK:STDOUT:     %self: <error> = bind_name self, %self.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [concrete] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .Cpp = imports.%Cpp
+// CHECK:STDOUT:     .Ref = %Ref.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %Cpp.import_cpp = import_cpp {
+// CHECK:STDOUT:     import Cpp "object_param_qualifiers.h"
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Ref.decl: %Ref.type = fn_decl @Ref [concrete = constants.%Ref] {
+// CHECK:STDOUT:     %p.patt: %pattern_type.bc1 = binding_pattern p [concrete]
+// CHECK:STDOUT:     %p.param_patt: %pattern_type.bc1 = value_param_pattern %p.patt, call_param0 [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %p.param: %ptr.ec3 = value_param call_param0
+// CHECK:STDOUT:     %.loc6: type = splice_block %ptr [concrete = constants.%ptr.ec3] {
+// CHECK:STDOUT:       %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:       %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
+// CHECK:STDOUT:       %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
+// CHECK:STDOUT:       %HasQualifiers.ref: type = name_ref HasQualifiers, imports.%HasQualifiers.decl [concrete = constants.%HasQualifiers]
+// CHECK:STDOUT:       %ptr: type = ptr_type %HasQualifiers.ref [concrete = constants.%ptr.ec3]
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:     %p: %ptr.ec3 = bind_name p, %p.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @HasQualifiers {
+// CHECK:STDOUT:   complete_type_witness = @Ref.%complete_type
+// CHECK:STDOUT:
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%HasQualifiers
+// CHECK:STDOUT:   .volatile_this = imports.%volatile_this.decl
+// CHECK:STDOUT:   import Cpp//...
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Ref(%p.param: %ptr.ec3) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %p.ref: %ptr.ec3 = name_ref p, %p
+// CHECK:STDOUT:   %.loc15: ref %HasQualifiers = deref %p.ref
+// CHECK:STDOUT:   %volatile_this.ref: %volatile_this.type = name_ref volatile_this, imports.%volatile_this.decl [concrete = constants.%volatile_this]
+// CHECK:STDOUT:   %volatile_this.bound: <bound method> = bound_method %.loc15, %volatile_this.ref
+// CHECK:STDOUT:   %addr: %ptr.ec3 = addr_of %.loc15
+// CHECK:STDOUT:   %volatile_this.call: init %empty_tuple.type = call %volatile_this.bound(<error>)
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @volatile_this(%self.param: <error>);
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_bad_object_param_qualifiers_ref_ref.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %HasQualifiers: type = class_type @HasQualifiers [concrete]
+// CHECK:STDOUT:   %empty_struct_type: type = struct_type {} [concrete]
+// CHECK:STDOUT:   %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
+// CHECK:STDOUT:   %ptr.ec3: type = ptr_type %HasQualifiers [concrete]
+// CHECK:STDOUT:   %pattern_type: type = pattern_type %ptr.ec3 [concrete]
+// CHECK:STDOUT:   %Ref.type: type = fn_type @Ref [concrete]
+// CHECK:STDOUT:   %Ref: %Ref.type = struct_value () [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [concrete] {
+// CHECK:STDOUT:     import Core//prelude
+// CHECK:STDOUT:     import Core//prelude/...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .HasQualifiers = %HasQualifiers.decl
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %HasQualifiers.decl: type = class_decl @HasQualifiers [concrete = constants.%HasQualifiers] {} {}
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   package: <namespace> = namespace [concrete] {
+// CHECK:STDOUT:     .Core = imports.%Core
+// CHECK:STDOUT:     .Cpp = imports.%Cpp
+// CHECK:STDOUT:     .Ref = %Ref.decl
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import = import Core
+// CHECK:STDOUT:   %Cpp.import_cpp = import_cpp {
+// CHECK:STDOUT:     import Cpp "object_param_qualifiers.h"
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Ref.decl: %Ref.type = fn_decl @Ref [concrete = constants.%Ref] {
+// CHECK:STDOUT:     %p.patt: %pattern_type = binding_pattern p [concrete]
+// CHECK:STDOUT:     %p.param_patt: %pattern_type = value_param_pattern %p.patt, call_param0 [concrete]
+// CHECK:STDOUT:   } {
+// CHECK:STDOUT:     %p.param: %ptr.ec3 = value_param call_param0
+// CHECK:STDOUT:     %.loc6: type = splice_block %ptr [concrete = constants.%ptr.ec3] {
+// CHECK:STDOUT:       %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:       %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
+// CHECK:STDOUT:       %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
+// CHECK:STDOUT:       %HasQualifiers.ref: type = name_ref HasQualifiers, imports.%HasQualifiers.decl [concrete = constants.%HasQualifiers]
+// CHECK:STDOUT:       %ptr: type = ptr_type %HasQualifiers.ref [concrete = constants.%ptr.ec3]
+// CHECK:STDOUT:     }
+// CHECK:STDOUT:     %p: %ptr.ec3 = bind_name p, %p.param
+// CHECK:STDOUT:   }
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: class @HasQualifiers {
+// CHECK:STDOUT:   complete_type_witness = @Ref.%complete_type
+// CHECK:STDOUT:
+// CHECK:STDOUT: !members:
+// CHECK:STDOUT:   .Self = constants.%HasQualifiers
+// CHECK:STDOUT:   .ref_ref_this = <error>
+// CHECK:STDOUT:   .const_ref_ref_this = <error>
+// CHECK:STDOUT:   import Cpp//...
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @Ref(%p.param: %ptr.ec3) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %p.ref.loc14: %ptr.ec3 = name_ref p, %p
+// CHECK:STDOUT:   %.loc14: ref %HasQualifiers = deref %p.ref.loc14
+// CHECK:STDOUT:   %ref_ref_this.ref: <error> = name_ref ref_ref_this, <error> [concrete = <error>]
+// CHECK:STDOUT:   %p.ref.loc23: %ptr.ec3 = name_ref p, %p
+// CHECK:STDOUT:   %.loc23: ref %HasQualifiers = deref %p.ref.loc23
+// CHECK:STDOUT:   %const_ref_ref_this.ref: <error> = name_ref const_ref_ref_this, <error> [concrete = <error>]
+// CHECK:STDOUT:   return
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 2 - 73
toolchain/check/testdata/interop/cpp/struct.carbon → toolchain/check/testdata/interop/cpp/class/struct.carbon

@@ -6,9 +6,9 @@
 //
 // AUTOUPDATE
 // TIP: To test this file alone, run:
-// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/struct.carbon
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/struct.carbon
 // TIP: To dump output, run:
-// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/struct.carbon
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/struct.carbon
 
 // ============================================================================
 // Declaration
@@ -115,35 +115,6 @@ fn MyF() {
   Cpp.Bar.foo();
 }
 
-// ============================================================================
-// Public member function
-// ============================================================================
-
-// --- public_member_function.h
-
-struct Bar {
-  auto foo() -> void;
-};
-
-// --- fail_todo_import_public_member_function.carbon
-
-library "[[@TEST_NAME]]";
-
-import Cpp library "public_member_function.h";
-
-//@dump-sem-ir-begin
-fn MyF(bar : Cpp.Bar*) {
-  // CHECK:STDERR: fail_todo_import_public_member_function.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: Non-global function` [SemanticsTodo]
-  // CHECK:STDERR:   bar->foo();
-  // CHECK:STDERR:   ^~~~~~~~
-  // CHECK:STDERR: fail_todo_import_public_member_function.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
-  // CHECK:STDERR:   bar->foo();
-  // CHECK:STDERR:   ^~~~~~~~
-  // CHECK:STDERR:
-  bar->foo();
-}
-//@dump-sem-ir-end
-
 // ============================================================================
 // Public static data member
 // ============================================================================
@@ -506,48 +477,6 @@ fn MyF(bar: Cpp.Bar*);
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_import_public_member_function.carbon
-// CHECK:STDOUT:
-// CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %Bar: type = class_type @Bar [concrete]
-// CHECK:STDOUT:   %ptr.f68: type = ptr_type %Bar [concrete]
-// CHECK:STDOUT:   %pattern_type: type = pattern_type %ptr.f68 [concrete]
-// CHECK:STDOUT:   %MyF.type: type = fn_type @MyF [concrete]
-// CHECK:STDOUT:   %MyF: %MyF.type = struct_value () [concrete]
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: imports {
-// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
-// CHECK:STDOUT:     .Bar = %Bar.decl
-// CHECK:STDOUT:     import Cpp//...
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %Bar.decl: type = class_decl @Bar [concrete = constants.%Bar] {} {}
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: file {
-// CHECK:STDOUT:   %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {
-// CHECK:STDOUT:     %bar.patt: %pattern_type = binding_pattern bar [concrete]
-// CHECK:STDOUT:     %bar.param_patt: %pattern_type = value_param_pattern %bar.patt, call_param0 [concrete]
-// CHECK:STDOUT:   } {
-// CHECK:STDOUT:     %bar.param: %ptr.f68 = value_param call_param0
-// CHECK:STDOUT:     %.loc7: type = splice_block %ptr [concrete = constants.%ptr.f68] {
-// CHECK:STDOUT:       %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
-// CHECK:STDOUT:       <elided>
-// CHECK:STDOUT:       %Bar.ref: type = name_ref Bar, imports.%Bar.decl [concrete = constants.%Bar]
-// CHECK:STDOUT:       %ptr: type = ptr_type %Bar.ref [concrete = constants.%ptr.f68]
-// CHECK:STDOUT:     }
-// CHECK:STDOUT:     %bar: %ptr.f68 = bind_name bar, %bar.param
-// CHECK:STDOUT:   }
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: fn @MyF(%bar.param: %ptr.f68) {
-// CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %bar.ref: %ptr.f68 = name_ref bar, %bar
-// CHECK:STDOUT:   %.loc15: ref %Bar = deref %bar.ref
-// CHECK:STDOUT:   %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
-// CHECK:STDOUT:   return
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: --- fail_todo_import_public_static_data_member.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {

+ 2 - 74
toolchain/check/testdata/interop/cpp/union.carbon → toolchain/check/testdata/interop/cpp/class/union.carbon

@@ -6,9 +6,9 @@
 //
 // AUTOUPDATE
 // TIP: To test this file alone, run:
-// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/union.carbon
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/union.carbon
 // TIP: To dump output, run:
-// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/union.carbon
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/union.carbon
 
 // ============================================================================
 // Declaration
@@ -116,36 +116,6 @@ fn MyF() {
   Cpp.Bar.foo();
 }
 
-// ============================================================================
-// Public member function
-// ============================================================================
-
-// --- public_member_function.h
-
-union Bar {
- public:
-  auto foo() -> void;
-};
-
-// --- fail_todo_import_public_member_function.carbon
-
-library "[[@TEST_NAME]]";
-
-import Cpp library "public_member_function.h";
-
-//@dump-sem-ir-begin
-fn MyF(bar : Cpp.Bar*) {
-  // CHECK:STDERR: fail_todo_import_public_member_function.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: Non-global function` [SemanticsTodo]
-  // CHECK:STDERR:   bar->foo();
-  // CHECK:STDERR:   ^~~~~~~~
-  // CHECK:STDERR: fail_todo_import_public_member_function.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
-  // CHECK:STDERR:   bar->foo();
-  // CHECK:STDERR:   ^~~~~~~~
-  // CHECK:STDERR:
-  bar->foo();
-}
-//@dump-sem-ir-end
-
 // ============================================================================
 // Public static data member
 // ============================================================================
@@ -400,48 +370,6 @@ fn MyF(bar: Cpp.Bar*);
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_import_public_member_function.carbon
-// CHECK:STDOUT:
-// CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %Bar: type = class_type @Bar [concrete]
-// CHECK:STDOUT:   %ptr.f68: type = ptr_type %Bar [concrete]
-// CHECK:STDOUT:   %pattern_type: type = pattern_type %ptr.f68 [concrete]
-// CHECK:STDOUT:   %MyF.type: type = fn_type @MyF [concrete]
-// CHECK:STDOUT:   %MyF: %MyF.type = struct_value () [concrete]
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: imports {
-// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
-// CHECK:STDOUT:     .Bar = %Bar.decl
-// CHECK:STDOUT:     import Cpp//...
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %Bar.decl: type = class_decl @Bar [concrete = constants.%Bar] {} {}
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: file {
-// CHECK:STDOUT:   %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {
-// CHECK:STDOUT:     %bar.patt: %pattern_type = binding_pattern bar [concrete]
-// CHECK:STDOUT:     %bar.param_patt: %pattern_type = value_param_pattern %bar.patt, call_param0 [concrete]
-// CHECK:STDOUT:   } {
-// CHECK:STDOUT:     %bar.param: %ptr.f68 = value_param call_param0
-// CHECK:STDOUT:     %.loc7: type = splice_block %ptr [concrete = constants.%ptr.f68] {
-// CHECK:STDOUT:       %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
-// CHECK:STDOUT:       <elided>
-// CHECK:STDOUT:       %Bar.ref: type = name_ref Bar, imports.%Bar.decl [concrete = constants.%Bar]
-// CHECK:STDOUT:       %ptr: type = ptr_type %Bar.ref [concrete = constants.%ptr.f68]
-// CHECK:STDOUT:     }
-// CHECK:STDOUT:     %bar: %ptr.f68 = bind_name bar, %bar.param
-// CHECK:STDOUT:   }
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: fn @MyF(%bar.param: %ptr.f68) {
-// CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %bar.ref: %ptr.f68 = name_ref bar, %bar
-// CHECK:STDOUT:   %.loc15: ref %Bar = deref %bar.ref
-// CHECK:STDOUT:   %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
-// CHECK:STDOUT:   return
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: --- fail_todo_import_public_static_data_member.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {

+ 11 - 11
toolchain/check/testdata/interop/cpp/function/function.carbon

@@ -141,7 +141,7 @@ fn F() {
 
 static auto foo() -> void;
 
-// --- fail_todo_import_static.carbon
+// --- import_static.carbon
 
 library "[[@TEST_NAME]]";
 
@@ -149,13 +149,8 @@ import Cpp library "static.h";
 
 fn F() {
   //@dump-sem-ir-begin
-  // CHECK:STDERR: fail_todo_import_static.carbon:[[@LINE+7]]:3: error: semantics TODO: `Unsupported: Non-global function` [SemanticsTodo]
-  // CHECK:STDERR:   Cpp.foo();
-  // CHECK:STDERR:   ^~~~~~~
-  // CHECK:STDERR: fail_todo_import_static.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `foo` [InCppNameLookup]
-  // CHECK:STDERR:   Cpp.foo();
-  // CHECK:STDERR:   ^~~~~~~
-  // CHECK:STDERR:
+  // TODO: We should eventually warn or error that `Cpp.foo` has internal
+  // linkage but is not defined.
   Cpp.foo();
   //@dump-sem-ir-end
 }
@@ -253,22 +248,27 @@ fn F() {
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_import_static.carbon
+// CHECK:STDOUT: --- import_static.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %empty_tuple.type: type = tuple_type () [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:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
-// CHECK:STDOUT:     .foo = <error>
+// CHECK:STDOUT:     .foo = %foo.decl
 // CHECK:STDOUT:     import Cpp//...
 // CHECK:STDOUT:   }
+// CHECK:STDOUT:   %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {}
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F() {
 // CHECK:STDOUT: !entry:
 // CHECK:STDOUT:   %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
-// CHECK:STDOUT:   %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
+// CHECK:STDOUT:   %foo.ref: %foo.type = name_ref foo, imports.%foo.decl [concrete = constants.%foo]
+// CHECK:STDOUT:   %foo.call: init %empty_tuple.type = call %foo.ref()
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:

+ 126 - 0
toolchain/lower/testdata/interop/cpp/method.carbon

@@ -0,0 +1,126 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/method.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/method.carbon
+
+// --- methods.h
+
+struct A {
+  int by_val() const { return n; }
+  int by_ref() { return n; }
+  int n;
+};
+
+// --- call_by_val.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp library "methods.h";
+
+fn UseVal(a: Cpp.A) -> i32 {
+  return a.by_val();
+}
+
+// --- call_by_ref.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp library "methods.h";
+
+fn UseVal(a: Cpp.A*) -> i32 {
+  return a->by_ref();
+}
+
+// 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.call = call i32 @_ZNK1A6by_valEv(ptr %a), !dbg !10
+// CHECK:STDOUT:   ret i32 %by_val.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: 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_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:   %by_ref.call = call i32 @_ZN1A6by_refEv(ptr %a), !dbg !10
+// CHECK:STDOUT:   ret i32 %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)

+ 1 - 1
toolchain/sem_ir/typed_insts.h

@@ -103,7 +103,7 @@ struct AddrOf {
 // An `addr` pattern, such as `addr self: Self*`. Structurally, `inner_id` will
 // generally be a pattern inst.
 struct AddrPattern {
-  static constexpr auto Kind = InstKind::AddrPattern.Define<Parse::AddrId>(
+  static constexpr auto Kind = InstKind::AddrPattern.Define<Parse::NodeId>(
       {.ir_name = "addr_pattern",
        .constant_kind = InstConstantKind::AlwaysUnique,
        .is_lowered = false});