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

Allow conversion between `T*` and `Cpp.void*`. (#6575)

Support an implicit conversion from `T*` to `Cpp.void*` and to `const
Cpp.void*`, and an `unsafe as` conversion in the opposite direction.

In order to support C++ calls taking and returning `void*` (which get
mapped to Carbon `Optional(Cpp.void*)`, also support conversions from
`Optional(T)` to `Optional(U)` if there's a conversion from `T` to `U`.

Fix a bug in `OptionalStorage` for `T*` where its `HasValue` was exactly
backwards.
Richard Smith 3 месяцев назад
Родитель
Сommit
31919afa24
31 измененных файлов с 986 добавлено и 381 удалено
  1. 8 0
      core/prelude/operators/as.carbon
  2. 25 4
      core/prelude/types/cpp/void.carbon
  3. 3 1
      core/prelude/types/int.carbon
  4. 16 1
      core/prelude/types/optional.carbon
  5. 3 1
      core/prelude/types/uint.carbon
  6. 2 3
      examples/interop/cpp/hello_world.carbon
  7. 2 1
      toolchain/check/eval.cpp
  8. 8 8
      toolchain/check/testdata/interop/cpp/builtins.llp64.carbon
  9. 8 8
      toolchain/check/testdata/interop/cpp/builtins.lp64.carbon
  10. 8 8
      toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon
  11. 6 6
      toolchain/check/testdata/interop/cpp/function/decayed_param.carbon
  12. 23 23
      toolchain/check/testdata/interop/cpp/function/pointer.carbon
  13. 5 5
      toolchain/check/testdata/interop/cpp/function/void_pointer.carbon
  14. 1 1
      toolchain/check/testdata/interop/cpp/void.carbon
  15. 353 35
      toolchain/check/testdata/interop/cpp/void_pointer.carbon
  16. 4 4
      toolchain/driver/testdata/compile/optimize/optimize_debug.carbon
  17. 4 4
      toolchain/driver/testdata/compile/optimize/optimize_default.carbon
  18. 7 7
      toolchain/driver/testdata/compile/optimize/optimize_none.carbon
  19. 7 7
      toolchain/driver/testdata/compile/optimize/optimize_size.carbon
  20. 4 4
      toolchain/driver/testdata/compile/optimize/optimize_speed.carbon
  21. 5 0
      toolchain/lower/handle_call.cpp
  22. 20 20
      toolchain/lower/testdata/array/iterate.carbon
  23. 9 9
      toolchain/lower/testdata/for/bindings.carbon
  24. 20 20
      toolchain/lower/testdata/for/break_continue.carbon
  25. 20 20
      toolchain/lower/testdata/for/for.carbon
  26. 8 8
      toolchain/lower/testdata/interop/cpp/pointer.carbon
  27. 258 45
      toolchain/lower/testdata/interop/cpp/void.carbon
  28. 7 7
      toolchain/lower/testdata/operators/increment.carbon
  29. 134 121
      toolchain/lower/testdata/primitives/optional.carbon
  30. 7 0
      toolchain/sem_ir/builtin_function_kind.cpp
  31. 1 0
      toolchain/sem_ir/builtin_function_kind.def

+ 8 - 0
core/prelude/operators/as.carbon

@@ -20,6 +20,14 @@ interface ImplicitAs(Dest:! type) {
   fn Convert[self: Self]() -> Dest;
 }
 
+impl forall [U:! type, T:! ImplicitAs(U)] T as As(U) {
+  fn Convert[self: Self]() -> U { return self.Convert(); }
+}
+
+impl forall [U:! type, T:! As(U)] T as UnsafeAs(U) {
+  fn Convert[self: Self]() -> U { return self.Convert(); }
+}
+
 impl forall [T:! Copy] T as ImplicitAs(T) {
   fn Convert[self: Self]() -> Self { return self.(Copy.Op)(); }
 }

+ 25 - 4
core/prelude/types/cpp/void.carbon

@@ -4,6 +4,8 @@
 
 package Core library "prelude/types/cpp/void";
 
+import library "prelude/operators/as";
+
 namespace CppCompat;
 
 // C++ `void` as a Carbon type.
@@ -23,7 +25,26 @@ abstract class CppCompat.VoidBase {
   adapt ();
 }
 
-// TODO: An unqualified pointer to `T` should implicitly convert to a pointer to
-// `<qualifiers> void` if `<qualifiers>` includes all of the qualifiers for `T`.
-// Similarly, a value of type `T` should implicitly convert to a value of type
-// `void`.
+// TODO: Support a conversion from a value of any type to a value of type
+// `Cpp.void` once we allow defining a conversion to a value category rather
+// than to an initializing category.
+
+// TODO: Do not allow a pointer to `const T` to convert to `Cpp.void*`.
+// #6357 allows it, and we don't have a good way to express "non-const" as a
+// constraint on this impl, but this conversion is not const-correct.
+impl forall [T:! type] T* as ImplicitAs(CppCompat.VoidBase*) {
+  fn Convert[self: T*]() -> CppCompat.VoidBase* = "pointer.unsafe_convert";
+}
+
+impl forall [T:! type] T* as ImplicitAs(const CppCompat.VoidBase*) {
+  fn Convert[self: T*]() -> CppCompat.VoidBase* = "pointer.unsafe_convert";
+}
+
+impl forall [T:! type] CppCompat.VoidBase* as UnsafeAs(T*) {
+  fn Convert[self: CppCompat.VoidBase*]() -> T* = "pointer.unsafe_convert";
+}
+
+// TODO: Should `unsafe as` be able to remove `const`?
+impl forall [T:! type] const CppCompat.VoidBase* as UnsafeAs(const T*) {
+  fn Convert[self: const CppCompat.VoidBase*]() -> const T* = "pointer.unsafe_convert";
+}

+ 3 - 1
core/prelude/types/int.carbon

@@ -31,7 +31,9 @@ final impl forall [From:! IntLiteral()] Int(From) as ImplicitAs(IntLiteral()) {
   fn Convert[self: Self]() -> IntLiteral() = "int.convert_checked";
 }
 
-// TODO: Remove these once ImplicitAs extends As.
+// TODO: Remove these once ImplicitAs extends As. For now we need them because
+// the forwarding impl of As in terms of ImplicitAs is not usable at compile
+// time.
 impl forall [To:! IntLiteral()] IntLiteral() as As(Int(To)) {
   fn Convert[self: Self]() -> Int(To) = "int.convert_checked";
 }

+ 16 - 1
core/prelude/types/optional.carbon

@@ -77,6 +77,17 @@ impl forall [T:! Destroy & OptionalStorage, U:! ImplicitAs(T)]
   }
 }
 
+impl forall [T:! Destroy & OptionalStorage,
+             U:! Destroy & OptionalStorage & ImplicitAs(T)]
+    Optional(U) as OptionalAs(T) {
+  fn Convert[self: Self]() -> Optional(T) {
+    if (self.HasValue()) {
+      return Optional(T).Some(self.Get().Convert());
+    }
+    return Optional(T).None();
+  }
+}
+
 impl forall [T:! OptionalStorage, U:! OptionalAs(T)]
     U as ImplicitAs(Optional(T)) {
   fn Convert[self: Self]() -> Optional(T) {
@@ -117,6 +128,8 @@ impl forall [T:! Copy & Destroy] T as OptionalStorage
   }
 }
 
+private fn PointerIsNull[T:! type](value: MaybeUnformed(T*)) -> bool = "pointer.is_null";
+
 // For pointers, we use a null pointer value as the "None" value. This allows
 // `Optional(T*)` to be ABI-compatible with a C++ nullable pointer.
 final impl forall [T:! type] T* as OptionalStorage
@@ -127,7 +140,9 @@ final impl forall [T:! type] T* as OptionalStorage
     result unsafe as T* = self;
     return var;
   }
-  fn Has(value: MaybeUnformed(T*)) -> bool = "pointer.is_null";
+  fn Has(value: MaybeUnformed(T*)) -> bool {
+    return not PointerIsNull(value);
+  }
   fn Get(value: MaybeUnformed(T*)) -> T* {
     return value unsafe as T*;
   }

+ 3 - 1
core/prelude/types/uint.carbon

@@ -32,7 +32,9 @@ final impl forall [From:! IntLiteral()] UInt(From) as ImplicitAs(IntLiteral()) {
   fn Convert[self: Self]() -> IntLiteral() = "int.convert_checked";
 }
 
-// TODO: Remove these once ImplicitAs extends As.
+// TODO: Remove these once ImplicitAs extends As. For now we need them because
+// the forwarding impl of As in terms of ImplicitAs is not usable at compile
+// time.
 impl forall [To:! IntLiteral()] IntLiteral() as As(UInt(To)) {
   fn Convert[self: Self]() -> UInt(To) = "int.convert_checked";
 }

+ 2 - 3
examples/interop/cpp/hello_world.carbon

@@ -37,9 +37,8 @@ fn HelloStdio() {
 
 // Demonstrate passing a string as a void pointer to a C++ function.
 fn HelloWrite() {
-  // TODO: Requires conversion from `const char*` to `const void*`.
-  // let s: str = "Hello world!\n";
-  // Cpp.write(1, Cpp.std.data(s), Cpp.std.size(s));
+  let s: str = "Hello world!\n";
+  Cpp.write(1, Cpp.std.data(s), Cpp.std.size(s));
 }
 
 fn HelloIostreams() {

+ 2 - 1
toolchain/check/eval.cpp

@@ -1783,7 +1783,8 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context,
     case SemIR::BuiltinFunctionKind::IntLeftShiftAssign:
     case SemIR::BuiltinFunctionKind::IntRightShiftAssign:
     case SemIR::BuiltinFunctionKind::PointerMakeNull:
-    case SemIR::BuiltinFunctionKind::PointerIsNull: {
+    case SemIR::BuiltinFunctionKind::PointerIsNull:
+    case SemIR::BuiltinFunctionKind::PointerUnsafeConvert: {
       // These are runtime-only builtins.
       // TODO: Consider tracking this on the `BuiltinFunctionKind`.
       return SemIR::ConstantId::NotConstant;

+ 8 - 8
toolchain/check/testdata/interop/cpp/builtins.llp64.carbon

@@ -516,8 +516,8 @@ fn F() {
 // CHECK:STDOUT:   %As.generic: %As.type.90f = struct_value () [concrete]
 // CHECK:STDOUT:   %As.type.508: type = facet_type <@As, @As(%Cpp.long)> [concrete]
 // CHECK:STDOUT:   %As.Convert.type.229: type = fn_type @As.Convert, @As(%Cpp.long) [concrete]
-// CHECK:STDOUT:   %As.impl_witness: <witness> = impl_witness imports.%As.impl_witness_table [concrete]
-// CHECK:STDOUT:   %As.facet: %As.type.508 = facet_value Core.IntLiteral, (%As.impl_witness) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.60c: <witness> = impl_witness imports.%As.impl_witness_table.797 [concrete]
+// CHECK:STDOUT:   %As.facet: %As.type.508 = facet_value Core.IntLiteral, (%As.impl_witness.60c) [concrete]
 // CHECK:STDOUT:   %.040: type = fn_type_with_self_type %As.Convert.type.229, %As.facet [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert.type: type = fn_type @Core.IntLiteral.as.As.impl.Convert [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert: %Core.IntLiteral.as.As.impl.Convert.type = struct_value () [concrete]
@@ -662,7 +662,7 @@ fn F() {
 // CHECK:STDOUT:   %Core.Float: %Float.type = import_ref Core//prelude/types/float, Float, loaded [concrete = constants.%Float.generic]
 // CHECK:STDOUT:   %Core.As: %As.type.90f = import_ref Core//prelude/operators/as, As, loaded [concrete = constants.%As.generic]
 // CHECK:STDOUT:   %Core.import_ref.686: %Core.IntLiteral.as.As.impl.Convert.type = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.686), @Core.IntLiteral.as.As.impl.a00 [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.797 = impl_witness_table (%Core.import_ref.686), @Core.IntLiteral.as.As.impl.a00 [concrete]
 // CHECK:STDOUT:   %Core.import_ref.168: %Cpp.long.as.ImplicitAs.impl.Convert.type.9ed = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Cpp.long.as.ImplicitAs.impl.Convert.d49]
 // CHECK:STDOUT:   %ImplicitAs.impl_witness_table.a09 = impl_witness_table (%Core.import_ref.168), @Cpp.long.as.ImplicitAs.impl.e94 [concrete]
 // CHECK:STDOUT:   %Core.import_ref.38a: @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type (%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type.02f) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert (constants.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.1f0)]
@@ -810,7 +810,7 @@ fn F() {
 // CHECK:STDOUT:     %int_1.loc24: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
 // CHECK:STDOUT:     %Cpp.ref.loc24: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
 // CHECK:STDOUT:     %long.ref.loc24: type = name_ref long, constants.%Cpp.long [concrete = constants.%Cpp.long]
-// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.040 = impl_witness_access constants.%As.impl_witness, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
+// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.040 = impl_witness_access constants.%As.impl_witness.60c, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
 // CHECK:STDOUT:     %bound_method.loc24_23.1: <bound method> = bound_method %int_1.loc24, %impl.elem0.loc24_23.1 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
 // CHECK:STDOUT:     %Core.IntLiteral.as.As.impl.Convert.call: init %Cpp.long = call %bound_method.loc24_23.1(%int_1.loc24) [concrete = constants.%int_1.5a4]
 // CHECK:STDOUT:     %.loc24_23.1: %Cpp.long = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_1.5a4]
@@ -1083,8 +1083,8 @@ fn F() {
 // CHECK:STDOUT:   %As.generic: %As.type.90f = struct_value () [concrete]
 // CHECK:STDOUT:   %As.type.950: type = facet_type <@As, @As(%Cpp.unsigned_long)> [concrete]
 // CHECK:STDOUT:   %As.Convert.type.3ff: type = fn_type @As.Convert, @As(%Cpp.unsigned_long) [concrete]
-// CHECK:STDOUT:   %As.impl_witness: <witness> = impl_witness imports.%As.impl_witness_table [concrete]
-// CHECK:STDOUT:   %As.facet: %As.type.950 = facet_value Core.IntLiteral, (%As.impl_witness) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.d5f: <witness> = impl_witness imports.%As.impl_witness_table.f58 [concrete]
+// CHECK:STDOUT:   %As.facet: %As.type.950 = facet_value Core.IntLiteral, (%As.impl_witness.d5f) [concrete]
 // CHECK:STDOUT:   %.80d: type = fn_type_with_self_type %As.Convert.type.3ff, %As.facet [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert.type: type = fn_type @Core.IntLiteral.as.As.impl.Convert [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert: %Core.IntLiteral.as.As.impl.Convert.type = struct_value () [concrete]
@@ -1171,7 +1171,7 @@ fn F() {
 // CHECK:STDOUT:   %Core.Float: %Float.type = import_ref Core//prelude/types/float, Float, loaded [concrete = constants.%Float.generic]
 // CHECK:STDOUT:   %Core.As: %As.type.90f = import_ref Core//prelude/operators/as, As, loaded [concrete = constants.%As.generic]
 // CHECK:STDOUT:   %Core.import_ref.190: %Core.IntLiteral.as.As.impl.Convert.type = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.190), @Core.IntLiteral.as.As.impl.8c9 [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.f58 = impl_witness_table (%Core.import_ref.190), @Core.IntLiteral.as.As.impl.8c9 [concrete]
 // CHECK:STDOUT:   %Core.import_ref.f5e: %Cpp.unsigned_long.as.ImplicitAs.impl.Convert.type.a9d = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Cpp.unsigned_long.as.ImplicitAs.impl.Convert.e53]
 // CHECK:STDOUT:   %ImplicitAs.impl_witness_table.50d = impl_witness_table (%Core.import_ref.f5e), @Cpp.unsigned_long.as.ImplicitAs.impl.78e [concrete]
 // CHECK:STDOUT:   %Core.import_ref.38a: @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type (%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type.02f) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert (constants.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.1f0)]
@@ -1295,7 +1295,7 @@ fn F() {
 // CHECK:STDOUT:     %int_1.loc24: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
 // CHECK:STDOUT:     %Cpp.ref.loc24: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
 // CHECK:STDOUT:     %unsigned_long.ref.loc24: type = name_ref unsigned_long, constants.%Cpp.unsigned_long [concrete = constants.%Cpp.unsigned_long]
-// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.80d = impl_witness_access constants.%As.impl_witness, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
+// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.80d = impl_witness_access constants.%As.impl_witness.d5f, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
 // CHECK:STDOUT:     %bound_method.loc24_23.1: <bound method> = bound_method %int_1.loc24, %impl.elem0.loc24_23.1 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
 // CHECK:STDOUT:     %Core.IntLiteral.as.As.impl.Convert.call: init %Cpp.unsigned_long = call %bound_method.loc24_23.1(%int_1.loc24) [concrete = constants.%int_1.0ab]
 // CHECK:STDOUT:     %.loc24_23.1: %Cpp.unsigned_long = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_1.0ab]

+ 8 - 8
toolchain/check/testdata/interop/cpp/builtins.lp64.carbon

@@ -482,8 +482,8 @@ fn F() {
 // CHECK:STDOUT:   %As.generic: %As.type.90f = struct_value () [concrete]
 // CHECK:STDOUT:   %As.type.b3e: type = facet_type <@As, @As(%Cpp.long_long)> [concrete]
 // CHECK:STDOUT:   %As.Convert.type.92c: type = fn_type @As.Convert, @As(%Cpp.long_long) [concrete]
-// CHECK:STDOUT:   %As.impl_witness: <witness> = impl_witness imports.%As.impl_witness_table [concrete]
-// CHECK:STDOUT:   %As.facet: %As.type.b3e = facet_value Core.IntLiteral, (%As.impl_witness) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.158: <witness> = impl_witness imports.%As.impl_witness_table.eb3 [concrete]
+// CHECK:STDOUT:   %As.facet: %As.type.b3e = facet_value Core.IntLiteral, (%As.impl_witness.158) [concrete]
 // CHECK:STDOUT:   %.ae2: type = fn_type_with_self_type %As.Convert.type.92c, %As.facet [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert.type: type = fn_type @Core.IntLiteral.as.As.impl.Convert [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert: %Core.IntLiteral.as.As.impl.Convert.type = struct_value () [concrete]
@@ -570,7 +570,7 @@ fn F() {
 // CHECK:STDOUT:   %Core.Float: %Float.type = import_ref Core//prelude/types/float, Float, loaded [concrete = constants.%Float.generic]
 // CHECK:STDOUT:   %Core.As: %As.type.90f = import_ref Core//prelude/operators/as, As, loaded [concrete = constants.%As.generic]
 // CHECK:STDOUT:   %Core.import_ref.cdc: %Core.IntLiteral.as.As.impl.Convert.type = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.cdc), @Core.IntLiteral.as.As.impl.823 [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.eb3 = impl_witness_table (%Core.import_ref.cdc), @Core.IntLiteral.as.As.impl.823 [concrete]
 // CHECK:STDOUT:   %Core.import_ref.74a: %Cpp.long_long.as.ImplicitAs.impl.Convert.type.506 = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Cpp.long_long.as.ImplicitAs.impl.Convert.ad2]
 // CHECK:STDOUT:   %ImplicitAs.impl_witness_table.64f = impl_witness_table (%Core.import_ref.74a), @Cpp.long_long.as.ImplicitAs.impl.60b [concrete]
 // CHECK:STDOUT:   %Core.import_ref.38a: @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type (%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type.02f) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert (constants.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.1f0)]
@@ -694,7 +694,7 @@ fn F() {
 // CHECK:STDOUT:     %int_1.loc24: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
 // CHECK:STDOUT:     %Cpp.ref.loc24: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
 // CHECK:STDOUT:     %long_long.ref.loc24: type = name_ref long_long, constants.%Cpp.long_long [concrete = constants.%Cpp.long_long]
-// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.ae2 = impl_witness_access constants.%As.impl_witness, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
+// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.ae2 = impl_witness_access constants.%As.impl_witness.158, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
 // CHECK:STDOUT:     %bound_method.loc24_23.1: <bound method> = bound_method %int_1.loc24, %impl.elem0.loc24_23.1 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
 // CHECK:STDOUT:     %Core.IntLiteral.as.As.impl.Convert.call: init %Cpp.long_long = call %bound_method.loc24_23.1(%int_1.loc24) [concrete = constants.%int_1.092]
 // CHECK:STDOUT:     %.loc24_23.1: %Cpp.long_long = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_1.092]
@@ -777,8 +777,8 @@ fn F() {
 // CHECK:STDOUT:   %As.generic: %As.type.90f = struct_value () [concrete]
 // CHECK:STDOUT:   %As.type.45a: type = facet_type <@As, @As(%Cpp.unsigned_long_long)> [concrete]
 // CHECK:STDOUT:   %As.Convert.type.2e6: type = fn_type @As.Convert, @As(%Cpp.unsigned_long_long) [concrete]
-// CHECK:STDOUT:   %As.impl_witness: <witness> = impl_witness imports.%As.impl_witness_table [concrete]
-// CHECK:STDOUT:   %As.facet: %As.type.45a = facet_value Core.IntLiteral, (%As.impl_witness) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.d1f: <witness> = impl_witness imports.%As.impl_witness_table.002 [concrete]
+// CHECK:STDOUT:   %As.facet: %As.type.45a = facet_value Core.IntLiteral, (%As.impl_witness.d1f) [concrete]
 // CHECK:STDOUT:   %.097: type = fn_type_with_self_type %As.Convert.type.2e6, %As.facet [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert.type: type = fn_type @Core.IntLiteral.as.As.impl.Convert [concrete]
 // CHECK:STDOUT:   %Core.IntLiteral.as.As.impl.Convert: %Core.IntLiteral.as.As.impl.Convert.type = struct_value () [concrete]
@@ -865,7 +865,7 @@ fn F() {
 // CHECK:STDOUT:   %Core.Float: %Float.type = import_ref Core//prelude/types/float, Float, loaded [concrete = constants.%Float.generic]
 // CHECK:STDOUT:   %Core.As: %As.type.90f = import_ref Core//prelude/operators/as, As, loaded [concrete = constants.%As.generic]
 // CHECK:STDOUT:   %Core.import_ref.7e9: %Core.IntLiteral.as.As.impl.Convert.type = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.7e9), @Core.IntLiteral.as.As.impl.b6f [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.002 = impl_witness_table (%Core.import_ref.7e9), @Core.IntLiteral.as.As.impl.b6f [concrete]
 // CHECK:STDOUT:   %Core.import_ref.5ac: %Cpp.unsigned_long_long.as.ImplicitAs.impl.Convert.type.109 = import_ref Core//prelude/types/cpp/int, loc{{\d+_\d+}}, loaded [concrete = constants.%Cpp.unsigned_long_long.as.ImplicitAs.impl.Convert.ffb]
 // CHECK:STDOUT:   %ImplicitAs.impl_witness_table.d12 = impl_witness_table (%Core.import_ref.5ac), @Cpp.unsigned_long_long.as.ImplicitAs.impl.fca [concrete]
 // CHECK:STDOUT:   %Core.import_ref.38a: @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type (%Core.FloatLiteral.as.ImplicitAs.impl.Convert.type.02f) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.ImplicitAs.impl.%Core.FloatLiteral.as.ImplicitAs.impl.Convert (constants.%Core.FloatLiteral.as.ImplicitAs.impl.Convert.1f0)]
@@ -989,7 +989,7 @@ fn F() {
 // CHECK:STDOUT:     %int_1.loc24: Core.IntLiteral = int_value 1 [concrete = constants.%int_1.5b8]
 // CHECK:STDOUT:     %Cpp.ref.loc24: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
 // CHECK:STDOUT:     %unsigned_long_long.ref.loc24: type = name_ref unsigned_long_long, constants.%Cpp.unsigned_long_long [concrete = constants.%Cpp.unsigned_long_long]
-// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.097 = impl_witness_access constants.%As.impl_witness, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
+// CHECK:STDOUT:     %impl.elem0.loc24_23.1: %.097 = impl_witness_access constants.%As.impl_witness.d1f, element0 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert]
 // CHECK:STDOUT:     %bound_method.loc24_23.1: <bound method> = bound_method %int_1.loc24, %impl.elem0.loc24_23.1 [concrete = constants.%Core.IntLiteral.as.As.impl.Convert.bound]
 // CHECK:STDOUT:     %Core.IntLiteral.as.As.impl.Convert.call: init %Cpp.unsigned_long_long = call %bound_method.loc24_23.1(%int_1.loc24) [concrete = constants.%int_1.79a]
 // CHECK:STDOUT:     %.loc24_23.1: %Cpp.unsigned_long_long = value_of_initializer %Core.IntLiteral.as.As.impl.Convert.call [concrete = constants.%int_1.79a]

+ 8 - 8
toolchain/check/testdata/interop/cpp/function/arithmetic_types_bridged.carbon

@@ -1721,7 +1721,7 @@ fn F() {
 // CHECK:STDOUT:   %As.Convert.type.c23: type = fn_type @As.Convert, @As(%f16.a6a) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.882: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%N) [symbolic]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.27d: %Core.FloatLiteral.as.As.impl.Convert.type.882 = struct_value () [symbolic]
-// CHECK:STDOUT:   %As.impl_witness.0d1: <witness> = impl_witness imports.%As.impl_witness_table, @Core.FloatLiteral.as.As.impl(%int_16) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.0d1: <witness> = impl_witness imports.%As.impl_witness_table.7c1, @Core.FloatLiteral.as.As.impl(%int_16) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.ae9: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%int_16) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.3fd: %Core.FloatLiteral.as.As.impl.Convert.type.ae9 = struct_value () [concrete]
 // CHECK:STDOUT:   %As.facet: %As.type.b64 = facet_value Core.FloatLiteral, (%As.impl_witness.0d1) [concrete]
@@ -1756,7 +1756,7 @@ fn F() {
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %foo.cpp_overload_set.value: %foo.cpp_overload_set.type = cpp_overload_set_value @foo.cpp_overload_set [concrete = constants.%foo.cpp_overload_set.value]
 // CHECK:STDOUT:   %Core.import_ref.509: @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert.type (%Core.FloatLiteral.as.As.impl.Convert.type.882) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert (constants.%Core.FloatLiteral.as.As.impl.Convert.27d)]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.7c1 = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
 // CHECK:STDOUT:   %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
 // CHECK:STDOUT:     <elided>
 // CHECK:STDOUT:   } {
@@ -1810,7 +1810,7 @@ fn F() {
 // CHECK:STDOUT:   %As.Convert.type.f5e: type = fn_type @As.Convert, @As(%f32.97e) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.882: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%N) [symbolic]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.27d: %Core.FloatLiteral.as.As.impl.Convert.type.882 = struct_value () [symbolic]
-// CHECK:STDOUT:   %As.impl_witness.748: <witness> = impl_witness imports.%As.impl_witness_table, @Core.FloatLiteral.as.As.impl(%int_32) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.748: <witness> = impl_witness imports.%As.impl_witness_table.7c1, @Core.FloatLiteral.as.As.impl(%int_32) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.847: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%int_32) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.683: %Core.FloatLiteral.as.As.impl.Convert.type.847 = struct_value () [concrete]
 // CHECK:STDOUT:   %As.facet: %As.type.9fc = facet_value Core.FloatLiteral, (%As.impl_witness.748) [concrete]
@@ -1845,7 +1845,7 @@ fn F() {
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %foo.cpp_overload_set.value: %foo.cpp_overload_set.type = cpp_overload_set_value @foo.cpp_overload_set [concrete = constants.%foo.cpp_overload_set.value]
 // CHECK:STDOUT:   %Core.import_ref.509: @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert.type (%Core.FloatLiteral.as.As.impl.Convert.type.882) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert (constants.%Core.FloatLiteral.as.As.impl.Convert.27d)]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.7c1 = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
 // CHECK:STDOUT:   %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
 // CHECK:STDOUT:     <elided>
 // CHECK:STDOUT:   } {
@@ -1899,7 +1899,7 @@ fn F() {
 // CHECK:STDOUT:   %As.Convert.type.8fc: type = fn_type @As.Convert, @As(%f64.d77) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.882: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%N) [symbolic]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.27d: %Core.FloatLiteral.as.As.impl.Convert.type.882 = struct_value () [symbolic]
-// CHECK:STDOUT:   %As.impl_witness.187: <witness> = impl_witness imports.%As.impl_witness_table, @Core.FloatLiteral.as.As.impl(%int_64) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.187: <witness> = impl_witness imports.%As.impl_witness_table.7c1, @Core.FloatLiteral.as.As.impl(%int_64) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.07c: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%int_64) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.4b9: %Core.FloatLiteral.as.As.impl.Convert.type.07c = struct_value () [concrete]
 // CHECK:STDOUT:   %As.facet: %As.type.a57 = facet_value Core.FloatLiteral, (%As.impl_witness.187) [concrete]
@@ -1934,7 +1934,7 @@ fn F() {
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %foo.cpp_overload_set.value: %foo.cpp_overload_set.type = cpp_overload_set_value @foo.cpp_overload_set [concrete = constants.%foo.cpp_overload_set.value]
 // CHECK:STDOUT:   %Core.import_ref.509: @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert.type (%Core.FloatLiteral.as.As.impl.Convert.type.882) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert (constants.%Core.FloatLiteral.as.As.impl.Convert.27d)]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.7c1 = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
 // CHECK:STDOUT:   %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
 // CHECK:STDOUT:     <elided>
 // CHECK:STDOUT:   } {
@@ -1988,7 +1988,7 @@ fn F() {
 // CHECK:STDOUT:   %As.Convert.type.3bf: type = fn_type @As.Convert, @As(%f128.b8c) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.882: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%N) [symbolic]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.27d: %Core.FloatLiteral.as.As.impl.Convert.type.882 = struct_value () [symbolic]
-// CHECK:STDOUT:   %As.impl_witness.738: <witness> = impl_witness imports.%As.impl_witness_table, @Core.FloatLiteral.as.As.impl(%int_128) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.738: <witness> = impl_witness imports.%As.impl_witness_table.7c1, @Core.FloatLiteral.as.As.impl(%int_128) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.type.e6b: type = fn_type @Core.FloatLiteral.as.As.impl.Convert, @Core.FloatLiteral.as.As.impl(%int_128) [concrete]
 // CHECK:STDOUT:   %Core.FloatLiteral.as.As.impl.Convert.3b3: %Core.FloatLiteral.as.As.impl.Convert.type.e6b = struct_value () [concrete]
 // CHECK:STDOUT:   %As.facet: %As.type.6c6 = facet_value Core.FloatLiteral, (%As.impl_witness.738) [concrete]
@@ -2023,7 +2023,7 @@ fn F() {
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %foo.cpp_overload_set.value: %foo.cpp_overload_set.type = cpp_overload_set_value @foo.cpp_overload_set [concrete = constants.%foo.cpp_overload_set.value]
 // CHECK:STDOUT:   %Core.import_ref.509: @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert.type (%Core.FloatLiteral.as.As.impl.Convert.type.882) = import_ref Core//prelude/types/float, loc{{\d+_\d+}}, loaded [symbolic = @Core.FloatLiteral.as.As.impl.%Core.FloatLiteral.as.As.impl.Convert (constants.%Core.FloatLiteral.as.As.impl.Convert.27d)]
-// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
+// CHECK:STDOUT:   %As.impl_witness_table.7c1 = impl_witness_table (%Core.import_ref.509), @Core.FloatLiteral.as.As.impl [concrete]
 // CHECK:STDOUT:   %foo__carbon_thunk.decl: %foo__carbon_thunk.type = fn_decl @foo__carbon_thunk [concrete = constants.%foo__carbon_thunk] {
 // CHECK:STDOUT:     <elided>
 // CHECK:STDOUT:   } {

+ 6 - 6
toolchain/check/testdata/interop/cpp/function/decayed_param.carbon

@@ -150,10 +150,10 @@ fn F() {
 // CHECK:STDOUT:   %Cpp.nullptr_t.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %uninit, %Cpp.nullptr_t.as.ImplicitAs.impl.Convert.2fd [concrete]
 // CHECK:STDOUT:   %Cpp.nullptr_t.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Cpp.nullptr_t.as.ImplicitAs.impl.Convert.2fd, @Cpp.nullptr_t.as.ImplicitAs.impl.Convert(%i32) [concrete]
 // CHECK:STDOUT:   %bound_method.3f0: <bound method> = bound_method %uninit, %Cpp.nullptr_t.as.ImplicitAs.impl.Convert.specific_fn [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc13 [concrete]
-// CHECK:STDOUT:   %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.7: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.7: type = fn_type @DestroyOp.loc13 [concrete]
 // CHECK:STDOUT:   %DestroyOp.b0ebf8.7: %DestroyOp.type.3e79c2.7 = struct_value () [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.8: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.b0ebf8.8: %DestroyOp.type.3e79c2.8 = struct_value () [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -245,11 +245,11 @@ fn F() {
 // CHECK:STDOUT:   %.loc13_21.3: ref %Optional.f08 = temporary %.loc13_21.2, %.loc13_21.1
 // CHECK:STDOUT:   %.loc13_21.4: %Optional.f08 = acquire_value %.loc13_21.3
 // CHECK:STDOUT:   %TakesArray.call.loc13: init %empty_tuple.type = call imports.%TakesArray.decl(%.loc13_21.4)
-// CHECK:STDOUT:   %DestroyOp.bound.loc13: <bound method> = bound_method %.loc13_21.3, constants.%DestroyOp.b0ebf8.6
+// CHECK:STDOUT:   %DestroyOp.bound.loc13: <bound method> = bound_method %.loc13_21.3, constants.%DestroyOp.b0ebf8.7
 // CHECK:STDOUT:   %DestroyOp.call.loc13: init %empty_tuple.type = call %DestroyOp.bound.loc13(%.loc13_21.3)
-// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_18.3, constants.%DestroyOp.b0ebf8.6
+// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_18.3, constants.%DestroyOp.b0ebf8.7
 // CHECK:STDOUT:   %DestroyOp.call.loc11: init %empty_tuple.type = call %DestroyOp.bound.loc11(%.loc11_18.3)
-// CHECK:STDOUT:   %DestroyOp.bound.loc10: <bound method> = bound_method %n.var, constants.%DestroyOp.b0ebf8.7
+// CHECK:STDOUT:   %DestroyOp.bound.loc10: <bound method> = bound_method %n.var, constants.%DestroyOp.b0ebf8.8
 // CHECK:STDOUT:   %DestroyOp.call.loc10: init %empty_tuple.type = call %DestroyOp.bound.loc10(%n.var)
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }

+ 23 - 23
toolchain/check/testdata/interop/cpp/function/pointer.carbon

@@ -955,10 +955,10 @@ fn F() {
 // CHECK:STDOUT:   %ImplicitAs.facet.37f: %ImplicitAs.type.42a = facet_value %const.b9a, (%ImplicitAs.impl_witness.e86) [concrete]
 // CHECK:STDOUT:   %.452: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet.37f [concrete]
 // CHECK:STDOUT:   %const.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %const.as.ImplicitAs.impl.Convert.1d8, @const.as.ImplicitAs.impl.Convert(%Optional.5a9, %ImplicitAs.facet.168) [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.5: type = fn_type @DestroyOp.loc11 [concrete]
-// CHECK:STDOUT:   %DestroyOp.b0ebf8.5: %DestroyOp.type.3e79c2.5 = struct_value () [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc11 [concrete]
 // CHECK:STDOUT:   %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.7: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.b0ebf8.7: %DestroyOp.type.3e79c2.7 = struct_value () [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -1025,9 +1025,9 @@ fn F() {
 // CHECK:STDOUT:   %.loc11_11.4: ref %Optional.5a9 = temporary %.loc11_11.3, %.loc11_11.2
 // CHECK:STDOUT:   %.loc11_11.5: %Optional.5a9 = acquire_value %.loc11_11.4
 // CHECK:STDOUT:   %foo.call: init %empty_tuple.type = call imports.%foo.decl(%.loc11_11.5)
-// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_11.4, constants.%DestroyOp.b0ebf8.5
+// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_11.4, constants.%DestroyOp.b0ebf8.6
 // CHECK:STDOUT:   %DestroyOp.call.loc11: init %empty_tuple.type = call %DestroyOp.bound.loc11(%.loc11_11.4)
-// CHECK:STDOUT:   %DestroyOp.bound.loc10: <bound method> = bound_method %p.var, constants.%DestroyOp.b0ebf8.6
+// CHECK:STDOUT:   %DestroyOp.bound.loc10: <bound method> = bound_method %p.var, constants.%DestroyOp.b0ebf8.7
 // CHECK:STDOUT:   %DestroyOp.call.loc10: init %empty_tuple.type = call %DestroyOp.bound.loc10(%p.var)
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
@@ -1078,13 +1078,13 @@ fn F() {
 // CHECK:STDOUT:   %ImplicitAs.impl_witness.368: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.840, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.type.5eb: type = fn_type @U.binding.as_type.as.ImplicitAs.impl.Convert.2, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.e6d: %U.binding.as_type.as.ImplicitAs.impl.Convert.type.5eb = struct_value () [concrete]
-// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.42a = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.368) [concrete]
-// CHECK:STDOUT:   %.bdc: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet.168: %ImplicitAs.type.42a = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.368) [concrete]
+// CHECK:STDOUT:   %.bdc: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet.168 [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %U.binding.as_type.as.ImplicitAs.impl.Convert.e6d, @U.binding.as_type.as.ImplicitAs.impl.Convert.2(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.5: type = fn_type @DestroyOp.loc11 [concrete]
-// CHECK:STDOUT:   %DestroyOp.b0ebf8.5: %DestroyOp.type.3e79c2.5 = struct_value () [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc11 [concrete]
 // CHECK:STDOUT:   %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.7: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.b0ebf8.7: %DestroyOp.type.3e79c2.7 = struct_value () [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -1148,9 +1148,9 @@ fn F() {
 // CHECK:STDOUT:   %.loc11_11.4: ref %Optional.5a9 = temporary %.loc11_11.3, %.loc11_11.2
 // CHECK:STDOUT:   %.loc11_11.5: %Optional.5a9 = acquire_value %.loc11_11.4
 // CHECK:STDOUT:   %foo.call: init %empty_tuple.type = call imports.%foo.decl(%.loc11_11.5)
-// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_11.4, constants.%DestroyOp.b0ebf8.5
+// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_11.4, constants.%DestroyOp.b0ebf8.6
 // CHECK:STDOUT:   %DestroyOp.call.loc11: init %empty_tuple.type = call %DestroyOp.bound.loc11(%.loc11_11.4)
-// CHECK:STDOUT:   %DestroyOp.bound.loc10: <bound method> = bound_method %p.var, constants.%DestroyOp.b0ebf8.6
+// CHECK:STDOUT:   %DestroyOp.bound.loc10: <bound method> = bound_method %p.var, constants.%DestroyOp.b0ebf8.7
 // CHECK:STDOUT:   %DestroyOp.call.loc10: init %empty_tuple.type = call %DestroyOp.bound.loc10(%p.var)
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
@@ -1336,11 +1336,11 @@ fn F() {
 // CHECK:STDOUT:   %ImplicitAs.impl_witness.368: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.840, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.type.5eb: type = fn_type @U.binding.as_type.as.ImplicitAs.impl.Convert.2, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.e6d: %U.binding.as_type.as.ImplicitAs.impl.Convert.type.5eb = struct_value () [concrete]
-// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.42a = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.368) [concrete]
-// CHECK:STDOUT:   %.bdc: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet.168: %ImplicitAs.type.42a = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.368) [concrete]
+// CHECK:STDOUT:   %.bdc: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet.168 [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %U.binding.as_type.as.ImplicitAs.impl.Convert.e6d, @U.binding.as_type.as.ImplicitAs.impl.Convert.2(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.5: type = fn_type @DestroyOp.loc9 [concrete]
-// CHECK:STDOUT:   %DestroyOp.b0ebf8.5: %DestroyOp.type.3e79c2.5 = struct_value () [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc9 [concrete]
+// CHECK:STDOUT:   %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
 // CHECK:STDOUT:   %S.cpp_destructor.type: type = fn_type @S.cpp_destructor [concrete]
 // CHECK:STDOUT:   %S.cpp_destructor: %S.cpp_destructor.type = struct_value () [concrete]
 // CHECK:STDOUT: }
@@ -1406,7 +1406,7 @@ fn F() {
 // CHECK:STDOUT:   %.loc9_11.3: ref %Optional.5a9 = temporary %.loc9_11.2, %.loc9_11.1
 // CHECK:STDOUT:   %.loc9_11.4: %Optional.5a9 = acquire_value %.loc9_11.3
 // CHECK:STDOUT:   %foo.call: init %empty_tuple.type = call imports.%foo.decl(%.loc9_11.4)
-// CHECK:STDOUT:   %DestroyOp.bound: <bound method> = bound_method %.loc9_11.3, constants.%DestroyOp.b0ebf8.5
+// CHECK:STDOUT:   %DestroyOp.bound: <bound method> = bound_method %.loc9_11.3, constants.%DestroyOp.b0ebf8.6
 // CHECK:STDOUT:   %DestroyOp.call: init %empty_tuple.type = call %DestroyOp.bound(%.loc9_11.3)
 // CHECK:STDOUT:   %S.cpp_destructor.bound: <bound method> = bound_method %s.var, constants.%S.cpp_destructor
 // CHECK:STDOUT:   %S.cpp_destructor.call: init %empty_tuple.type = call %S.cpp_destructor.bound(%s.var)
@@ -1849,15 +1849,15 @@ fn F() {
 // CHECK:STDOUT:   %ImplicitAs.impl_witness.368: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.840, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.type.5eb: type = fn_type @U.binding.as_type.as.ImplicitAs.impl.Convert.2, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.e6d: %U.binding.as_type.as.ImplicitAs.impl.Convert.type.5eb = struct_value () [concrete]
-// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.42a = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.368) [concrete]
-// CHECK:STDOUT:   %.bdc: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet.168: %ImplicitAs.type.42a = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.368) [concrete]
+// CHECK:STDOUT:   %.bdc: type = fn_type_with_self_type %ImplicitAs.Convert.type.a3c, %ImplicitAs.facet.168 [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %U.binding.as_type.as.ImplicitAs.impl.Convert.e6d, @U.binding.as_type.as.ImplicitAs.impl.Convert.2(%OptionalStorage.facet.fc6, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %Indirect.cpp_overload_set.type: type = cpp_overload_set_type @Indirect.cpp_overload_set [concrete]
 // CHECK:STDOUT:   %Indirect.cpp_overload_set.value: %Indirect.cpp_overload_set.type = cpp_overload_set_value @Indirect.cpp_overload_set [concrete]
 // CHECK:STDOUT:   %Indirect__carbon_thunk.type: type = fn_type @Indirect__carbon_thunk [concrete]
 // CHECK:STDOUT:   %Indirect__carbon_thunk: %Indirect__carbon_thunk.type = struct_value () [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.5: type = fn_type @DestroyOp.loc13_58 [concrete]
-// CHECK:STDOUT:   %DestroyOp.b0ebf8.5: %DestroyOp.type.3e79c2.5 = struct_value () [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc13_58 [concrete]
+// CHECK:STDOUT:   %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
 // CHECK:STDOUT:   %S.cpp_destructor.type: type = fn_type @S.cpp_destructor [concrete]
 // CHECK:STDOUT:   %S.cpp_destructor: %S.cpp_destructor.type = struct_value () [concrete]
 // CHECK:STDOUT: }
@@ -1976,11 +1976,11 @@ fn F() {
 // CHECK:STDOUT:   %.loc13_58.2: ref %Optional.5a9 = temporary %.loc13_58.1, %Indirect__carbon_thunk.call
 // CHECK:STDOUT:   %.loc13_58.3: %Optional.5a9 = acquire_value %.loc13_58.2
 // CHECK:STDOUT:   %a: %Optional.5a9 = value_binding a, %.loc13_58.3
-// CHECK:STDOUT:   %DestroyOp.bound.loc13: <bound method> = bound_method %.loc13_58.2, constants.%DestroyOp.b0ebf8.5
+// CHECK:STDOUT:   %DestroyOp.bound.loc13: <bound method> = bound_method %.loc13_58.2, constants.%DestroyOp.b0ebf8.6
 // CHECK:STDOUT:   %DestroyOp.call.loc13: init %empty_tuple.type = call %DestroyOp.bound.loc13(%.loc13_58.2)
 // CHECK:STDOUT:   %S.cpp_destructor.bound.loc13: <bound method> = bound_method %.loc13_48.4, constants.%S.cpp_destructor
 // CHECK:STDOUT:   %S.cpp_destructor.call.loc13: init %empty_tuple.type = call %S.cpp_destructor.bound.loc13(%.loc13_48.4)
-// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_14.3, constants.%DestroyOp.b0ebf8.5
+// CHECK:STDOUT:   %DestroyOp.bound.loc11: <bound method> = bound_method %.loc11_14.3, constants.%DestroyOp.b0ebf8.6
 // CHECK:STDOUT:   %DestroyOp.call.loc11: init %empty_tuple.type = call %DestroyOp.bound.loc11(%.loc11_14.3)
 // CHECK:STDOUT:   %S.cpp_destructor.bound.loc10: <bound method> = bound_method %s.var, constants.%S.cpp_destructor
 // CHECK:STDOUT:   %S.cpp_destructor.call.loc10: init %empty_tuple.type = call %S.cpp_destructor.bound.loc10(%s.var)

+ 5 - 5
toolchain/check/testdata/interop/cpp/function/void_pointer.carbon

@@ -231,11 +231,11 @@ fn F() {
 // CHECK:STDOUT:   %ImplicitAs.impl_witness.a2f: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.840, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.309, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.type.e82: type = fn_type @U.binding.as_type.as.ImplicitAs.impl.Convert.2, @U.binding.as_type.as.ImplicitAs.impl.71c(%OptionalStorage.facet.309, %OptionalAs.facet) [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.247: %U.binding.as_type.as.ImplicitAs.impl.Convert.type.e82 = struct_value () [concrete]
-// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.8e2 = facet_value %ptr.874, (%ImplicitAs.impl_witness.a2f) [concrete]
-// CHECK:STDOUT:   %.0d5: type = fn_type_with_self_type %ImplicitAs.Convert.type.2c8, %ImplicitAs.facet [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet.a05: %ImplicitAs.type.8e2 = facet_value %ptr.874, (%ImplicitAs.impl_witness.a2f) [concrete]
+// CHECK:STDOUT:   %.0d5: type = fn_type_with_self_type %ImplicitAs.Convert.type.2c8, %ImplicitAs.facet.a05 [concrete]
 // CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %U.binding.as_type.as.ImplicitAs.impl.Convert.247, @U.binding.as_type.as.ImplicitAs.impl.Convert.2(%OptionalStorage.facet.309, %OptionalAs.facet) [concrete]
-// CHECK:STDOUT:   %DestroyOp.type.3e79c2.5: type = fn_type @DestroyOp.loc10 [concrete]
-// CHECK:STDOUT:   %DestroyOp.b0ebf8.5: %DestroyOp.type.3e79c2.5 = struct_value () [concrete]
+// CHECK:STDOUT:   %DestroyOp.type.3e79c2.6: type = fn_type @DestroyOp.loc10 [concrete]
+// CHECK:STDOUT:   %DestroyOp.b0ebf8.6: %DestroyOp.type.3e79c2.6 = struct_value () [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -283,7 +283,7 @@ fn F() {
 // CHECK:STDOUT:   %.loc10_11.3: ref %Optional.367 = temporary %.loc10_11.2, %.loc10_11.1
 // CHECK:STDOUT:   %.loc10_11.4: %Optional.367 = acquire_value %.loc10_11.3
 // CHECK:STDOUT:   %foo.call: init %empty_tuple.type = call imports.%foo.decl(%.loc10_11.4)
-// CHECK:STDOUT:   %DestroyOp.bound: <bound method> = bound_method %.loc10_11.3, constants.%DestroyOp.b0ebf8.5
+// CHECK:STDOUT:   %DestroyOp.bound: <bound method> = bound_method %.loc10_11.3, constants.%DestroyOp.b0ebf8.6
 // CHECK:STDOUT:   %DestroyOp.call: init %empty_tuple.type = call %DestroyOp.bound(%.loc10_11.3)
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }

+ 1 - 1
toolchain/check/testdata/interop/cpp/void.carbon

@@ -30,7 +30,7 @@ fn G() {
   // CHECK:STDERR: fail_void_abstract.carbon:[[@LINE+7]]:10: error: binding pattern has abstract type `Cpp.void` in `var` pattern [AbstractTypeInVarPattern]
   // CHECK:STDERR:   var x: Cpp.void;
   // CHECK:STDERR:          ^~~~~~~~
-  // CHECK:STDERR: {{.*}}/prelude/types/cpp/void.carbon:22:1: note: class was declared abstract here [ClassAbstractHere]
+  // CHECK:STDERR: {{.*}}/prelude/types/cpp/void.carbon:24:1: note: class was declared abstract here [ClassAbstractHere]
   // CHECK:STDERR: abstract class CppCompat.VoidBase {
   // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   // CHECK:STDERR:

+ 353 - 35
toolchain/check/testdata/interop/cpp/void_pointer.carbon

@@ -10,7 +10,7 @@
 // TIP: To dump output, run:
 // TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/void_pointer.carbon
 
-// --- fail_todo_implicit_as_from_cpp_class_pointer_to_void_pointer.carbon
+// --- implicit_as_from_cpp_class_pointer_to_void_pointer.carbon
 
 library "[[@TEST_NAME]]";
 
@@ -20,18 +20,11 @@ struct S {};
 
 fn F(input: Cpp.S*) {
   //@dump-sem-ir-begin
-  // CHECK:STDERR: fail_todo_implicit_as_from_cpp_class_pointer_to_void_pointer.carbon:[[@LINE+7]]:22: error: cannot implicitly convert expression of type `Cpp.S*` to `Cpp.void*` [ConversionFailure]
-  // CHECK:STDERR:   let p: Cpp.void* = input;
-  // CHECK:STDERR:                      ^~~~~
-  // CHECK:STDERR: fail_todo_implicit_as_from_cpp_class_pointer_to_void_pointer.carbon:[[@LINE+4]]:22: note: type `Cpp.S*` does not implement interface `Core.ImplicitAs(Cpp.void*)` [MissingImplInMemberAccessNote]
-  // CHECK:STDERR:   let p: Cpp.void* = input;
-  // CHECK:STDERR:                      ^~~~~
-  // CHECK:STDERR:
   let p: Cpp.void* = input;
   //@dump-sem-ir-end
 }
 
-// --- fail_todo_implicit_as_from_carbon_class_pointer_to_void_pointer.carbon
+// --- implicit_as_from_carbon_class_pointer_to_void_pointer.carbon
 
 library "[[@TEST_NAME]]";
 
@@ -41,18 +34,39 @@ class C {}
 
 fn F(input: C*) {
   //@dump-sem-ir-begin
-  // CHECK:STDERR: fail_todo_implicit_as_from_carbon_class_pointer_to_void_pointer.carbon:[[@LINE+7]]:22: error: cannot implicitly convert expression of type `C*` to `Cpp.void*` [ConversionFailure]
-  // CHECK:STDERR:   let p: Cpp.void* = input;
-  // CHECK:STDERR:                      ^~~~~
-  // CHECK:STDERR: fail_todo_implicit_as_from_carbon_class_pointer_to_void_pointer.carbon:[[@LINE+4]]:22: note: type `C*` does not implement interface `Core.ImplicitAs(Cpp.void*)` [MissingImplInMemberAccessNote]
-  // CHECK:STDERR:   let p: Cpp.void* = input;
-  // CHECK:STDERR:                      ^~~~~
-  // CHECK:STDERR:
   let p: Cpp.void* = input;
   //@dump-sem-ir-end
 }
 
-// --- fail_todo_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon
+// --- explicit_as_from_cpp_class_pointer_to_void_pointer.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp inline '''
+struct S {};
+''';
+
+fn F(input: Cpp.S*) {
+  //@dump-sem-ir-begin
+  let p: Cpp.void* = input as Cpp.void*;
+  //@dump-sem-ir-end
+}
+
+// --- explicit_as_from_carbon_class_pointer_to_void_pointer.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp;
+
+class C {}
+
+fn F(input: C*) {
+  //@dump-sem-ir-begin
+  let p: Cpp.void* = input as Cpp.void*;
+  //@dump-sem-ir-end
+}
+
+// --- fail_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon
 
 library "[[@TEST_NAME]]";
 
@@ -62,10 +76,10 @@ struct S {};
 
 fn F(input: Cpp.void*) {
   //@dump-sem-ir-begin
-  // CHECK:STDERR: fail_todo_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon:[[@LINE+7]]:19: error: cannot convert expression of type `Cpp.void*` to `Cpp.S*` with `as` [ConversionFailure]
+  // CHECK:STDERR: fail_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon:[[@LINE+7]]:19: error: cannot convert expression of type `Cpp.void*` to `Cpp.S*` with `as` [ConversionFailure]
   // CHECK:STDERR:   let p: Cpp.S* = input as Cpp.S*;
   // CHECK:STDERR:                   ^~~~~~~~~~~~~~~
-  // CHECK:STDERR: fail_todo_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon:[[@LINE+4]]:19: note: type `Cpp.void*` does not implement interface `Core.As(Cpp.S*)` [MissingImplInMemberAccessNote]
+  // CHECK:STDERR: fail_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon:[[@LINE+4]]:19: note: type `Cpp.void*` does not implement interface `Core.As(Cpp.S*)` [MissingImplInMemberAccessNote]
   // CHECK:STDERR:   let p: Cpp.S* = input as Cpp.S*;
   // CHECK:STDERR:                   ^~~~~~~~~~~~~~~
   // CHECK:STDERR:
@@ -73,7 +87,7 @@ fn F(input: Cpp.void*) {
   //@dump-sem-ir-end
 }
 
-// --- fail_todo_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon
+// --- fail_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon
 
 library "[[@TEST_NAME]]";
 
@@ -83,10 +97,10 @@ class C {}
 
 fn F(input: Cpp.void*) {
   //@dump-sem-ir-begin
-  // CHECK:STDERR: fail_todo_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon:[[@LINE+7]]:15: error: cannot convert expression of type `Cpp.void*` to `C*` with `as` [ConversionFailure]
+  // CHECK:STDERR: fail_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon:[[@LINE+7]]:15: error: cannot convert expression of type `Cpp.void*` to `C*` with `as` [ConversionFailure]
   // CHECK:STDERR:   let p: C* = input as C*;
   // CHECK:STDERR:               ^~~~~~~~~~~
-  // CHECK:STDERR: fail_todo_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon:[[@LINE+4]]:15: note: type `Cpp.void*` does not implement interface `Core.As(C*)` [MissingImplInMemberAccessNote]
+  // CHECK:STDERR: fail_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon:[[@LINE+4]]:15: note: type `Cpp.void*` does not implement interface `Core.As(C*)` [MissingImplInMemberAccessNote]
   // CHECK:STDERR:   let p: C* = input as C*;
   // CHECK:STDERR:               ^~~~~~~~~~~
   // CHECK:STDERR:
@@ -94,7 +108,35 @@ fn F(input: Cpp.void*) {
   //@dump-sem-ir-end
 }
 
-// CHECK:STDOUT: --- fail_todo_implicit_as_from_cpp_class_pointer_to_void_pointer.carbon
+// --- unsafe_as_from_void_pointer_to_cpp_class_pointer.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp inline '''
+struct S {};
+''';
+
+fn F(input: Cpp.void*) {
+  //@dump-sem-ir-begin
+  let p: Cpp.S* = input unsafe as Cpp.S*;
+  //@dump-sem-ir-end
+}
+
+// --- unsafe_as_from_void_pointer_to_carbon_class_pointer.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp;
+
+class C {}
+
+fn F(input: Cpp.void*) {
+  //@dump-sem-ir-begin
+  let p: C* = input unsafe as C*;
+  //@dump-sem-ir-end
+}
+
+// CHECK:STDOUT: --- implicit_as_from_cpp_class_pointer_to_void_pointer.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %S: type = class_type @S [concrete]
@@ -102,6 +144,17 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
 // CHECK:STDOUT:   %ptr.874: type = ptr_type %Cpp.void [concrete]
 // CHECK:STDOUT:   %pattern_type.9fb: type = pattern_type %ptr.874 [concrete]
+// CHECK:STDOUT:   %ImplicitAs.type.02d: type = facet_type <@ImplicitAs, @ImplicitAs(%ptr.874)> [concrete]
+// CHECK:STDOUT:   %ImplicitAs.Convert.type.9be: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%ptr.874) [concrete]
+// CHECK:STDOUT:   %T.67d: type = symbolic_binding T, 0 [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.type.ccd: type = fn_type @ptr.as.ImplicitAs.impl.Convert.1, @ptr.as.ImplicitAs.impl.334(%T.67d) [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.1ec: %ptr.as.ImplicitAs.impl.Convert.type.ccd = struct_value () [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness.ffd: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.25e, @ptr.as.ImplicitAs.impl.334(%S) [concrete]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.type.f61: type = fn_type @ptr.as.ImplicitAs.impl.Convert.1, @ptr.as.ImplicitAs.impl.334(%S) [concrete]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.d8d: %ptr.as.ImplicitAs.impl.Convert.type.f61 = struct_value () [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.02d = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.ffd) [concrete]
+// CHECK:STDOUT:   %.caa: type = fn_type_with_self_type %ImplicitAs.Convert.type.9be, %ImplicitAs.facet [concrete]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.specific_fn.ffe: <specific function> = specific_function %ptr.as.ImplicitAs.impl.Convert.d8d, @ptr.as.ImplicitAs.impl.Convert.1(%S) [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -111,6 +164,8 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:     import Cpp//...
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
+// CHECK:STDOUT:   %Core.import_ref.654: @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert.type (%ptr.as.ImplicitAs.impl.Convert.type.ccd) = import_ref Core//prelude/types/cpp/void, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert (constants.%ptr.as.ImplicitAs.impl.Convert.1ec)]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness_table.25e = impl_witness_table (%Core.import_ref.654), @ptr.as.ImplicitAs.impl.334 [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F(%input.param: %ptr.5c7) {
@@ -119,17 +174,23 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:     %p.patt: %pattern_type.9fb = value_binding_pattern p [concrete]
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %input.ref: %ptr.5c7 = name_ref input, %input
-// CHECK:STDOUT:   %.loc17_18: type = splice_block %ptr.loc17 [concrete = constants.%ptr.874] {
-// CHECK:STDOUT:     %Cpp.ref.loc17: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:   %.loc10_18: type = splice_block %ptr.loc10 [concrete = constants.%ptr.874] {
+// CHECK:STDOUT:     %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
 // CHECK:STDOUT:     %void.ref: type = name_ref void, constants.%Cpp.void [concrete = constants.%Cpp.void]
-// CHECK:STDOUT:     %ptr.loc17: type = ptr_type %void.ref [concrete = constants.%ptr.874]
+// CHECK:STDOUT:     %ptr.loc10: type = ptr_type %void.ref [concrete = constants.%ptr.874]
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc17_22: %ptr.874 = converted %input.ref, <error> [concrete = <error>]
-// CHECK:STDOUT:   %p: %ptr.874 = value_binding p, <error> [concrete = <error>]
+// CHECK:STDOUT:   %impl.elem0: %.caa = impl_witness_access constants.%ImplicitAs.impl_witness.ffd, element0 [concrete = constants.%ptr.as.ImplicitAs.impl.Convert.d8d]
+// CHECK:STDOUT:   %bound_method.loc10_22.1: <bound method> = bound_method %input.ref, %impl.elem0
+// CHECK:STDOUT:   %specific_fn: <specific function> = specific_function %impl.elem0, @ptr.as.ImplicitAs.impl.Convert.1(constants.%S) [concrete = constants.%ptr.as.ImplicitAs.impl.Convert.specific_fn.ffe]
+// CHECK:STDOUT:   %bound_method.loc10_22.2: <bound method> = bound_method %input.ref, %specific_fn
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.call: init %ptr.874 = call %bound_method.loc10_22.2(%input.ref)
+// CHECK:STDOUT:   %.loc10_22.1: %ptr.874 = value_of_initializer %ptr.as.ImplicitAs.impl.Convert.call
+// CHECK:STDOUT:   %.loc10_22.2: %ptr.874 = converted %input.ref, %.loc10_22.1
+// CHECK:STDOUT:   %p: %ptr.874 = value_binding p, %.loc10_22.2
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_implicit_as_from_carbon_class_pointer_to_void_pointer.carbon
+// CHECK:STDOUT: --- implicit_as_from_carbon_class_pointer_to_void_pointer.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %C: type = class_type @C [concrete]
@@ -137,6 +198,17 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
 // CHECK:STDOUT:   %ptr.874: type = ptr_type %Cpp.void [concrete]
 // CHECK:STDOUT:   %pattern_type.9fb: type = pattern_type %ptr.874 [concrete]
+// CHECK:STDOUT:   %ImplicitAs.type.02d: type = facet_type <@ImplicitAs, @ImplicitAs(%ptr.874)> [concrete]
+// CHECK:STDOUT:   %ImplicitAs.Convert.type.9be: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%ptr.874) [concrete]
+// CHECK:STDOUT:   %T.67d: type = symbolic_binding T, 0 [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.type.ccd: type = fn_type @ptr.as.ImplicitAs.impl.Convert.1, @ptr.as.ImplicitAs.impl.334(%T.67d) [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.1ec: %ptr.as.ImplicitAs.impl.Convert.type.ccd = struct_value () [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness.39c: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.25e, @ptr.as.ImplicitAs.impl.334(%C) [concrete]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.type.155: type = fn_type @ptr.as.ImplicitAs.impl.Convert.1, @ptr.as.ImplicitAs.impl.334(%C) [concrete]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.1f8: %ptr.as.ImplicitAs.impl.Convert.type.155 = struct_value () [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.02d = facet_value %ptr.31e, (%ImplicitAs.impl_witness.39c) [concrete]
+// CHECK:STDOUT:   %.2b2: type = fn_type_with_self_type %ImplicitAs.Convert.type.9be, %ImplicitAs.facet [concrete]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.specific_fn.384: <specific function> = specific_function %ptr.as.ImplicitAs.impl.Convert.1f8, @ptr.as.ImplicitAs.impl.Convert.1(%C) [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: imports {
@@ -144,6 +216,8 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:     .void = constants.%Cpp.void
 // CHECK:STDOUT:     import Cpp//...
 // CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import_ref.654: @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert.type (%ptr.as.ImplicitAs.impl.Convert.type.ccd) = import_ref Core//prelude/types/cpp/void, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert (constants.%ptr.as.ImplicitAs.impl.Convert.1ec)]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness_table.25e = impl_witness_table (%Core.import_ref.654), @ptr.as.ImplicitAs.impl.334 [concrete]
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: fn @F(%input.param: %ptr.31e) {
@@ -152,17 +226,155 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:     %p.patt: %pattern_type.9fb = value_binding_pattern p [concrete]
 // CHECK:STDOUT:   }
 // CHECK:STDOUT:   %input.ref: %ptr.31e = name_ref input, %input
-// CHECK:STDOUT:   %.loc17_18: type = splice_block %ptr.loc17 [concrete = constants.%ptr.874] {
+// CHECK:STDOUT:   %.loc10_18: type = splice_block %ptr.loc10 [concrete = constants.%ptr.874] {
 // CHECK:STDOUT:     %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
 // CHECK:STDOUT:     %void.ref: type = name_ref void, constants.%Cpp.void [concrete = constants.%Cpp.void]
-// CHECK:STDOUT:     %ptr.loc17: type = ptr_type %void.ref [concrete = constants.%ptr.874]
+// CHECK:STDOUT:     %ptr.loc10: type = ptr_type %void.ref [concrete = constants.%ptr.874]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %impl.elem0: %.2b2 = impl_witness_access constants.%ImplicitAs.impl_witness.39c, element0 [concrete = constants.%ptr.as.ImplicitAs.impl.Convert.1f8]
+// CHECK:STDOUT:   %bound_method.loc10_22.1: <bound method> = bound_method %input.ref, %impl.elem0
+// CHECK:STDOUT:   %specific_fn: <specific function> = specific_function %impl.elem0, @ptr.as.ImplicitAs.impl.Convert.1(constants.%C) [concrete = constants.%ptr.as.ImplicitAs.impl.Convert.specific_fn.384]
+// CHECK:STDOUT:   %bound_method.loc10_22.2: <bound method> = bound_method %input.ref, %specific_fn
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.call: init %ptr.874 = call %bound_method.loc10_22.2(%input.ref)
+// CHECK:STDOUT:   %.loc10_22.1: %ptr.874 = value_of_initializer %ptr.as.ImplicitAs.impl.Convert.call
+// CHECK:STDOUT:   %.loc10_22.2: %ptr.874 = converted %input.ref, %.loc10_22.1
+// CHECK:STDOUT:   %p: %ptr.874 = value_binding p, %.loc10_22.2
+// CHECK:STDOUT:   <elided>
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- explicit_as_from_cpp_class_pointer_to_void_pointer.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %S: type = class_type @S [concrete]
+// CHECK:STDOUT:   %ptr.5c7: type = ptr_type %S [concrete]
+// CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
+// CHECK:STDOUT:   %ptr.874: type = ptr_type %Cpp.void [concrete]
+// CHECK:STDOUT:   %pattern_type.9fb: type = pattern_type %ptr.874 [concrete]
+// CHECK:STDOUT:   %As.type.d24: type = facet_type <@As, @As(%ptr.874)> [concrete]
+// CHECK:STDOUT:   %As.Convert.type.97f: type = fn_type @As.Convert, @As(%ptr.874) [concrete]
+// CHECK:STDOUT:   %U.67d: type = symbolic_binding U, 0 [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.type.031604.2: type = facet_type <@ImplicitAs, @ImplicitAs(%U.67d)> [symbolic]
+// CHECK:STDOUT:   %T.738: %ImplicitAs.type.031604.2 = symbolic_binding T, 1 [symbolic]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.type.6c0: type = fn_type @T.binding.as_type.as.As.impl.Convert, @T.binding.as_type.as.As.impl(%U.67d, %T.738) [symbolic]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.8f1: %T.binding.as_type.as.As.impl.Convert.type.6c0 = struct_value () [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.type.02d: type = facet_type <@ImplicitAs, @ImplicitAs(%ptr.874)> [concrete]
+// CHECK:STDOUT:   %T.67d: type = symbolic_binding T, 0 [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.type.ccd: type = fn_type @ptr.as.ImplicitAs.impl.Convert.1, @ptr.as.ImplicitAs.impl.334(%T.67d) [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.1ec: %ptr.as.ImplicitAs.impl.Convert.type.ccd = struct_value () [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness.ffd: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.25e, @ptr.as.ImplicitAs.impl.334(%S) [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.02d = facet_value %ptr.5c7, (%ImplicitAs.impl_witness.ffd) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.9e9: <witness> = impl_witness imports.%As.impl_witness_table, @T.binding.as_type.as.As.impl(%ptr.874, %ImplicitAs.facet) [concrete]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.type.b2a: type = fn_type @T.binding.as_type.as.As.impl.Convert, @T.binding.as_type.as.As.impl(%ptr.874, %ImplicitAs.facet) [concrete]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.e7d: %T.binding.as_type.as.As.impl.Convert.type.b2a = struct_value () [concrete]
+// CHECK:STDOUT:   %As.facet: %As.type.d24 = facet_value %ptr.5c7, (%As.impl_witness.9e9) [concrete]
+// CHECK:STDOUT:   %.a02: type = fn_type_with_self_type %As.Convert.type.97f, %As.facet [concrete]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.specific_fn: <specific function> = specific_function %T.binding.as_type.as.As.impl.Convert.e7d, @T.binding.as_type.as.As.impl.Convert(%ptr.874, %ImplicitAs.facet) [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .S = %S.decl
+// CHECK:STDOUT:     .void = constants.%Cpp.void
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
+// CHECK:STDOUT:   %Core.import_ref.bde: @T.binding.as_type.as.As.impl.%T.binding.as_type.as.As.impl.Convert.type (%T.binding.as_type.as.As.impl.Convert.type.6c0) = import_ref Core//prelude/operators/as, loc{{\d+_\d+}}, loaded [symbolic = @T.binding.as_type.as.As.impl.%T.binding.as_type.as.As.impl.Convert (constants.%T.binding.as_type.as.As.impl.Convert.8f1)]
+// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.bde), @T.binding.as_type.as.As.impl [concrete]
+// CHECK:STDOUT:   %Core.import_ref.654: @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert.type (%ptr.as.ImplicitAs.impl.Convert.type.ccd) = import_ref Core//prelude/types/cpp/void, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert (constants.%ptr.as.ImplicitAs.impl.Convert.1ec)]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness_table.25e = impl_witness_table (%Core.import_ref.654), @ptr.as.ImplicitAs.impl.334 [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @F(%input.param: %ptr.5c7) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %p.patt: %pattern_type.9fb = value_binding_pattern p [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %input.ref: %ptr.5c7 = name_ref input, %input
+// CHECK:STDOUT:   %Cpp.ref.loc10_31: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:   %void.ref.loc10_34: type = name_ref void, constants.%Cpp.void [concrete = constants.%Cpp.void]
+// CHECK:STDOUT:   %ptr.loc10_39: type = ptr_type %void.ref.loc10_34 [concrete = constants.%ptr.874]
+// CHECK:STDOUT:   %impl.elem0: %.a02 = impl_witness_access constants.%As.impl_witness.9e9, element0 [concrete = constants.%T.binding.as_type.as.As.impl.Convert.e7d]
+// CHECK:STDOUT:   %bound_method.loc10_28.1: <bound method> = bound_method %input.ref, %impl.elem0
+// CHECK:STDOUT:   %specific_fn: <specific function> = specific_function %impl.elem0, @T.binding.as_type.as.As.impl.Convert(constants.%ptr.874, constants.%ImplicitAs.facet) [concrete = constants.%T.binding.as_type.as.As.impl.Convert.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc10_28.2: <bound method> = bound_method %input.ref, %specific_fn
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.call: init %ptr.874 = call %bound_method.loc10_28.2(%input.ref)
+// CHECK:STDOUT:   %.loc10_28.1: %ptr.874 = value_of_initializer %T.binding.as_type.as.As.impl.Convert.call
+// CHECK:STDOUT:   %.loc10_28.2: %ptr.874 = converted %input.ref, %.loc10_28.1
+// CHECK:STDOUT:   %.loc10_18: type = splice_block %ptr.loc10_18 [concrete = constants.%ptr.874] {
+// CHECK:STDOUT:     %Cpp.ref.loc10_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:     %void.ref.loc10_13: type = name_ref void, constants.%Cpp.void [concrete = constants.%Cpp.void]
+// CHECK:STDOUT:     %ptr.loc10_18: type = ptr_type %void.ref.loc10_13 [concrete = constants.%ptr.874]
 // CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc17_22: %ptr.874 = converted %input.ref, <error> [concrete = <error>]
-// CHECK:STDOUT:   %p: %ptr.874 = value_binding p, <error> [concrete = <error>]
+// CHECK:STDOUT:   %p: %ptr.874 = value_binding p, %.loc10_28.2
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon
+// CHECK:STDOUT: --- explicit_as_from_carbon_class_pointer_to_void_pointer.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %C: type = class_type @C [concrete]
+// CHECK:STDOUT:   %ptr.31e: type = ptr_type %C [concrete]
+// CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
+// CHECK:STDOUT:   %ptr.874: type = ptr_type %Cpp.void [concrete]
+// CHECK:STDOUT:   %pattern_type.9fb: type = pattern_type %ptr.874 [concrete]
+// CHECK:STDOUT:   %As.type.d24: type = facet_type <@As, @As(%ptr.874)> [concrete]
+// CHECK:STDOUT:   %As.Convert.type.97f: type = fn_type @As.Convert, @As(%ptr.874) [concrete]
+// CHECK:STDOUT:   %U.67d: type = symbolic_binding U, 0 [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.type.031604.2: type = facet_type <@ImplicitAs, @ImplicitAs(%U.67d)> [symbolic]
+// CHECK:STDOUT:   %T.738: %ImplicitAs.type.031604.2 = symbolic_binding T, 1 [symbolic]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.type.6c0: type = fn_type @T.binding.as_type.as.As.impl.Convert, @T.binding.as_type.as.As.impl(%U.67d, %T.738) [symbolic]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.8f1: %T.binding.as_type.as.As.impl.Convert.type.6c0 = struct_value () [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.type.02d: type = facet_type <@ImplicitAs, @ImplicitAs(%ptr.874)> [concrete]
+// CHECK:STDOUT:   %T.67d: type = symbolic_binding T, 0 [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.type.ccd: type = fn_type @ptr.as.ImplicitAs.impl.Convert.1, @ptr.as.ImplicitAs.impl.334(%T.67d) [symbolic]
+// CHECK:STDOUT:   %ptr.as.ImplicitAs.impl.Convert.1ec: %ptr.as.ImplicitAs.impl.Convert.type.ccd = struct_value () [symbolic]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness.39c: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.25e, @ptr.as.ImplicitAs.impl.334(%C) [concrete]
+// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.02d = facet_value %ptr.31e, (%ImplicitAs.impl_witness.39c) [concrete]
+// CHECK:STDOUT:   %As.impl_witness.fa1: <witness> = impl_witness imports.%As.impl_witness_table, @T.binding.as_type.as.As.impl(%ptr.874, %ImplicitAs.facet) [concrete]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.type.05b: type = fn_type @T.binding.as_type.as.As.impl.Convert, @T.binding.as_type.as.As.impl(%ptr.874, %ImplicitAs.facet) [concrete]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.483: %T.binding.as_type.as.As.impl.Convert.type.05b = struct_value () [concrete]
+// CHECK:STDOUT:   %As.facet: %As.type.d24 = facet_value %ptr.31e, (%As.impl_witness.fa1) [concrete]
+// CHECK:STDOUT:   %.cf8: type = fn_type_with_self_type %As.Convert.type.97f, %As.facet [concrete]
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.specific_fn: <specific function> = specific_function %T.binding.as_type.as.As.impl.Convert.483, @T.binding.as_type.as.As.impl.Convert(%ptr.874, %ImplicitAs.facet) [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .void = constants.%Cpp.void
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %Core.import_ref.bde: @T.binding.as_type.as.As.impl.%T.binding.as_type.as.As.impl.Convert.type (%T.binding.as_type.as.As.impl.Convert.type.6c0) = import_ref Core//prelude/operators/as, loc{{\d+_\d+}}, loaded [symbolic = @T.binding.as_type.as.As.impl.%T.binding.as_type.as.As.impl.Convert (constants.%T.binding.as_type.as.As.impl.Convert.8f1)]
+// CHECK:STDOUT:   %As.impl_witness_table = impl_witness_table (%Core.import_ref.bde), @T.binding.as_type.as.As.impl [concrete]
+// CHECK:STDOUT:   %Core.import_ref.654: @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert.type (%ptr.as.ImplicitAs.impl.Convert.type.ccd) = import_ref Core//prelude/types/cpp/void, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.ImplicitAs.impl.334.%ptr.as.ImplicitAs.impl.Convert (constants.%ptr.as.ImplicitAs.impl.Convert.1ec)]
+// CHECK:STDOUT:   %ImplicitAs.impl_witness_table.25e = impl_witness_table (%Core.import_ref.654), @ptr.as.ImplicitAs.impl.334 [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @F(%input.param: %ptr.31e) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %p.patt: %pattern_type.9fb = value_binding_pattern p [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %input.ref: %ptr.31e = name_ref input, %input
+// CHECK:STDOUT:   %Cpp.ref.loc10_31: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:   %void.ref.loc10_34: type = name_ref void, constants.%Cpp.void [concrete = constants.%Cpp.void]
+// CHECK:STDOUT:   %ptr.loc10_39: type = ptr_type %void.ref.loc10_34 [concrete = constants.%ptr.874]
+// CHECK:STDOUT:   %impl.elem0: %.cf8 = impl_witness_access constants.%As.impl_witness.fa1, element0 [concrete = constants.%T.binding.as_type.as.As.impl.Convert.483]
+// CHECK:STDOUT:   %bound_method.loc10_28.1: <bound method> = bound_method %input.ref, %impl.elem0
+// CHECK:STDOUT:   %specific_fn: <specific function> = specific_function %impl.elem0, @T.binding.as_type.as.As.impl.Convert(constants.%ptr.874, constants.%ImplicitAs.facet) [concrete = constants.%T.binding.as_type.as.As.impl.Convert.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc10_28.2: <bound method> = bound_method %input.ref, %specific_fn
+// CHECK:STDOUT:   %T.binding.as_type.as.As.impl.Convert.call: init %ptr.874 = call %bound_method.loc10_28.2(%input.ref)
+// CHECK:STDOUT:   %.loc10_28.1: %ptr.874 = value_of_initializer %T.binding.as_type.as.As.impl.Convert.call
+// CHECK:STDOUT:   %.loc10_28.2: %ptr.874 = converted %input.ref, %.loc10_28.1
+// CHECK:STDOUT:   %.loc10_18: type = splice_block %ptr.loc10_18 [concrete = constants.%ptr.874] {
+// CHECK:STDOUT:     %Cpp.ref.loc10_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:     %void.ref.loc10_13: type = name_ref void, constants.%Cpp.void [concrete = constants.%Cpp.void]
+// CHECK:STDOUT:     %ptr.loc10_18: type = ptr_type %void.ref.loc10_13 [concrete = constants.%ptr.874]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %p: %ptr.874 = value_binding p, %.loc10_28.2
+// CHECK:STDOUT:   <elided>
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- fail_explicit_as_from_void_pointer_to_cpp_class_pointer.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
@@ -200,7 +412,7 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: --- fail_todo_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon
+// CHECK:STDOUT: --- fail_explicit_as_from_void_pointer_to_carbon_class_pointer.carbon
 // CHECK:STDOUT:
 // CHECK:STDOUT: constants {
 // CHECK:STDOUT:   %C: type = class_type @C [concrete]
@@ -230,3 +442,109 @@ fn F(input: Cpp.void*) {
 // CHECK:STDOUT:   <elided>
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: --- unsafe_as_from_void_pointer_to_cpp_class_pointer.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
+// CHECK:STDOUT:   %ptr.874: type = ptr_type %Cpp.void [concrete]
+// CHECK:STDOUT:   %S: type = class_type @S [concrete]
+// CHECK:STDOUT:   %ptr.5c7: type = ptr_type %S [concrete]
+// CHECK:STDOUT:   %pattern_type.259: type = pattern_type %ptr.5c7 [concrete]
+// CHECK:STDOUT:   %UnsafeAs.type.0ee: type = facet_type <@UnsafeAs, @UnsafeAs(%ptr.5c7)> [concrete]
+// CHECK:STDOUT:   %UnsafeAs.Convert.type.e91: type = fn_type @UnsafeAs.Convert, @UnsafeAs(%ptr.5c7) [concrete]
+// CHECK:STDOUT:   %T.67d: type = symbolic_binding T, 0 [symbolic]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.type.9c9: type = fn_type @ptr.as.UnsafeAs.impl.Convert.1, @ptr.as.UnsafeAs.impl.f07(%T.67d) [symbolic]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.175: %ptr.as.UnsafeAs.impl.Convert.type.9c9 = struct_value () [symbolic]
+// CHECK:STDOUT:   %UnsafeAs.impl_witness.624: <witness> = impl_witness imports.%UnsafeAs.impl_witness_table.93a, @ptr.as.UnsafeAs.impl.f07(%S) [concrete]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.type.010: type = fn_type @ptr.as.UnsafeAs.impl.Convert.1, @ptr.as.UnsafeAs.impl.f07(%S) [concrete]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.811: %ptr.as.UnsafeAs.impl.Convert.type.010 = struct_value () [concrete]
+// CHECK:STDOUT:   %UnsafeAs.facet: %UnsafeAs.type.0ee = facet_value %ptr.874, (%UnsafeAs.impl_witness.624) [concrete]
+// CHECK:STDOUT:   %.ce5: type = fn_type_with_self_type %UnsafeAs.Convert.type.e91, %UnsafeAs.facet [concrete]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.specific_fn: <specific function> = specific_function %ptr.as.UnsafeAs.impl.Convert.811, @ptr.as.UnsafeAs.impl.Convert.1(%S) [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
+// CHECK:STDOUT:     .void = constants.%Cpp.void
+// CHECK:STDOUT:     .S = %S.decl
+// CHECK:STDOUT:     import Cpp//...
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %S.decl: type = class_decl @S [concrete = constants.%S] {} {}
+// CHECK:STDOUT:   %Core.import_ref.8bb: @ptr.as.UnsafeAs.impl.f07.%ptr.as.UnsafeAs.impl.Convert.type (%ptr.as.UnsafeAs.impl.Convert.type.9c9) = import_ref Core//prelude/types/cpp/void, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.UnsafeAs.impl.f07.%ptr.as.UnsafeAs.impl.Convert (constants.%ptr.as.UnsafeAs.impl.Convert.175)]
+// CHECK:STDOUT:   %UnsafeAs.impl_witness_table.93a = impl_witness_table (%Core.import_ref.8bb), @ptr.as.UnsafeAs.impl.f07 [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @F(%input.param: %ptr.874) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %p.patt: %pattern_type.259 = value_binding_pattern p [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %input.ref: %ptr.874 = name_ref input, %input
+// CHECK:STDOUT:   %Cpp.ref.loc10_35: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:   %S.ref.loc10_38: type = name_ref S, imports.%S.decl [concrete = constants.%S]
+// CHECK:STDOUT:   %ptr.loc10_40: type = ptr_type %S.ref.loc10_38 [concrete = constants.%ptr.5c7]
+// CHECK:STDOUT:   %impl.elem0: %.ce5 = impl_witness_access constants.%UnsafeAs.impl_witness.624, element0 [concrete = constants.%ptr.as.UnsafeAs.impl.Convert.811]
+// CHECK:STDOUT:   %bound_method.loc10_32.1: <bound method> = bound_method %input.ref, %impl.elem0
+// CHECK:STDOUT:   %specific_fn: <specific function> = specific_function %impl.elem0, @ptr.as.UnsafeAs.impl.Convert.1(constants.%S) [concrete = constants.%ptr.as.UnsafeAs.impl.Convert.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc10_32.2: <bound method> = bound_method %input.ref, %specific_fn
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.call: init %ptr.5c7 = call %bound_method.loc10_32.2(%input.ref)
+// CHECK:STDOUT:   %.loc10_32.1: %ptr.5c7 = value_of_initializer %ptr.as.UnsafeAs.impl.Convert.call
+// CHECK:STDOUT:   %.loc10_32.2: %ptr.5c7 = converted %input.ref, %.loc10_32.1
+// CHECK:STDOUT:   %.loc10_15: type = splice_block %ptr.loc10_15 [concrete = constants.%ptr.5c7] {
+// CHECK:STDOUT:     %Cpp.ref.loc10_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
+// CHECK:STDOUT:     %S.ref.loc10_13: type = name_ref S, imports.%S.decl [concrete = constants.%S]
+// CHECK:STDOUT:     %ptr.loc10_15: type = ptr_type %S.ref.loc10_13 [concrete = constants.%ptr.5c7]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %p: %ptr.5c7 = value_binding p, %.loc10_32.2
+// CHECK:STDOUT:   <elided>
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: --- unsafe_as_from_void_pointer_to_carbon_class_pointer.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %C: type = class_type @C [concrete]
+// CHECK:STDOUT:   %Cpp.void: type = class_type @VoidBase [concrete]
+// CHECK:STDOUT:   %ptr.874: type = ptr_type %Cpp.void [concrete]
+// CHECK:STDOUT:   %ptr.31e: type = ptr_type %C [concrete]
+// CHECK:STDOUT:   %pattern_type.506: type = pattern_type %ptr.31e [concrete]
+// CHECK:STDOUT:   %UnsafeAs.type.1ec: type = facet_type <@UnsafeAs, @UnsafeAs(%ptr.31e)> [concrete]
+// CHECK:STDOUT:   %UnsafeAs.Convert.type.b51: type = fn_type @UnsafeAs.Convert, @UnsafeAs(%ptr.31e) [concrete]
+// CHECK:STDOUT:   %T.67d: type = symbolic_binding T, 0 [symbolic]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.type.9c9: type = fn_type @ptr.as.UnsafeAs.impl.Convert.1, @ptr.as.UnsafeAs.impl.f07(%T.67d) [symbolic]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.175: %ptr.as.UnsafeAs.impl.Convert.type.9c9 = struct_value () [symbolic]
+// CHECK:STDOUT:   %UnsafeAs.impl_witness.29a: <witness> = impl_witness imports.%UnsafeAs.impl_witness_table.93a, @ptr.as.UnsafeAs.impl.f07(%C) [concrete]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.type.53a: type = fn_type @ptr.as.UnsafeAs.impl.Convert.1, @ptr.as.UnsafeAs.impl.f07(%C) [concrete]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.e72: %ptr.as.UnsafeAs.impl.Convert.type.53a = struct_value () [concrete]
+// CHECK:STDOUT:   %UnsafeAs.facet: %UnsafeAs.type.1ec = facet_value %ptr.874, (%UnsafeAs.impl_witness.29a) [concrete]
+// CHECK:STDOUT:   %.a62: type = fn_type_with_self_type %UnsafeAs.Convert.type.b51, %UnsafeAs.facet [concrete]
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.specific_fn: <specific function> = specific_function %ptr.as.UnsafeAs.impl.Convert.e72, @ptr.as.UnsafeAs.impl.Convert.1(%C) [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Core.import_ref.8bb: @ptr.as.UnsafeAs.impl.f07.%ptr.as.UnsafeAs.impl.Convert.type (%ptr.as.UnsafeAs.impl.Convert.type.9c9) = import_ref Core//prelude/types/cpp/void, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.UnsafeAs.impl.f07.%ptr.as.UnsafeAs.impl.Convert (constants.%ptr.as.UnsafeAs.impl.Convert.175)]
+// CHECK:STDOUT:   %UnsafeAs.impl_witness_table.93a = impl_witness_table (%Core.import_ref.8bb), @ptr.as.UnsafeAs.impl.f07 [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @F(%input.param: %ptr.874) {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %p.patt: %pattern_type.506 = value_binding_pattern p [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %input.ref: %ptr.874 = name_ref input, %input
+// CHECK:STDOUT:   %C.ref.loc10_31: type = name_ref C, file.%C.decl [concrete = constants.%C]
+// CHECK:STDOUT:   %ptr.loc10_32: type = ptr_type %C.ref.loc10_31 [concrete = constants.%ptr.31e]
+// CHECK:STDOUT:   %impl.elem0: %.a62 = impl_witness_access constants.%UnsafeAs.impl_witness.29a, element0 [concrete = constants.%ptr.as.UnsafeAs.impl.Convert.e72]
+// CHECK:STDOUT:   %bound_method.loc10_28.1: <bound method> = bound_method %input.ref, %impl.elem0
+// CHECK:STDOUT:   %specific_fn: <specific function> = specific_function %impl.elem0, @ptr.as.UnsafeAs.impl.Convert.1(constants.%C) [concrete = constants.%ptr.as.UnsafeAs.impl.Convert.specific_fn]
+// CHECK:STDOUT:   %bound_method.loc10_28.2: <bound method> = bound_method %input.ref, %specific_fn
+// CHECK:STDOUT:   %ptr.as.UnsafeAs.impl.Convert.call: init %ptr.31e = call %bound_method.loc10_28.2(%input.ref)
+// CHECK:STDOUT:   %.loc10_28.1: %ptr.31e = value_of_initializer %ptr.as.UnsafeAs.impl.Convert.call
+// CHECK:STDOUT:   %.loc10_28.2: %ptr.31e = converted %input.ref, %.loc10_28.1
+// CHECK:STDOUT:   %.loc10_11: type = splice_block %ptr.loc10_11 [concrete = constants.%ptr.31e] {
+// CHECK:STDOUT:     %C.ref.loc10_10: type = name_ref C, file.%C.decl [concrete = constants.%C]
+// CHECK:STDOUT:     %ptr.loc10_11: type = ptr_type %C.ref.loc10_10 [concrete = constants.%ptr.31e]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %p: %ptr.31e = value_binding p, %.loc10_28.2
+// CHECK:STDOUT:   <elided>
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 4 - 4
toolchain/driver/testdata/compile/optimize/optimize_debug.carbon

@@ -113,16 +113,16 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
 // CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !16, type: !19)
 // CHECK:STDOUT: !22 = !DILocation(line: 18, column: 9, scope: !16)
 // CHECK:STDOUT: !23 = !DILocation(line: 19, column: 5, scope: !16)
-// CHECK:STDOUT: !24 = !DILocation(line: 275, column: 3, scope: !25, inlinedAt: !32)
-// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !26, line: 275, type: !27, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29)
+// CHECK:STDOUT: !24 = !DILocation(line: 277, column: 3, scope: !25, inlinedAt: !32)
+// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !26, line: 277, type: !27, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29)
 // CHECK:STDOUT: !26 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !27 = !DISubroutineType(types: !28)
 // CHECK:STDOUT: !28 = !{null, !7, !7}
 // CHECK:STDOUT: !29 = !{!30, !31}
 // CHECK:STDOUT: !30 = !DILocalVariable(arg: 1, scope: !25, type: !7)
 // CHECK:STDOUT: !31 = !DILocalVariable(arg: 2, scope: !25, type: !7)
-// CHECK:STDOUT: !32 = distinct !DILocation(line: 341, column: 5, scope: !33, inlinedAt: !38)
-// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !26, line: 339, type: !34, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !36)
+// CHECK:STDOUT: !32 = distinct !DILocation(line: 343, column: 5, scope: !33, inlinedAt: !38)
+// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !26, line: 341, type: !34, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !36)
 // CHECK:STDOUT: !34 = !DISubroutineType(types: !35)
 // CHECK:STDOUT: !35 = !{null, !7}
 // CHECK:STDOUT: !36 = !{!37}

+ 4 - 4
toolchain/driver/testdata/compile/optimize/optimize_default.carbon

@@ -113,16 +113,16 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
 // CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !16, type: !19)
 // CHECK:STDOUT: !22 = !DILocation(line: 18, column: 9, scope: !16)
 // CHECK:STDOUT: !23 = !DILocation(line: 19, column: 5, scope: !16)
-// CHECK:STDOUT: !24 = !DILocation(line: 275, column: 3, scope: !25, inlinedAt: !32)
-// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !26, line: 275, type: !27, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29)
+// CHECK:STDOUT: !24 = !DILocation(line: 277, column: 3, scope: !25, inlinedAt: !32)
+// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !26, line: 277, type: !27, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29)
 // CHECK:STDOUT: !26 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !27 = !DISubroutineType(types: !28)
 // CHECK:STDOUT: !28 = !{null, !7, !7}
 // CHECK:STDOUT: !29 = !{!30, !31}
 // CHECK:STDOUT: !30 = !DILocalVariable(arg: 1, scope: !25, type: !7)
 // CHECK:STDOUT: !31 = !DILocalVariable(arg: 2, scope: !25, type: !7)
-// CHECK:STDOUT: !32 = distinct !DILocation(line: 341, column: 5, scope: !33, inlinedAt: !38)
-// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !26, line: 339, type: !34, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !36)
+// CHECK:STDOUT: !32 = distinct !DILocation(line: 343, column: 5, scope: !33, inlinedAt: !38)
+// CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !26, line: 341, type: !34, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !36)
 // CHECK:STDOUT: !34 = !DISubroutineType(types: !35)
 // CHECK:STDOUT: !35 = !{null, !7}
 // CHECK:STDOUT: !36 = !{!37}

+ 7 - 7
toolchain/driver/testdata/compile/optimize/optimize_none.carbon

@@ -139,26 +139,26 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
 // CHECK:STDOUT: !25 = !DILocation(line: 20, column: 5, scope: !14)
 // CHECK:STDOUT: !26 = !DILocation(line: 18, column: 3, scope: !14)
 // CHECK:STDOUT: !27 = !DILocation(line: 15, column: 1, scope: !14)
-// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !29, line: 339, type: !30, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !32)
+// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !29, line: 341, type: !30, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !32)
 // CHECK:STDOUT: !29 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !30 = !DISubroutineType(types: !31)
 // CHECK:STDOUT: !31 = !{null, !7}
 // CHECK:STDOUT: !32 = !{!33}
 // CHECK:STDOUT: !33 = !DILocalVariable(arg: 1, scope: !28, type: !7)
-// CHECK:STDOUT: !34 = !DILocation(line: 341, column: 5, scope: !28)
-// CHECK:STDOUT: !35 = !DILocation(line: 339, column: 3, scope: !28)
-// CHECK:STDOUT: !36 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !29, line: 275, type: !37, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !39)
+// CHECK:STDOUT: !34 = !DILocation(line: 343, column: 5, scope: !28)
+// CHECK:STDOUT: !35 = !DILocation(line: 341, column: 3, scope: !28)
+// CHECK:STDOUT: !36 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !29, line: 277, type: !37, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !39)
 // CHECK:STDOUT: !37 = !DISubroutineType(types: !38)
 // CHECK:STDOUT: !38 = !{null, !7, !7}
 // CHECK:STDOUT: !39 = !{!40, !41}
 // CHECK:STDOUT: !40 = !DILocalVariable(arg: 1, scope: !36, type: !7)
 // CHECK:STDOUT: !41 = !DILocalVariable(arg: 2, scope: !36, type: !7)
 // CHECK:STDOUT: !42 = !DILocation(line: 4294967295, scope: !36)
-// CHECK:STDOUT: !43 = !DILocation(line: 275, column: 3, scope: !36)
-// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !45, line: 24, type: !46, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !48)
+// CHECK:STDOUT: !43 = !DILocation(line: 277, column: 3, scope: !36)
+// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !45, line: 32, type: !46, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !48)
 // CHECK:STDOUT: !45 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !46 = !DISubroutineType(types: !47)
 // CHECK:STDOUT: !47 = !{!7, !7}
 // CHECK:STDOUT: !48 = !{!49}
 // CHECK:STDOUT: !49 = !DILocalVariable(arg: 1, scope: !44, type: !7)
-// CHECK:STDOUT: !50 = !DILocation(line: 24, column: 38, scope: !44)
+// CHECK:STDOUT: !50 = !DILocation(line: 32, column: 38, scope: !44)

+ 7 - 7
toolchain/driver/testdata/compile/optimize/optimize_size.carbon

@@ -139,26 +139,26 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
 // CHECK:STDOUT: !25 = !DILocation(line: 20, column: 5, scope: !14)
 // CHECK:STDOUT: !26 = !DILocation(line: 18, column: 3, scope: !14)
 // CHECK:STDOUT: !27 = !DILocation(line: 15, column: 1, scope: !14)
-// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !29, line: 339, type: !30, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !32)
+// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !29, line: 341, type: !30, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !32)
 // CHECK:STDOUT: !29 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !30 = !DISubroutineType(types: !31)
 // CHECK:STDOUT: !31 = !{null, !7}
 // CHECK:STDOUT: !32 = !{!33}
 // CHECK:STDOUT: !33 = !DILocalVariable(arg: 1, scope: !28, type: !7)
-// CHECK:STDOUT: !34 = !DILocation(line: 341, column: 5, scope: !28)
-// CHECK:STDOUT: !35 = !DILocation(line: 339, column: 3, scope: !28)
-// CHECK:STDOUT: !36 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !29, line: 275, type: !37, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !39)
+// CHECK:STDOUT: !34 = !DILocation(line: 343, column: 5, scope: !28)
+// CHECK:STDOUT: !35 = !DILocation(line: 341, column: 3, scope: !28)
+// CHECK:STDOUT: !36 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !29, line: 277, type: !37, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !39)
 // CHECK:STDOUT: !37 = !DISubroutineType(types: !38)
 // CHECK:STDOUT: !38 = !{null, !7, !7}
 // CHECK:STDOUT: !39 = !{!40, !41}
 // CHECK:STDOUT: !40 = !DILocalVariable(arg: 1, scope: !36, type: !7)
 // CHECK:STDOUT: !41 = !DILocalVariable(arg: 2, scope: !36, type: !7)
 // CHECK:STDOUT: !42 = !DILocation(line: 4294967295, scope: !36)
-// CHECK:STDOUT: !43 = !DILocation(line: 275, column: 3, scope: !36)
-// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !45, line: 24, type: !46, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !48)
+// CHECK:STDOUT: !43 = !DILocation(line: 277, column: 3, scope: !36)
+// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !45, line: 32, type: !46, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !48)
 // CHECK:STDOUT: !45 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !46 = !DISubroutineType(types: !47)
 // CHECK:STDOUT: !47 = !{!7, !7}
 // CHECK:STDOUT: !48 = !{!49}
 // CHECK:STDOUT: !49 = !DILocalVariable(arg: 1, scope: !44, type: !7)
-// CHECK:STDOUT: !50 = !DILocation(line: 24, column: 38, scope: !44)
+// CHECK:STDOUT: !50 = !DILocation(line: 32, column: 38, scope: !44)

+ 4 - 4
toolchain/driver/testdata/compile/optimize/optimize_speed.carbon

@@ -128,16 +128,16 @@ fn VectorizedWithOptSpeed(a: array(i32, 65536)*) {
 // CHECK:STDOUT: !20 = !{!21}
 // CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !16, type: !19)
 // CHECK:STDOUT: !22 = !DILocation(line: 18, column: 9, scope: !16)
-// CHECK:STDOUT: !23 = !DILocation(line: 275, column: 3, scope: !24, inlinedAt: !31)
-// CHECK:STDOUT: !24 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !25, line: 275, type: !26, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !28)
+// CHECK:STDOUT: !23 = !DILocation(line: 277, column: 3, scope: !24, inlinedAt: !31)
+// CHECK:STDOUT: !24 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !25, line: 277, type: !26, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !28)
 // CHECK:STDOUT: !25 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !26 = !DISubroutineType(types: !27)
 // CHECK:STDOUT: !27 = !{null, !7, !7}
 // CHECK:STDOUT: !28 = !{!29, !30}
 // CHECK:STDOUT: !29 = !DILocalVariable(arg: 1, scope: !24, type: !7)
 // CHECK:STDOUT: !30 = !DILocalVariable(arg: 2, scope: !24, type: !7)
-// CHECK:STDOUT: !31 = distinct !DILocation(line: 341, column: 5, scope: !32, inlinedAt: !37)
-// CHECK:STDOUT: !32 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !25, line: 339, type: !33, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !35)
+// CHECK:STDOUT: !31 = distinct !DILocation(line: 343, column: 5, scope: !32, inlinedAt: !37)
+// CHECK:STDOUT: !32 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !25, line: 341, type: !33, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !35)
 // CHECK:STDOUT: !33 = !DISubroutineType(types: !34)
 // CHECK:STDOUT: !34 = !{null, !7}
 // CHECK:STDOUT: !35 = !{!36}

+ 5 - 0
toolchain/lower/handle_call.cpp

@@ -505,6 +505,11 @@ static auto HandleBuiltinCall(FunctionContext& context, SemIR::InstId inst_id,
                                     context.GetValue(arg_ids[0])));
       return;
     }
+
+    case SemIR::BuiltinFunctionKind::PointerUnsafeConvert: {
+      context.SetLocal(inst_id, context.GetValue(arg_ids[0]));
+      return;
+    }
   }
 
   CARBON_FATAL("Unsupported builtin call.");

+ 20 - 20
toolchain/lower/testdata/array/iterate.carbon

@@ -226,14 +226,14 @@ fn F() {
 // CHECK:STDOUT: !46 = !DILocalVariable(arg: 1, scope: !44, type: !17)
 // CHECK:STDOUT: !47 = !DILocation(line: 36, column: 12, scope: !44)
 // CHECK:STDOUT: !48 = !DILocation(line: 36, column: 5, scope: !44)
-// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !50, line: 339, type: !51, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !53)
+// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !50, line: 341, type: !51, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !53)
 // CHECK:STDOUT: !50 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !51 = !DISubroutineType(types: !52)
 // CHECK:STDOUT: !52 = !{null, !16}
 // CHECK:STDOUT: !53 = !{!54}
 // CHECK:STDOUT: !54 = !DILocalVariable(arg: 1, scope: !49, type: !16)
-// CHECK:STDOUT: !55 = !DILocation(line: 341, column: 5, scope: !49)
-// CHECK:STDOUT: !56 = !DILocation(line: 339, column: 3, scope: !49)
+// CHECK:STDOUT: !55 = !DILocation(line: 343, column: 5, scope: !49)
+// CHECK:STDOUT: !56 = !DILocation(line: 341, column: 3, scope: !49)
 // CHECK:STDOUT: !57 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.75e118c322ac5019", scope: null, file: !37, line: 29, type: !58, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !60)
 // CHECK:STDOUT: !58 = !DISubroutineType(types: !59)
 // CHECK:STDOUT: !59 = !{!17, !16}
@@ -246,37 +246,37 @@ fn F() {
 // CHECK:STDOUT: !66 = !{!17}
 // CHECK:STDOUT: !67 = !DILocation(line: 27, column: 12, scope: !64)
 // CHECK:STDOUT: !68 = !DILocation(line: 27, column: 5, scope: !64)
-// CHECK:STDOUT: !69 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 112, type: !38, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !70)
+// CHECK:STDOUT: !69 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 123, type: !38, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !70)
 // CHECK:STDOUT: !70 = !{!71}
 // CHECK:STDOUT: !71 = !DILocalVariable(arg: 1, scope: !69, type: !17)
-// CHECK:STDOUT: !72 = !DILocation(line: 113, column: 12, scope: !69)
-// CHECK:STDOUT: !73 = !DILocation(line: 113, column: 5, scope: !69)
-// CHECK:STDOUT: !74 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 115, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !75)
+// CHECK:STDOUT: !72 = !DILocation(line: 124, column: 12, scope: !69)
+// CHECK:STDOUT: !73 = !DILocation(line: 124, column: 5, scope: !69)
+// CHECK:STDOUT: !74 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 126, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !75)
 // CHECK:STDOUT: !75 = !{!76}
 // CHECK:STDOUT: !76 = !DILocalVariable(arg: 1, scope: !74, type: !17)
-// CHECK:STDOUT: !77 = !DILocation(line: 116, column: 12, scope: !74)
-// CHECK:STDOUT: !78 = !DILocation(line: 116, column: 5, scope: !74)
-// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.e2da7149b7fcf782.Core.dcdd24268af36579", scope: null, file: !50, line: 275, type: !80, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !82)
+// CHECK:STDOUT: !77 = !DILocation(line: 127, column: 12, scope: !74)
+// CHECK:STDOUT: !78 = !DILocation(line: 127, column: 5, scope: !74)
+// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.e2da7149b7fcf782.Core.dcdd24268af36579", scope: null, file: !50, line: 277, type: !80, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !82)
 // CHECK:STDOUT: !80 = !DISubroutineType(types: !81)
 // CHECK:STDOUT: !81 = !{null, !16, !16}
 // CHECK:STDOUT: !82 = !{!83, !84}
 // CHECK:STDOUT: !83 = !DILocalVariable(arg: 1, scope: !79, type: !16)
 // CHECK:STDOUT: !84 = !DILocalVariable(arg: 2, scope: !79, type: !16)
 // CHECK:STDOUT: !85 = !DILocation(line: 4294967295, scope: !79)
-// CHECK:STDOUT: !86 = !DILocation(line: 275, column: 3, scope: !79)
-// CHECK:STDOUT: !87 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 104, type: !58, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !88)
+// CHECK:STDOUT: !86 = !DILocation(line: 277, column: 3, scope: !79)
+// CHECK:STDOUT: !87 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 115, type: !58, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !88)
 // CHECK:STDOUT: !88 = !{!89}
 // CHECK:STDOUT: !89 = !DILocalVariable(arg: 1, scope: !87, type: !16)
-// CHECK:STDOUT: !90 = !DILocation(line: 108, column: 5, scope: !87)
-// CHECK:STDOUT: !91 = !DILocation(line: 109, column: 5, scope: !87)
-// CHECK:STDOUT: !92 = !DILocation(line: 110, column: 5, scope: !87)
-// CHECK:STDOUT: !93 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 99, type: !65, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !94 = !DILocation(line: 101, column: 5, scope: !93)
-// CHECK:STDOUT: !95 = !DILocation(line: 102, column: 5, scope: !93)
-// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.1e58d10da180d7d9:ImplicitAs.39e2e54f50ee65cc.Core.255ef555a3d2f793", scope: null, file: !97, line: 24, type: !98, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !100)
+// CHECK:STDOUT: !90 = !DILocation(line: 119, column: 5, scope: !87)
+// CHECK:STDOUT: !91 = !DILocation(line: 120, column: 5, scope: !87)
+// CHECK:STDOUT: !92 = !DILocation(line: 121, column: 5, scope: !87)
+// CHECK:STDOUT: !93 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !37, line: 110, type: !65, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !94 = !DILocation(line: 112, column: 5, scope: !93)
+// CHECK:STDOUT: !95 = !DILocation(line: 113, column: 5, scope: !93)
+// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.1e58d10da180d7d9:ImplicitAs.39e2e54f50ee65cc.Core.255ef555a3d2f793", scope: null, file: !97, line: 32, type: !98, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !100)
 // CHECK:STDOUT: !97 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !98 = !DISubroutineType(types: !99)
 // CHECK:STDOUT: !99 = !{!16, !16}
 // CHECK:STDOUT: !100 = !{!101}
 // CHECK:STDOUT: !101 = !DILocalVariable(arg: 1, scope: !96, type: !16)
-// CHECK:STDOUT: !102 = !DILocation(line: 24, column: 38, scope: !96)
+// CHECK:STDOUT: !102 = !DILocation(line: 32, column: 38, scope: !96)

+ 9 - 9
toolchain/lower/testdata/for/bindings.carbon

@@ -200,19 +200,19 @@ fn For() {
 // CHECK:STDOUT: !41 = !{!16}
 // CHECK:STDOUT: !42 = !DILocation(line: 27, column: 12, scope: !39)
 // CHECK:STDOUT: !43 = !DILocation(line: 27, column: 5, scope: !39)
-// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.c6c37881d2ed7d9d", scope: null, file: !29, line: 112, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.c6c37881d2ed7d9d", scope: null, file: !29, line: 123, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
 // CHECK:STDOUT: !45 = !{!46}
 // CHECK:STDOUT: !46 = !DILocalVariable(arg: 1, scope: !44, type: !16)
-// CHECK:STDOUT: !47 = !DILocation(line: 113, column: 12, scope: !44)
-// CHECK:STDOUT: !48 = !DILocation(line: 113, column: 5, scope: !44)
-// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.c6c37881d2ed7d9d", scope: null, file: !29, line: 115, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !50)
+// CHECK:STDOUT: !47 = !DILocation(line: 124, column: 12, scope: !44)
+// CHECK:STDOUT: !48 = !DILocation(line: 124, column: 5, scope: !44)
+// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.c6c37881d2ed7d9d", scope: null, file: !29, line: 126, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !50)
 // CHECK:STDOUT: !50 = !{!51}
 // CHECK:STDOUT: !51 = !DILocalVariable(arg: 1, scope: !49, type: !16)
-// CHECK:STDOUT: !52 = !DILocation(line: 116, column: 12, scope: !49)
-// CHECK:STDOUT: !53 = !DILocation(line: 116, column: 5, scope: !49)
-// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.c6c37881d2ed7d9d", scope: null, file: !29, line: 99, type: !40, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !55 = !DILocation(line: 101, column: 5, scope: !54)
-// CHECK:STDOUT: !56 = !DILocation(line: 102, column: 5, scope: !54)
+// CHECK:STDOUT: !52 = !DILocation(line: 127, column: 12, scope: !49)
+// CHECK:STDOUT: !53 = !DILocation(line: 127, column: 5, scope: !49)
+// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.c6c37881d2ed7d9d", scope: null, file: !29, line: 110, type: !40, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !55 = !DILocation(line: 112, column: 5, scope: !54)
+// CHECK:STDOUT: !56 = !DILocation(line: 113, column: 5, scope: !54)
 // CHECK:STDOUT: !57 = distinct !DISubprogram(name: "Op", linkageName: "_COp.e4daa70d026fdea2:Copy.Core.3e36085cb869f630", scope: null, file: !58, line: 58, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !59)
 // CHECK:STDOUT: !58 = !DIFile(filename: "{{.*}}/prelude/copy.carbon", directory: "")
 // CHECK:STDOUT: !59 = !{!60}

+ 20 - 20
toolchain/lower/testdata/for/break_continue.carbon

@@ -255,14 +255,14 @@ fn For() {
 // CHECK:STDOUT: !55 = !DILocalVariable(arg: 1, scope: !53, type: !23)
 // CHECK:STDOUT: !56 = !DILocation(line: 36, column: 12, scope: !53)
 // CHECK:STDOUT: !57 = !DILocation(line: 36, column: 5, scope: !53)
-// CHECK:STDOUT: !58 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !59, line: 339, type: !60, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !62)
+// CHECK:STDOUT: !58 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !59, line: 341, type: !60, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !62)
 // CHECK:STDOUT: !59 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !60 = !DISubroutineType(types: !61)
 // CHECK:STDOUT: !61 = !{null, !22}
 // CHECK:STDOUT: !62 = !{!63}
 // CHECK:STDOUT: !63 = !DILocalVariable(arg: 1, scope: !58, type: !22)
-// CHECK:STDOUT: !64 = !DILocation(line: 341, column: 5, scope: !58)
-// CHECK:STDOUT: !65 = !DILocation(line: 339, column: 3, scope: !58)
+// CHECK:STDOUT: !64 = !DILocation(line: 343, column: 5, scope: !58)
+// CHECK:STDOUT: !65 = !DILocation(line: 341, column: 3, scope: !58)
 // CHECK:STDOUT: !66 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.a88acd4c94838316", scope: null, file: !46, line: 29, type: !67, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !69)
 // CHECK:STDOUT: !67 = !DISubroutineType(types: !68)
 // CHECK:STDOUT: !68 = !{!23, !22}
@@ -275,37 +275,37 @@ fn For() {
 // CHECK:STDOUT: !75 = !{!23}
 // CHECK:STDOUT: !76 = !DILocation(line: 27, column: 12, scope: !73)
 // CHECK:STDOUT: !77 = !DILocation(line: 27, column: 5, scope: !73)
-// CHECK:STDOUT: !78 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 112, type: !47, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !79)
+// CHECK:STDOUT: !78 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 123, type: !47, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !79)
 // CHECK:STDOUT: !79 = !{!80}
 // CHECK:STDOUT: !80 = !DILocalVariable(arg: 1, scope: !78, type: !23)
-// CHECK:STDOUT: !81 = !DILocation(line: 113, column: 12, scope: !78)
-// CHECK:STDOUT: !82 = !DILocation(line: 113, column: 5, scope: !78)
-// CHECK:STDOUT: !83 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 115, type: !20, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !84)
+// CHECK:STDOUT: !81 = !DILocation(line: 124, column: 12, scope: !78)
+// CHECK:STDOUT: !82 = !DILocation(line: 124, column: 5, scope: !78)
+// CHECK:STDOUT: !83 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 126, type: !20, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !84)
 // CHECK:STDOUT: !84 = !{!85}
 // CHECK:STDOUT: !85 = !DILocalVariable(arg: 1, scope: !83, type: !23)
-// CHECK:STDOUT: !86 = !DILocation(line: 116, column: 12, scope: !83)
-// CHECK:STDOUT: !87 = !DILocation(line: 116, column: 5, scope: !83)
-// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.cfd8ddddc59ca787", scope: null, file: !59, line: 275, type: !89, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !91)
+// CHECK:STDOUT: !86 = !DILocation(line: 127, column: 12, scope: !83)
+// CHECK:STDOUT: !87 = !DILocation(line: 127, column: 5, scope: !83)
+// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.cfd8ddddc59ca787", scope: null, file: !59, line: 277, type: !89, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !91)
 // CHECK:STDOUT: !89 = !DISubroutineType(types: !90)
 // CHECK:STDOUT: !90 = !{null, !22, !22}
 // CHECK:STDOUT: !91 = !{!92, !93}
 // CHECK:STDOUT: !92 = !DILocalVariable(arg: 1, scope: !88, type: !22)
 // CHECK:STDOUT: !93 = !DILocalVariable(arg: 2, scope: !88, type: !22)
 // CHECK:STDOUT: !94 = !DILocation(line: 4294967295, scope: !88)
-// CHECK:STDOUT: !95 = !DILocation(line: 275, column: 3, scope: !88)
-// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 104, type: !67, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !97)
+// CHECK:STDOUT: !95 = !DILocation(line: 277, column: 3, scope: !88)
+// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 115, type: !67, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !97)
 // CHECK:STDOUT: !97 = !{!98}
 // CHECK:STDOUT: !98 = !DILocalVariable(arg: 1, scope: !96, type: !22)
-// CHECK:STDOUT: !99 = !DILocation(line: 108, column: 5, scope: !96)
-// CHECK:STDOUT: !100 = !DILocation(line: 109, column: 5, scope: !96)
-// CHECK:STDOUT: !101 = !DILocation(line: 110, column: 5, scope: !96)
-// CHECK:STDOUT: !102 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 99, type: !74, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !103 = !DILocation(line: 101, column: 5, scope: !102)
-// CHECK:STDOUT: !104 = !DILocation(line: 102, column: 5, scope: !102)
-// CHECK:STDOUT: !105 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.beca8a3ca33a86fb", scope: null, file: !106, line: 24, type: !107, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !109)
+// CHECK:STDOUT: !99 = !DILocation(line: 119, column: 5, scope: !96)
+// CHECK:STDOUT: !100 = !DILocation(line: 120, column: 5, scope: !96)
+// CHECK:STDOUT: !101 = !DILocation(line: 121, column: 5, scope: !96)
+// CHECK:STDOUT: !102 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !46, line: 110, type: !74, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !103 = !DILocation(line: 112, column: 5, scope: !102)
+// CHECK:STDOUT: !104 = !DILocation(line: 113, column: 5, scope: !102)
+// CHECK:STDOUT: !105 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.beca8a3ca33a86fb", scope: null, file: !106, line: 32, type: !107, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !109)
 // CHECK:STDOUT: !106 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !107 = !DISubroutineType(types: !108)
 // CHECK:STDOUT: !108 = !{!22, !22}
 // CHECK:STDOUT: !109 = !{!110}
 // CHECK:STDOUT: !110 = !DILocalVariable(arg: 1, scope: !105, type: !22)
-// CHECK:STDOUT: !111 = !DILocation(line: 24, column: 38, scope: !105)
+// CHECK:STDOUT: !111 = !DILocation(line: 32, column: 38, scope: !105)

+ 20 - 20
toolchain/lower/testdata/for/for.carbon

@@ -239,14 +239,14 @@ fn For() {
 // CHECK:STDOUT: !51 = !DILocalVariable(arg: 1, scope: !49, type: !19)
 // CHECK:STDOUT: !52 = !DILocation(line: 36, column: 12, scope: !49)
 // CHECK:STDOUT: !53 = !DILocation(line: 36, column: 5, scope: !49)
-// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !55, line: 339, type: !56, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !58)
+// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !55, line: 341, type: !56, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !58)
 // CHECK:STDOUT: !55 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !56 = !DISubroutineType(types: !57)
 // CHECK:STDOUT: !57 = !{null, !18}
 // CHECK:STDOUT: !58 = !{!59}
 // CHECK:STDOUT: !59 = !DILocalVariable(arg: 1, scope: !54, type: !18)
-// CHECK:STDOUT: !60 = !DILocation(line: 341, column: 5, scope: !54)
-// CHECK:STDOUT: !61 = !DILocation(line: 339, column: 3, scope: !54)
+// CHECK:STDOUT: !60 = !DILocation(line: 343, column: 5, scope: !54)
+// CHECK:STDOUT: !61 = !DILocation(line: 341, column: 3, scope: !54)
 // CHECK:STDOUT: !62 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.a88acd4c94838316", scope: null, file: !42, line: 29, type: !63, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !65)
 // CHECK:STDOUT: !63 = !DISubroutineType(types: !64)
 // CHECK:STDOUT: !64 = !{!19, !18}
@@ -259,37 +259,37 @@ fn For() {
 // CHECK:STDOUT: !71 = !{!19}
 // CHECK:STDOUT: !72 = !DILocation(line: 27, column: 12, scope: !69)
 // CHECK:STDOUT: !73 = !DILocation(line: 27, column: 5, scope: !69)
-// CHECK:STDOUT: !74 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 112, type: !43, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !75)
+// CHECK:STDOUT: !74 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 123, type: !43, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !75)
 // CHECK:STDOUT: !75 = !{!76}
 // CHECK:STDOUT: !76 = !DILocalVariable(arg: 1, scope: !74, type: !19)
-// CHECK:STDOUT: !77 = !DILocation(line: 113, column: 12, scope: !74)
-// CHECK:STDOUT: !78 = !DILocation(line: 113, column: 5, scope: !74)
-// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 115, type: !16, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !80)
+// CHECK:STDOUT: !77 = !DILocation(line: 124, column: 12, scope: !74)
+// CHECK:STDOUT: !78 = !DILocation(line: 124, column: 5, scope: !74)
+// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 126, type: !16, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !80)
 // CHECK:STDOUT: !80 = !{!81}
 // CHECK:STDOUT: !81 = !DILocalVariable(arg: 1, scope: !79, type: !19)
-// CHECK:STDOUT: !82 = !DILocation(line: 116, column: 12, scope: !79)
-// CHECK:STDOUT: !83 = !DILocation(line: 116, column: 5, scope: !79)
-// CHECK:STDOUT: !84 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.cfd8ddddc59ca787", scope: null, file: !55, line: 275, type: !85, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !87)
+// CHECK:STDOUT: !82 = !DILocation(line: 127, column: 12, scope: !79)
+// CHECK:STDOUT: !83 = !DILocation(line: 127, column: 5, scope: !79)
+// CHECK:STDOUT: !84 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.cfd8ddddc59ca787", scope: null, file: !55, line: 277, type: !85, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !87)
 // CHECK:STDOUT: !85 = !DISubroutineType(types: !86)
 // CHECK:STDOUT: !86 = !{null, !18, !18}
 // CHECK:STDOUT: !87 = !{!88, !89}
 // CHECK:STDOUT: !88 = !DILocalVariable(arg: 1, scope: !84, type: !18)
 // CHECK:STDOUT: !89 = !DILocalVariable(arg: 2, scope: !84, type: !18)
 // CHECK:STDOUT: !90 = !DILocation(line: 4294967295, scope: !84)
-// CHECK:STDOUT: !91 = !DILocation(line: 275, column: 3, scope: !84)
-// CHECK:STDOUT: !92 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 104, type: !63, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !93)
+// CHECK:STDOUT: !91 = !DILocation(line: 277, column: 3, scope: !84)
+// CHECK:STDOUT: !92 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 115, type: !63, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !93)
 // CHECK:STDOUT: !93 = !{!94}
 // CHECK:STDOUT: !94 = !DILocalVariable(arg: 1, scope: !92, type: !18)
-// CHECK:STDOUT: !95 = !DILocation(line: 108, column: 5, scope: !92)
-// CHECK:STDOUT: !96 = !DILocation(line: 109, column: 5, scope: !92)
-// CHECK:STDOUT: !97 = !DILocation(line: 110, column: 5, scope: !92)
-// CHECK:STDOUT: !98 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 99, type: !70, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !99 = !DILocation(line: 101, column: 5, scope: !98)
-// CHECK:STDOUT: !100 = !DILocation(line: 102, column: 5, scope: !98)
-// CHECK:STDOUT: !101 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.beca8a3ca33a86fb", scope: null, file: !102, line: 24, type: !103, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !105)
+// CHECK:STDOUT: !95 = !DILocation(line: 119, column: 5, scope: !92)
+// CHECK:STDOUT: !96 = !DILocation(line: 120, column: 5, scope: !92)
+// CHECK:STDOUT: !97 = !DILocation(line: 121, column: 5, scope: !92)
+// CHECK:STDOUT: !98 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.32fa7206ac42c9b7", scope: null, file: !42, line: 110, type: !70, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !99 = !DILocation(line: 112, column: 5, scope: !98)
+// CHECK:STDOUT: !100 = !DILocation(line: 113, column: 5, scope: !98)
+// CHECK:STDOUT: !101 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.beca8a3ca33a86fb", scope: null, file: !102, line: 32, type: !103, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !105)
 // CHECK:STDOUT: !102 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !103 = !DISubroutineType(types: !104)
 // CHECK:STDOUT: !104 = !{!18, !18}
 // CHECK:STDOUT: !105 = !{!106}
 // CHECK:STDOUT: !106 = !DILocalVariable(arg: 1, scope: !101, type: !18)
-// CHECK:STDOUT: !107 = !DILocation(line: 24, column: 38, scope: !101)
+// CHECK:STDOUT: !107 = !DILocation(line: 32, column: 38, scope: !101)

+ 8 - 8
toolchain/lower/testdata/interop/cpp/pointer.carbon

@@ -343,14 +343,14 @@ fn ReturnPtrWithThunk() -> Core.Optional(Cpp.C*) {
 // CHECK:STDOUT: !35 = distinct !DISubprogram(name: "ReturnPtrWithThunk", linkageName: "_CReturnPtrWithThunk.Main", scope: null, file: !6, line: 38, type: !21, spFlags: DISPFlagDefinition, unit: !5)
 // CHECK:STDOUT: !36 = !DILocation(line: 39, column: 10, scope: !35)
 // CHECK:STDOUT: !37 = !DILocation(line: 39, column: 3, scope: !35)
-// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41", scope: null, file: !39, line: 82, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !42)
+// CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41", scope: null, file: !39, line: 93, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !42)
 // CHECK:STDOUT: !39 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "")
 // CHECK:STDOUT: !40 = !DISubroutineType(types: !41)
 // CHECK:STDOUT: !41 = !{!10, !10}
 // CHECK:STDOUT: !42 = !{!43}
 // CHECK:STDOUT: !43 = !DILocalVariable(arg: 1, scope: !38, type: !10)
-// CHECK:STDOUT: !44 = !DILocation(line: 83, column: 12, scope: !38)
-// CHECK:STDOUT: !45 = !DILocation(line: 83, column: 5, scope: !38)
+// CHECK:STDOUT: !44 = !DILocation(line: 94, column: 12, scope: !38)
+// CHECK:STDOUT: !45 = !DILocation(line: 94, column: 5, scope: !38)
 // CHECK:STDOUT: !46 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.ea71e3f17b6b4efb", scope: null, file: !39, line: 68, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !47)
 // CHECK:STDOUT: !47 = !{!48}
 // CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !46, type: !10)
@@ -361,10 +361,10 @@ fn ReturnPtrWithThunk() -> Core.Optional(Cpp.C*) {
 // CHECK:STDOUT: !53 = !DILocalVariable(arg: 1, scope: !51, type: !10)
 // CHECK:STDOUT: !54 = !DILocation(line: 30, column: 12, scope: !51)
 // CHECK:STDOUT: !55 = !DILocation(line: 30, column: 5, scope: !51)
-// CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655", scope: null, file: !39, line: 125, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !57)
+// CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655", scope: null, file: !39, line: 138, type: !40, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !57)
 // CHECK:STDOUT: !57 = !{!58}
 // CHECK:STDOUT: !58 = !DILocalVariable(arg: 1, scope: !56, type: !10)
-// CHECK:STDOUT: !59 = !DILocation(line: 126, column: 14, scope: !56)
-// CHECK:STDOUT: !60 = !DILocation(line: 127, column: 5, scope: !56)
-// CHECK:STDOUT: !61 = !DILocation(line: 126, column: 18, scope: !56)
-// CHECK:STDOUT: !62 = !DILocation(line: 128, column: 5, scope: !56)
+// CHECK:STDOUT: !59 = !DILocation(line: 139, column: 14, scope: !56)
+// CHECK:STDOUT: !60 = !DILocation(line: 140, column: 5, scope: !56)
+// CHECK:STDOUT: !61 = !DILocation(line: 139, column: 18, scope: !56)
+// CHECK:STDOUT: !62 = !DILocation(line: 141, column: 5, scope: !56)

+ 258 - 45
toolchain/lower/testdata/interop/cpp/void.carbon

@@ -10,22 +10,54 @@
 // TIP: To dump output, run:
 // TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/void.carbon
 
-// --- take_void_ptr.h
+// --- void_ptr.h
 
 void take_void_ptr(void *p);
+void take_const_void_ptr(const void *p);
+void *return_void_ptr();
 
-// --- call.carbon
+// --- pass.carbon
 
 library "[[@TEST_NAME]]";
 
-import Cpp library "take_void_ptr.h";
+import Cpp library "void_ptr.h";
 
 fn PassVoidPtr(a: Cpp.void*) {
   Cpp.take_void_ptr(a);
 }
 
-// CHECK:STDOUT: ; ModuleID = 'call.carbon'
-// CHECK:STDOUT: source_filename = "call.carbon"
+fn PassIntPtr(a: Cpp.int*) {
+  Cpp.take_void_ptr(a);
+}
+
+fn PassIntPtrToConstVoidPtr(a: Cpp.int*) {
+  Cpp.take_const_void_ptr(a);
+}
+
+fn PassConstIntPtrToConstVoidPtr(a: const Cpp.int*) {
+  Cpp.take_const_void_ptr(a);
+}
+
+// --- receive.carbon
+
+library "[[@TEST_NAME]]";
+
+import Cpp library "void_ptr.h";
+
+fn ReceiveVoidPtr() -> Core.Optional(Cpp.void*) {
+  return Cpp.return_void_ptr();
+}
+
+fn ConvertFromVoidPtr(p: Cpp.void*) -> i32* {
+  return p unsafe as i32*;
+}
+
+fn ConvertFromConstVoidPtr(p: const Cpp.void*) -> const i32* {
+  return p unsafe as const i32*;
+}
+
+// CHECK:STDOUT: ; ModuleID = 'pass.carbon'
+// CHECK:STDOUT: source_filename = "pass.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:
@@ -44,37 +76,119 @@ fn PassVoidPtr(a: Cpp.void*) {
 // CHECK:STDOUT: declare void @_Z13take_void_ptrPv(ptr)
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5c62f2dbad753cd9"(ptr %self) #0 !dbg !16 {
-// CHECK:STDOUT:   %1 = call ptr @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d2075df181ac34c1"(ptr %self), !dbg !22
-// CHECK:STDOUT:   ret ptr %1, !dbg !23
+// CHECK:STDOUT: define void @_CPassIntPtr.Main(ptr %a) #0 !dbg !16 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %.loc11_21.2.temp = alloca ptr, align 8, !dbg !19
+// CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.call = call ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.63e244d930b21b2a"(ptr %a), !dbg !19
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %.loc11_21.2.temp), !dbg !19
+// CHECK:STDOUT:   store ptr %U.binding.as_type.as.ImplicitAs.impl.Convert.call, ptr %.loc11_21.2.temp, align 8, !dbg !19
+// CHECK:STDOUT:   %.loc11_21.4 = load ptr, ptr %.loc11_21.2.temp, align 8, !dbg !19
+// CHECK:STDOUT:   call void @_Z13take_void_ptrPv(ptr %.loc11_21.4), !dbg !20
+// CHECK:STDOUT:   ret void, !dbg !21
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define void @_CPassIntPtrToConstVoidPtr.Main(ptr %a) #0 !dbg !22 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %.loc15_27.2.temp = alloca ptr, align 8, !dbg !25
+// CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.call = call ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.3fcbaa3d70c86d44"(ptr %a), !dbg !25
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %.loc15_27.2.temp), !dbg !25
+// CHECK:STDOUT:   store ptr %U.binding.as_type.as.ImplicitAs.impl.Convert.call, ptr %.loc15_27.2.temp, align 8, !dbg !25
+// CHECK:STDOUT:   %.loc15_27.4 = load ptr, ptr %.loc15_27.2.temp, align 8, !dbg !25
+// CHECK:STDOUT:   call void @_Z19take_const_void_ptrPKv(ptr %.loc15_27.4), !dbg !26
+// CHECK:STDOUT:   ret void, !dbg !27
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: declare void @_Z19take_const_void_ptrPKv(ptr)
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define void @_CPassConstIntPtrToConstVoidPtr.Main(ptr %a) #0 !dbg !28 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %.loc19_27.2.temp = alloca ptr, align 8, !dbg !31
+// CHECK:STDOUT:   %U.binding.as_type.as.ImplicitAs.impl.Convert.call = call ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.3fcbaa3d70c86d44"(ptr %a), !dbg !31
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %.loc19_27.2.temp), !dbg !31
+// CHECK:STDOUT:   store ptr %U.binding.as_type.as.ImplicitAs.impl.Convert.call, ptr %.loc19_27.2.temp, align 8, !dbg !31
+// CHECK:STDOUT:   %.loc19_27.4 = load ptr, ptr %.loc19_27.2.temp, align 8, !dbg !31
+// CHECK:STDOUT:   call void @_Z19take_const_void_ptrPKv(ptr %.loc19_27.4), !dbg !32
+// CHECK:STDOUT:   ret void, !dbg !33
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5c62f2dbad753cd9"(ptr %self) #0 !dbg !34 {
+// CHECK:STDOUT:   %1 = call ptr @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d2075df181ac34c1"(ptr %self), !dbg !40
+// CHECK:STDOUT:   ret ptr %1, !dbg !41
 // CHECK:STDOUT: }
 // 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)) #1
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d2075df181ac34c1"(ptr %self) #0 !dbg !24 {
-// CHECK:STDOUT:   %1 = call ptr @_CSome.Optional.Core.d2075df181ac34c1(ptr %self), !dbg !27
-// CHECK:STDOUT:   ret ptr %1, !dbg !28
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.63e244d930b21b2a"(ptr %self) #0 !dbg !42 {
+// CHECK:STDOUT:   %1 = call ptr @"_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.599fcf6815ccd825"(ptr %self), !dbg !45
+// CHECK:STDOUT:   ret ptr %1, !dbg !46
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.3fcbaa3d70c86d44"(ptr %self) #0 !dbg !47 {
+// CHECK:STDOUT:   %1 = call ptr @"_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.40332936f52138f0"(ptr %self), !dbg !50
+// CHECK:STDOUT:   ret ptr %1, !dbg !51
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d2075df181ac34c1"(ptr %self) #0 !dbg !52 {
+// CHECK:STDOUT:   %1 = call ptr @_CSome.Optional.Core.d2075df181ac34c1(ptr %self), !dbg !55
+// CHECK:STDOUT:   ret ptr %1, !dbg !56
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.599fcf6815ccd825"(ptr %self) #0 !dbg !57 {
+// CHECK:STDOUT:   %temp = alloca ptr, align 8, !dbg !60
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %temp), !dbg !60
+// CHECK:STDOUT:   store ptr %self, ptr %temp, align 8, !dbg !60
+// CHECK:STDOUT:   %1 = load ptr, ptr %temp, align 8, !dbg !60
+// CHECK:STDOUT:   %2 = call ptr @_CSome.Optional.Core.d2075df181ac34c1(ptr %1), !dbg !61
+// CHECK:STDOUT:   ret ptr %2, !dbg !62
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.40332936f52138f0"(ptr %self) #0 !dbg !63 {
+// CHECK:STDOUT:   %temp = alloca ptr, align 8, !dbg !66
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %temp), !dbg !66
+// CHECK:STDOUT:   %1 = call ptr @"_CConvert:thunk.e8f8f92d3d08d149:ImplicitAs.ffd58aeb29886b72.Core.b88d1103f417c6d4"(ptr %self), !dbg !66
+// CHECK:STDOUT:   store ptr %1, ptr %temp, align 8, !dbg !66
+// CHECK:STDOUT:   %2 = load ptr, ptr %temp, align 8, !dbg !66
+// CHECK:STDOUT:   %3 = call ptr @_CSome.Optional.Core.d2075df181ac34c1(ptr %2), !dbg !67
+// CHECK:STDOUT:   ret ptr %3, !dbg !68
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr ptr @_CSome.Optional.Core.d2075df181ac34c1(ptr %value) #0 !dbg !29 {
-// CHECK:STDOUT:   %1 = call ptr @"_CSome.e8f8f92d3d08d149:OptionalStorage.Core.a3238f3d1f6ba299"(ptr %value), !dbg !32
-// CHECK:STDOUT:   ret ptr %1, !dbg !33
+// CHECK:STDOUT: define linkonce_odr ptr @_CSome.Optional.Core.d2075df181ac34c1(ptr %value) #0 !dbg !69 {
+// CHECK:STDOUT:   %1 = call ptr @"_CSome.e8f8f92d3d08d149:OptionalStorage.Core.a3238f3d1f6ba299"(ptr %value), !dbg !72
+// CHECK:STDOUT:   ret ptr %1, !dbg !73
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind
+// CHECK:STDOUT: define linkonce_odr ptr @"_CConvert:thunk.e8f8f92d3d08d149:ImplicitAs.ffd58aeb29886b72.Core.b88d1103f417c6d4"(ptr %self) #2 !dbg !74 {
+// CHECK:STDOUT:   ret ptr %self, !dbg !78
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr ptr @"_CSome.e8f8f92d3d08d149:OptionalStorage.Core.a3238f3d1f6ba299"(ptr %self) #0 !dbg !34 {
-// CHECK:STDOUT:   %1 = alloca ptr, align 8, !dbg !37
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %1), !dbg !37
-// CHECK:STDOUT:   store ptr %self, ptr %1, align 8, !dbg !38
-// CHECK:STDOUT:   %2 = load ptr, ptr %1, align 8, !dbg !39
-// CHECK:STDOUT:   ret ptr %2, !dbg !40
+// CHECK:STDOUT: define linkonce_odr ptr @"_CSome.e8f8f92d3d08d149:OptionalStorage.Core.a3238f3d1f6ba299"(ptr %self) #0 !dbg !79 {
+// CHECK:STDOUT:   %1 = alloca ptr, align 8, !dbg !82
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %1), !dbg !82
+// CHECK:STDOUT:   store ptr %self, ptr %1, align 8, !dbg !83
+// CHECK:STDOUT:   %2 = load ptr, ptr %1, align 8, !dbg !84
+// CHECK:STDOUT:   ret ptr %2, !dbg !85
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
+// CHECK:STDOUT: ; uselistorder directives
+// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 0, 1, 2, 6, 5, 4, 3 }
+// CHECK:STDOUT: uselistorder ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.3fcbaa3d70c86d44", { 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CSome.Optional.Core.d2075df181ac34c1, { 2, 1, 0 }
+// CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nounwind }
 // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
+// CHECK:STDOUT: attributes #2 = { alwaysinline nounwind }
 // CHECK:STDOUT:
 // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
 // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
@@ -85,7 +199,7 @@ fn PassVoidPtr(a: Cpp.void*) {
 // 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_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
-// CHECK:STDOUT: !6 = !DIFile(filename: "call.carbon", directory: "")
+// CHECK:STDOUT: !6 = !DIFile(filename: "pass.carbon", directory: "")
 // CHECK:STDOUT: !7 = distinct !DISubprogram(name: "PassVoidPtr", linkageName: "_CPassVoidPtr.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !11)
 // CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
 // CHECK:STDOUT: !9 = !{null, !10}
@@ -95,28 +209,127 @@ fn PassVoidPtr(a: Cpp.void*) {
 // CHECK:STDOUT: !13 = !DILocation(line: 7, column: 21, scope: !7)
 // CHECK:STDOUT: !14 = !DILocation(line: 7, column: 3, scope: !7)
 // CHECK:STDOUT: !15 = !DILocation(line: 6, column: 1, scope: !7)
-// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5c62f2dbad753cd9", scope: null, file: !17, line: 82, type: !18, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !20)
-// CHECK:STDOUT: !17 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "")
-// CHECK:STDOUT: !18 = !DISubroutineType(types: !19)
-// CHECK:STDOUT: !19 = !{!10, !10}
+// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "PassIntPtr", linkageName: "_CPassIntPtr.Main", scope: null, file: !6, line: 10, type: !8, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !17)
+// CHECK:STDOUT: !17 = !{!18}
+// CHECK:STDOUT: !18 = !DILocalVariable(arg: 1, scope: !16, type: !10)
+// CHECK:STDOUT: !19 = !DILocation(line: 11, column: 21, scope: !16)
+// CHECK:STDOUT: !20 = !DILocation(line: 11, column: 3, scope: !16)
+// CHECK:STDOUT: !21 = !DILocation(line: 10, column: 1, scope: !16)
+// CHECK:STDOUT: !22 = distinct !DISubprogram(name: "PassIntPtrToConstVoidPtr", linkageName: "_CPassIntPtrToConstVoidPtr.Main", scope: null, file: !6, line: 14, type: !8, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !23)
+// CHECK:STDOUT: !23 = !{!24}
+// CHECK:STDOUT: !24 = !DILocalVariable(arg: 1, scope: !22, type: !10)
+// CHECK:STDOUT: !25 = !DILocation(line: 15, column: 27, scope: !22)
+// CHECK:STDOUT: !26 = !DILocation(line: 15, column: 3, scope: !22)
+// CHECK:STDOUT: !27 = !DILocation(line: 14, column: 1, scope: !22)
+// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "PassConstIntPtrToConstVoidPtr", linkageName: "_CPassConstIntPtrToConstVoidPtr.Main", scope: null, file: !6, line: 18, type: !8, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !29)
+// CHECK:STDOUT: !29 = !{!30}
+// CHECK:STDOUT: !30 = !DILocalVariable(arg: 1, scope: !28, type: !10)
+// CHECK:STDOUT: !31 = !DILocation(line: 19, column: 27, scope: !28)
+// CHECK:STDOUT: !32 = !DILocation(line: 19, column: 3, scope: !28)
+// CHECK:STDOUT: !33 = !DILocation(line: 18, column: 1, scope: !28)
+// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5c62f2dbad753cd9", scope: null, file: !35, line: 93, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !38)
+// CHECK:STDOUT: !35 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "")
+// CHECK:STDOUT: !36 = !DISubroutineType(types: !37)
+// CHECK:STDOUT: !37 = !{!10, !10}
+// CHECK:STDOUT: !38 = !{!39}
+// CHECK:STDOUT: !39 = !DILocalVariable(arg: 1, scope: !34, type: !10)
+// CHECK:STDOUT: !40 = !DILocation(line: 94, column: 12, scope: !34)
+// CHECK:STDOUT: !41 = !DILocation(line: 94, column: 5, scope: !34)
+// CHECK:STDOUT: !42 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.63e244d930b21b2a", scope: null, file: !35, line: 93, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !43)
+// CHECK:STDOUT: !43 = !{!44}
+// CHECK:STDOUT: !44 = !DILocalVariable(arg: 1, scope: !42, type: !10)
+// CHECK:STDOUT: !45 = !DILocation(line: 94, column: 12, scope: !42)
+// CHECK:STDOUT: !46 = !DILocation(line: 94, column: 5, scope: !42)
+// CHECK:STDOUT: !47 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.3fcbaa3d70c86d44", scope: null, file: !35, line: 93, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !48)
+// CHECK:STDOUT: !48 = !{!49}
+// CHECK:STDOUT: !49 = !DILocalVariable(arg: 1, scope: !47, type: !10)
+// CHECK:STDOUT: !50 = !DILocation(line: 94, column: 12, scope: !47)
+// CHECK:STDOUT: !51 = !DILocation(line: 94, column: 5, scope: !47)
+// CHECK:STDOUT: !52 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d2075df181ac34c1", scope: null, file: !35, line: 68, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !53)
+// CHECK:STDOUT: !53 = !{!54}
+// CHECK:STDOUT: !54 = !DILocalVariable(arg: 1, scope: !52, type: !10)
+// CHECK:STDOUT: !55 = !DILocation(line: 69, column: 12, scope: !52)
+// CHECK:STDOUT: !56 = !DILocation(line: 69, column: 5, scope: !52)
+// CHECK:STDOUT: !57 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.599fcf6815ccd825", scope: null, file: !35, line: 75, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !58)
+// CHECK:STDOUT: !58 = !{!59}
+// CHECK:STDOUT: !59 = !DILocalVariable(arg: 1, scope: !57, type: !10)
+// CHECK:STDOUT: !60 = !DILocation(line: 76, column: 29, scope: !57)
+// CHECK:STDOUT: !61 = !DILocation(line: 76, column: 12, scope: !57)
+// CHECK:STDOUT: !62 = !DILocation(line: 76, column: 5, scope: !57)
+// CHECK:STDOUT: !63 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.40332936f52138f0", scope: null, file: !35, line: 75, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !64)
+// CHECK:STDOUT: !64 = !{!65}
+// CHECK:STDOUT: !65 = !DILocalVariable(arg: 1, scope: !63, type: !10)
+// CHECK:STDOUT: !66 = !DILocation(line: 76, column: 29, scope: !63)
+// CHECK:STDOUT: !67 = !DILocation(line: 76, column: 12, scope: !63)
+// CHECK:STDOUT: !68 = !DILocation(line: 76, column: 5, scope: !63)
+// CHECK:STDOUT: !69 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.d2075df181ac34c1", scope: null, file: !35, line: 29, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !70)
+// CHECK:STDOUT: !70 = !{!71}
+// CHECK:STDOUT: !71 = !DILocalVariable(arg: 1, scope: !69, type: !10)
+// CHECK:STDOUT: !72 = !DILocation(line: 30, column: 12, scope: !69)
+// CHECK:STDOUT: !73 = !DILocation(line: 30, column: 5, scope: !69)
+// CHECK:STDOUT: !74 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert:thunk.e8f8f92d3d08d149:ImplicitAs.ffd58aeb29886b72.Core.b88d1103f417c6d4", scope: null, file: !75, line: 40, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !76)
+// CHECK:STDOUT: !75 = !DIFile(filename: "{{.*}}/prelude/types/cpp/void.carbon", directory: "")
+// CHECK:STDOUT: !76 = !{!77}
+// CHECK:STDOUT: !77 = !DILocalVariable(arg: 1, scope: !74, type: !10)
+// CHECK:STDOUT: !78 = !DILocation(line: 40, column: 3, scope: !74)
+// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.a3238f3d1f6ba299", scope: null, file: !35, line: 138, type: !36, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !80)
+// CHECK:STDOUT: !80 = !{!81}
+// CHECK:STDOUT: !81 = !DILocalVariable(arg: 1, scope: !79, type: !10)
+// CHECK:STDOUT: !82 = !DILocation(line: 139, column: 14, scope: !79)
+// CHECK:STDOUT: !83 = !DILocation(line: 140, column: 5, scope: !79)
+// CHECK:STDOUT: !84 = !DILocation(line: 139, column: 18, scope: !79)
+// CHECK:STDOUT: !85 = !DILocation(line: 141, column: 5, scope: !79)
+// CHECK:STDOUT: ; ModuleID = 'receive.carbon'
+// CHECK:STDOUT: source_filename = "receive.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: ; Function Attrs: nounwind
+// CHECK:STDOUT: define ptr @_CReceiveVoidPtr.Main() #0 !dbg !7 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %return_void_ptr.call = call ptr @_Z15return_void_ptrv(), !dbg !11
+// CHECK:STDOUT:   ret ptr %return_void_ptr.call, !dbg !12
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: declare ptr @_Z15return_void_ptrv()
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define ptr @_CConvertFromVoidPtr.Main(ptr %p) #0 !dbg !13 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   ret ptr %p, !dbg !18
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define ptr @_CConvertFromConstVoidPtr.Main(ptr %p) #0 !dbg !19 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   ret ptr %p, !dbg !22
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: attributes #0 = { nounwind }
+// 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_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+// CHECK:STDOUT: !6 = !DIFile(filename: "receive.carbon", directory: "")
+// CHECK:STDOUT: !7 = distinct !DISubprogram(name: "ReceiveVoidPtr", linkageName: "_CReceiveVoidPtr.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
+// CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
+// CHECK:STDOUT: !9 = !{!10}
+// CHECK:STDOUT: !10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
+// CHECK:STDOUT: !11 = !DILocation(line: 7, column: 10, scope: !7)
+// CHECK:STDOUT: !12 = !DILocation(line: 7, column: 3, scope: !7)
+// CHECK:STDOUT: !13 = distinct !DISubprogram(name: "ConvertFromVoidPtr", linkageName: "_CConvertFromVoidPtr.Main", scope: null, file: !6, line: 10, type: !14, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !16)
+// CHECK:STDOUT: !14 = !DISubroutineType(types: !15)
+// CHECK:STDOUT: !15 = !{!10, !10}
+// CHECK:STDOUT: !16 = !{!17}
+// CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !13, type: !10)
+// CHECK:STDOUT: !18 = !DILocation(line: 11, column: 3, scope: !13)
+// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "ConvertFromConstVoidPtr", linkageName: "_CConvertFromConstVoidPtr.Main", scope: null, file: !6, line: 14, type: !14, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !20)
 // CHECK:STDOUT: !20 = !{!21}
-// CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !16, type: !10)
-// CHECK:STDOUT: !22 = !DILocation(line: 83, column: 12, scope: !16)
-// CHECK:STDOUT: !23 = !DILocation(line: 83, column: 5, scope: !16)
-// CHECK:STDOUT: !24 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d2075df181ac34c1", scope: null, file: !17, line: 68, type: !18, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !25)
-// CHECK:STDOUT: !25 = !{!26}
-// CHECK:STDOUT: !26 = !DILocalVariable(arg: 1, scope: !24, type: !10)
-// CHECK:STDOUT: !27 = !DILocation(line: 69, column: 12, scope: !24)
-// CHECK:STDOUT: !28 = !DILocation(line: 69, column: 5, scope: !24)
-// CHECK:STDOUT: !29 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.d2075df181ac34c1", scope: null, file: !17, line: 29, type: !18, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !30)
-// CHECK:STDOUT: !30 = !{!31}
-// CHECK:STDOUT: !31 = !DILocalVariable(arg: 1, scope: !29, type: !10)
-// CHECK:STDOUT: !32 = !DILocation(line: 30, column: 12, scope: !29)
-// CHECK:STDOUT: !33 = !DILocation(line: 30, column: 5, scope: !29)
-// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.a3238f3d1f6ba299", scope: null, file: !17, line: 125, type: !18, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !35)
-// CHECK:STDOUT: !35 = !{!36}
-// CHECK:STDOUT: !36 = !DILocalVariable(arg: 1, scope: !34, type: !10)
-// CHECK:STDOUT: !37 = !DILocation(line: 126, column: 14, scope: !34)
-// CHECK:STDOUT: !38 = !DILocation(line: 127, column: 5, scope: !34)
-// CHECK:STDOUT: !39 = !DILocation(line: 126, column: 18, scope: !34)
-// CHECK:STDOUT: !40 = !DILocation(line: 128, column: 5, scope: !34)
+// CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !19, type: !10)
+// CHECK:STDOUT: !22 = !DILocation(line: 15, column: 3, scope: !19)

+ 7 - 7
toolchain/lower/testdata/operators/increment.carbon

@@ -72,27 +72,27 @@ fn IncrSigned() {
 // CHECK:STDOUT: !7 = !DILocation(line: 5, column: 3, scope: !4)
 // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 3, scope: !4)
 // CHECK:STDOUT: !9 = !DILocation(line: 4, column: 1, scope: !4)
-// CHECK:STDOUT: !10 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !11, line: 339, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !15)
+// CHECK:STDOUT: !10 = distinct !DISubprogram(name: "Op", linkageName: "_COp.Int.9452f4c51951679b.Core:Inc.Core.be1e879c1ad406d8", scope: null, file: !11, line: 341, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !15)
 // CHECK:STDOUT: !11 = !DIFile(filename: "{{.*}}/prelude/types/int.carbon", directory: "")
 // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
 // CHECK:STDOUT: !13 = !{null, !14}
 // CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
 // CHECK:STDOUT: !15 = !{!16}
 // CHECK:STDOUT: !16 = !DILocalVariable(arg: 1, scope: !10, type: !14)
-// CHECK:STDOUT: !17 = !DILocation(line: 341, column: 5, scope: !10)
-// CHECK:STDOUT: !18 = !DILocation(line: 339, column: 3, scope: !10)
-// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !11, line: 275, type: !20, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !22)
+// CHECK:STDOUT: !17 = !DILocation(line: 343, column: 5, scope: !10)
+// CHECK:STDOUT: !18 = !DILocation(line: 341, column: 3, scope: !10)
+// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.Int.9452f4c51951679b.Core:AddAssignWith.5375cfcbca6d9e35.Core.75bec4d236c9daa5", scope: null, file: !11, line: 277, type: !20, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !22)
 // CHECK:STDOUT: !20 = !DISubroutineType(types: !21)
 // CHECK:STDOUT: !21 = !{null, !14, !14}
 // CHECK:STDOUT: !22 = !{!23, !24}
 // CHECK:STDOUT: !23 = !DILocalVariable(arg: 1, scope: !19, type: !14)
 // CHECK:STDOUT: !24 = !DILocalVariable(arg: 2, scope: !19, type: !14)
 // CHECK:STDOUT: !25 = !DILocation(line: 4294967295, scope: !19)
-// CHECK:STDOUT: !26 = !DILocation(line: 275, column: 3, scope: !19)
-// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !28, line: 24, type: !29, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !31)
+// CHECK:STDOUT: !26 = !DILocation(line: 277, column: 3, scope: !19)
+// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !28, line: 32, type: !29, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !31)
 // CHECK:STDOUT: !28 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !29 = !DISubroutineType(types: !30)
 // CHECK:STDOUT: !30 = !{!14, !14}
 // CHECK:STDOUT: !31 = !{!32}
 // CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !27, type: !14)
-// CHECK:STDOUT: !33 = !DILocation(line: 24, column: 38, scope: !27)
+// CHECK:STDOUT: !33 = !DILocation(line: 32, column: 38, scope: !27)

+ 134 - 121
toolchain/lower/testdata/primitives/optional.carbon

@@ -83,7 +83,7 @@ fn AddOrRemoveConst(a: i32, b: const i32) {
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
 // CHECK:STDOUT: define linkonce_odr i1 @_CHasValue.Optional.Core.cb8cde10e3c2d324(ptr %self) #0 !dbg !33 {
-// CHECK:STDOUT:   %1 = icmp eq ptr %self, null, !dbg !37
+// CHECK:STDOUT:   %1 = call i1 @"_CHas.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4"(ptr %self), !dbg !37
 // CHECK:STDOUT:   ret i1 %1, !dbg !38
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -155,81 +155,88 @@ fn AddOrRemoveConst(a: i32, b: const i32) {
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr ptr @"_CGet.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4"(ptr %value) #0 !dbg !92 {
-// CHECK:STDOUT:   ret ptr %value, !dbg !95
+// CHECK:STDOUT: define linkonce_odr i1 @"_CHas.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4"(ptr %value) #0 !dbg !92 {
+// CHECK:STDOUT:   %1 = icmp eq ptr %value, null, !dbg !95
+// CHECK:STDOUT:   %2 = xor i1 %1, true, !dbg !96
+// CHECK:STDOUT:   ret i1 %2, !dbg !97
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d4e523823e737747"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !96 {
-// CHECK:STDOUT:   call void @_CSome.Optional.Core.d4e523823e737747(ptr %return, i32 %self), !dbg !99
-// CHECK:STDOUT:   ret void, !dbg !100
+// CHECK:STDOUT: define linkonce_odr ptr @"_CGet.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4"(ptr %value) #0 !dbg !98 {
+// CHECK:STDOUT:   ret ptr %value, !dbg !101
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @"_CNone.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207"(ptr sret({ i32, i1 }) %return) #0 !dbg !101 {
-// CHECK:STDOUT:   %has_value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 1, !dbg !102
-// CHECK:STDOUT:   store i8 0, ptr %has_value, align 1, !dbg !102
-// CHECK:STDOUT:   ret void, !dbg !103
+// CHECK:STDOUT: define linkonce_odr void @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d4e523823e737747"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !102 {
+// CHECK:STDOUT:   call void @_CSome.Optional.Core.d4e523823e737747(ptr %return, i32 %self), !dbg !105
+// CHECK:STDOUT:   ret void, !dbg !106
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @"_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.dbad48707eb766d5"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !104 {
-// CHECK:STDOUT:   %temp = alloca i32, align 4, !dbg !107
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %temp), !dbg !107
-// CHECK:STDOUT:   %1 = call i32 @"_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b930bfdac0979466"(i32 %self), !dbg !107
-// CHECK:STDOUT:   store i32 %1, ptr %temp, align 4, !dbg !107
-// CHECK:STDOUT:   %2 = load i32, ptr %temp, align 4, !dbg !107
-// CHECK:STDOUT:   call void @_CSome.Optional.Core.2a814810f68c37ba(ptr %return, i32 %2), !dbg !108
+// CHECK:STDOUT: define linkonce_odr void @"_CNone.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207"(ptr sret({ i32, i1 }) %return) #0 !dbg !107 {
+// CHECK:STDOUT:   %has_value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 1, !dbg !108
+// CHECK:STDOUT:   store i8 0, ptr %has_value, align 1, !dbg !108
 // CHECK:STDOUT:   ret void, !dbg !109
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @_CSome.Optional.Core.d4e523823e737747(ptr sret({ i32, i1 }) %return, i32 %value) #0 !dbg !110 {
-// CHECK:STDOUT:   call void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207"(ptr %return, i32 %value), !dbg !113
-// CHECK:STDOUT:   ret void, !dbg !114
+// CHECK:STDOUT: define linkonce_odr void @"_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.dbad48707eb766d5"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !110 {
+// CHECK:STDOUT:   %temp = alloca i32, align 4, !dbg !113
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %temp), !dbg !113
+// CHECK:STDOUT:   %1 = call i32 @"_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b930bfdac0979466"(i32 %self), !dbg !113
+// CHECK:STDOUT:   store i32 %1, ptr %temp, align 4, !dbg !113
+// CHECK:STDOUT:   %2 = load i32, ptr %temp, align 4, !dbg !113
+// CHECK:STDOUT:   call void @_CSome.Optional.Core.2a814810f68c37ba(ptr %return, i32 %2), !dbg !114
+// CHECK:STDOUT:   ret void, !dbg !115
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr i32 @"_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b930bfdac0979466"(i32 %self) #0 !dbg !115 {
-// CHECK:STDOUT:   %temp = alloca i32, align 4, !dbg !118
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %temp), !dbg !118
-// CHECK:STDOUT:   %1 = call i32 @"_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e"(i32 %self), !dbg !118
-// CHECK:STDOUT:   ret i32 %1, !dbg !119
+// CHECK:STDOUT: define linkonce_odr void @_CSome.Optional.Core.d4e523823e737747(ptr sret({ i32, i1 }) %return, i32 %value) #0 !dbg !116 {
+// CHECK:STDOUT:   call void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207"(ptr %return, i32 %value), !dbg !119
+// CHECK:STDOUT:   ret void, !dbg !120
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @_CSome.Optional.Core.2a814810f68c37ba(ptr sret({ i32, i1 }) %return, i32 %value) #0 !dbg !120 {
-// CHECK:STDOUT:   call void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.d9fa83018d7f62e1"(ptr %return, i32 %value), !dbg !123
-// CHECK:STDOUT:   ret void, !dbg !124
+// CHECK:STDOUT: define linkonce_odr i32 @"_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b930bfdac0979466"(i32 %self) #0 !dbg !121 {
+// CHECK:STDOUT:   %temp = alloca i32, align 4, !dbg !124
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(ptr %temp), !dbg !124
+// CHECK:STDOUT:   %1 = call i32 @"_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e"(i32 %self), !dbg !124
+// CHECK:STDOUT:   ret i32 %1, !dbg !125
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !125 {
-// CHECK:STDOUT:   %value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 0, !dbg !128
-// CHECK:STDOUT:   store i32 %self, ptr %value, align 4, !dbg !128
-// CHECK:STDOUT:   %has_value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 1, !dbg !129
-// CHECK:STDOUT:   store i8 1, ptr %has_value, align 1, !dbg !129
+// CHECK:STDOUT: define linkonce_odr void @_CSome.Optional.Core.2a814810f68c37ba(ptr sret({ i32, i1 }) %return, i32 %value) #0 !dbg !126 {
+// CHECK:STDOUT:   call void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.d9fa83018d7f62e1"(ptr %return, i32 %value), !dbg !129
 // CHECK:STDOUT:   ret void, !dbg !130
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr i32 @"_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e"(i32 %self) #0 !dbg !131 {
-// CHECK:STDOUT:   ret i32 %self, !dbg !136
+// CHECK:STDOUT: define linkonce_odr void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !131 {
+// CHECK:STDOUT:   %value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 0, !dbg !134
+// CHECK:STDOUT:   store i32 %self, ptr %value, align 4, !dbg !134
+// CHECK:STDOUT:   %has_value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 1, !dbg !135
+// CHECK:STDOUT:   store i8 1, ptr %has_value, align 1, !dbg !135
+// CHECK:STDOUT:   ret void, !dbg !136
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.d9fa83018d7f62e1"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !137 {
-// CHECK:STDOUT:   %value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 0, !dbg !140
-// CHECK:STDOUT:   %1 = call i32 @"_COp.34e7a685d3648824:Copy.Core.64ccbb8e5d9a0b8e"(i32 %self), !dbg !141
-// CHECK:STDOUT:   store i32 %1, ptr %value, align 4, !dbg !140
-// CHECK:STDOUT:   %has_value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 1, !dbg !142
-// CHECK:STDOUT:   store i8 1, ptr %has_value, align 1, !dbg !142
-// CHECK:STDOUT:   ret void, !dbg !143
+// CHECK:STDOUT: define linkonce_odr i32 @"_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e"(i32 %self) #0 !dbg !137 {
+// CHECK:STDOUT:   ret i32 %self, !dbg !142
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; Function Attrs: nounwind
-// CHECK:STDOUT: define linkonce_odr i32 @"_COp.34e7a685d3648824:Copy.Core.64ccbb8e5d9a0b8e"(i32 %self) #0 !dbg !144 {
-// CHECK:STDOUT:   ret i32 %self, !dbg !148
+// CHECK:STDOUT: define linkonce_odr void @"_CSome.3e8267224c5dc9c2:OptionalStorage.Core.d9fa83018d7f62e1"(ptr sret({ i32, i1 }) %return, i32 %self) #0 !dbg !143 {
+// CHECK:STDOUT:   %value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 0, !dbg !146
+// CHECK:STDOUT:   %1 = call i32 @"_COp.34e7a685d3648824:Copy.Core.64ccbb8e5d9a0b8e"(i32 %self), !dbg !147
+// CHECK:STDOUT:   store i32 %1, ptr %value, align 4, !dbg !146
+// CHECK:STDOUT:   %has_value = getelementptr inbounds nuw { i32, i1 }, ptr %return, i32 0, i32 1, !dbg !148
+// CHECK:STDOUT:   store i8 1, ptr %has_value, align 1, !dbg !148
+// CHECK:STDOUT:   ret void, !dbg !149
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nounwind
+// CHECK:STDOUT: define linkonce_odr i32 @"_COp.34e7a685d3648824:Copy.Core.64ccbb8e5d9a0b8e"(i32 %self) #0 !dbg !150 {
+// CHECK:STDOUT:   ret i32 %self, !dbg !154
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
@@ -286,108 +293,114 @@ fn AddOrRemoveConst(a: i32, b: const i32) {
 // CHECK:STDOUT: !41 = !DILocalVariable(arg: 1, scope: !39, type: !7)
 // CHECK:STDOUT: !42 = !DILocation(line: 36, column: 12, scope: !39)
 // CHECK:STDOUT: !43 = !DILocation(line: 36, column: 5, scope: !39)
-// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.622e77b643a0d3a8", scope: null, file: !34, line: 82, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !47)
+// CHECK:STDOUT: !44 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.622e77b643a0d3a8", scope: null, file: !34, line: 93, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !47)
 // CHECK:STDOUT: !45 = !DISubroutineType(types: !46)
 // CHECK:STDOUT: !46 = !{!7, !20}
 // CHECK:STDOUT: !47 = !{!48}
 // CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !44, type: !20)
-// CHECK:STDOUT: !49 = !DILocation(line: 83, column: 12, scope: !44)
-// CHECK:STDOUT: !50 = !DILocation(line: 83, column: 5, scope: !44)
+// CHECK:STDOUT: !49 = !DILocation(line: 94, column: 12, scope: !44)
+// CHECK:STDOUT: !50 = !DILocation(line: 94, column: 5, scope: !44)
 // CHECK:STDOUT: !51 = distinct !DISubprogram(name: "None", linkageName: "_CNone.Optional.Core.d4e523823e737747", scope: null, file: !34, line: 26, type: !52, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !52 = !DISubroutineType(types: !53)
 // CHECK:STDOUT: !53 = !{!7}
 // CHECK:STDOUT: !54 = !DILocation(line: 27, column: 12, scope: !51)
 // CHECK:STDOUT: !55 = !DILocation(line: 27, column: 5, scope: !51)
-// CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.bd3a79eb4ffd3025", scope: null, file: !57, line: 28, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !58)
+// CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.bd3a79eb4ffd3025", scope: null, file: !57, line: 36, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !58)
 // CHECK:STDOUT: !57 = !DIFile(filename: "{{.*}}/prelude/operators/as.carbon", directory: "")
 // CHECK:STDOUT: !58 = !{!59}
 // CHECK:STDOUT: !59 = !DILocalVariable(arg: 1, scope: !56, type: !20)
-// CHECK:STDOUT: !60 = !DILocation(line: 28, column: 45, scope: !56)
-// CHECK:STDOUT: !61 = !DILocation(line: 28, column: 38, scope: !56)
-// CHECK:STDOUT: !62 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.a7b795aef3d7a0e5", scope: null, file: !34, line: 82, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !63)
+// CHECK:STDOUT: !60 = !DILocation(line: 36, column: 45, scope: !56)
+// CHECK:STDOUT: !61 = !DILocation(line: 36, column: 38, scope: !56)
+// CHECK:STDOUT: !62 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.a7b795aef3d7a0e5", scope: null, file: !34, line: 93, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !63)
 // CHECK:STDOUT: !63 = !{!64}
 // CHECK:STDOUT: !64 = !DILocalVariable(arg: 1, scope: !62, type: !20)
-// CHECK:STDOUT: !65 = !DILocation(line: 83, column: 12, scope: !62)
-// CHECK:STDOUT: !66 = !DILocation(line: 83, column: 5, scope: !62)
-// CHECK:STDOUT: !67 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b37806f50d6ac6f2", scope: null, file: !57, line: 28, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !68)
+// CHECK:STDOUT: !65 = !DILocation(line: 94, column: 12, scope: !62)
+// CHECK:STDOUT: !66 = !DILocation(line: 94, column: 5, scope: !62)
+// CHECK:STDOUT: !67 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b37806f50d6ac6f2", scope: null, file: !57, line: 36, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !68)
 // CHECK:STDOUT: !68 = !{!69}
 // CHECK:STDOUT: !69 = !DILocalVariable(arg: 1, scope: !67, type: !20)
-// CHECK:STDOUT: !70 = !DILocation(line: 28, column: 45, scope: !67)
-// CHECK:STDOUT: !71 = !DILocation(line: 28, column: 38, scope: !67)
-// CHECK:STDOUT: !72 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.bd3a79eb4ffd3025", scope: null, file: !57, line: 32, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !73)
+// CHECK:STDOUT: !70 = !DILocation(line: 36, column: 45, scope: !67)
+// CHECK:STDOUT: !71 = !DILocation(line: 36, column: 38, scope: !67)
+// CHECK:STDOUT: !72 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.bd3a79eb4ffd3025", scope: null, file: !57, line: 40, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !73)
 // CHECK:STDOUT: !73 = !{!74}
 // CHECK:STDOUT: !74 = !DILocalVariable(arg: 1, scope: !72, type: !20)
-// CHECK:STDOUT: !75 = !DILocation(line: 32, column: 45, scope: !72)
-// CHECK:STDOUT: !76 = !DILocation(line: 32, column: 38, scope: !72)
-// CHECK:STDOUT: !77 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.fdb5566b9a89e24d", scope: null, file: !57, line: 32, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !78)
+// CHECK:STDOUT: !75 = !DILocation(line: 40, column: 45, scope: !72)
+// CHECK:STDOUT: !76 = !DILocation(line: 40, column: 38, scope: !72)
+// CHECK:STDOUT: !77 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.fdb5566b9a89e24d", scope: null, file: !57, line: 40, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !78)
 // CHECK:STDOUT: !78 = !{!79}
 // CHECK:STDOUT: !79 = !DILocalVariable(arg: 1, scope: !77, type: !20)
-// CHECK:STDOUT: !80 = !DILocation(line: 32, column: 45, scope: !77)
-// CHECK:STDOUT: !81 = !DILocation(line: 32, column: 38, scope: !77)
-// CHECK:STDOUT: !82 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.b37806f50d6ac6f2", scope: null, file: !57, line: 32, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !83)
+// CHECK:STDOUT: !80 = !DILocation(line: 40, column: 45, scope: !77)
+// CHECK:STDOUT: !81 = !DILocation(line: 40, column: 38, scope: !77)
+// CHECK:STDOUT: !82 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.b37806f50d6ac6f2", scope: null, file: !57, line: 40, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !83)
 // CHECK:STDOUT: !83 = !{!84}
 // CHECK:STDOUT: !84 = !DILocalVariable(arg: 1, scope: !82, type: !20)
-// CHECK:STDOUT: !85 = !DILocation(line: 32, column: 45, scope: !82)
-// CHECK:STDOUT: !86 = !DILocation(line: 32, column: 38, scope: !82)
-// CHECK:STDOUT: !87 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.5fb98646c26c8976", scope: null, file: !57, line: 32, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !88)
+// CHECK:STDOUT: !85 = !DILocation(line: 40, column: 45, scope: !82)
+// CHECK:STDOUT: !86 = !DILocation(line: 40, column: 38, scope: !82)
+// CHECK:STDOUT: !87 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.17f42c13d842b71d:ImplicitAs.eb057aa32837c84e.Core.5fb98646c26c8976", scope: null, file: !57, line: 40, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !88)
 // CHECK:STDOUT: !88 = !{!89}
 // CHECK:STDOUT: !89 = !DILocalVariable(arg: 1, scope: !87, type: !20)
-// CHECK:STDOUT: !90 = !DILocation(line: 32, column: 45, scope: !87)
-// CHECK:STDOUT: !91 = !DILocation(line: 32, column: 38, scope: !87)
-// CHECK:STDOUT: !92 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4", scope: null, file: !34, line: 131, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !93)
+// CHECK:STDOUT: !90 = !DILocation(line: 40, column: 45, scope: !87)
+// CHECK:STDOUT: !91 = !DILocation(line: 40, column: 38, scope: !87)
+// CHECK:STDOUT: !92 = distinct !DISubprogram(name: "Has", linkageName: "_CHas.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4", scope: null, file: !34, line: 143, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !93)
 // CHECK:STDOUT: !93 = !{!94}
 // CHECK:STDOUT: !94 = !DILocalVariable(arg: 1, scope: !92, type: !7)
-// CHECK:STDOUT: !95 = !DILocation(line: 132, column: 5, scope: !92)
-// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d4e523823e737747", scope: null, file: !34, line: 68, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !97)
-// CHECK:STDOUT: !97 = !{!98}
-// CHECK:STDOUT: !98 = !DILocalVariable(arg: 1, scope: !96, type: !20)
-// CHECK:STDOUT: !99 = !DILocation(line: 69, column: 12, scope: !96)
-// CHECK:STDOUT: !100 = !DILocation(line: 69, column: 5, scope: !96)
-// CHECK:STDOUT: !101 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !34, line: 99, type: !52, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !102 = !DILocation(line: 101, column: 5, scope: !101)
-// CHECK:STDOUT: !103 = !DILocation(line: 102, column: 5, scope: !101)
-// CHECK:STDOUT: !104 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.dbad48707eb766d5", scope: null, file: !34, line: 75, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !105)
-// CHECK:STDOUT: !105 = !{!106}
-// CHECK:STDOUT: !106 = !DILocalVariable(arg: 1, scope: !104, type: !20)
-// CHECK:STDOUT: !107 = !DILocation(line: 76, column: 29, scope: !104)
-// CHECK:STDOUT: !108 = !DILocation(line: 76, column: 12, scope: !104)
-// CHECK:STDOUT: !109 = !DILocation(line: 76, column: 5, scope: !104)
-// CHECK:STDOUT: !110 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.d4e523823e737747", scope: null, file: !34, line: 29, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !111)
+// CHECK:STDOUT: !95 = !DILocation(line: 144, column: 16, scope: !92)
+// CHECK:STDOUT: !96 = !DILocation(line: 144, column: 12, scope: !92)
+// CHECK:STDOUT: !97 = !DILocation(line: 144, column: 5, scope: !92)
+// CHECK:STDOUT: !98 = distinct !DISubprogram(name: "Get", linkageName: "_CGet.e8f8f92d3d08d149:OptionalStorage.Core.b88d1103f417c6d4", scope: null, file: !34, line: 146, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !99)
+// CHECK:STDOUT: !99 = !{!100}
+// CHECK:STDOUT: !100 = !DILocalVariable(arg: 1, scope: !98, type: !7)
+// CHECK:STDOUT: !101 = !DILocation(line: 147, column: 5, scope: !98)
+// CHECK:STDOUT: !102 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.d4e523823e737747", scope: null, file: !34, line: 68, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !103)
+// CHECK:STDOUT: !103 = !{!104}
+// CHECK:STDOUT: !104 = !DILocalVariable(arg: 1, scope: !102, type: !20)
+// CHECK:STDOUT: !105 = !DILocation(line: 69, column: 12, scope: !102)
+// CHECK:STDOUT: !106 = !DILocation(line: 69, column: 5, scope: !102)
+// CHECK:STDOUT: !107 = distinct !DISubprogram(name: "None", linkageName: "_CNone.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !34, line: 110, type: !52, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !108 = !DILocation(line: 112, column: 5, scope: !107)
+// CHECK:STDOUT: !109 = !DILocation(line: 113, column: 5, scope: !107)
+// CHECK:STDOUT: !110 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.3667eb502d1ddfa9:OptionalAs.c7a50af9bdd61b43.Core.dbad48707eb766d5", scope: null, file: !34, line: 75, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !111)
 // CHECK:STDOUT: !111 = !{!112}
 // CHECK:STDOUT: !112 = !DILocalVariable(arg: 1, scope: !110, type: !20)
-// CHECK:STDOUT: !113 = !DILocation(line: 30, column: 12, scope: !110)
-// CHECK:STDOUT: !114 = !DILocation(line: 30, column: 5, scope: !110)
-// CHECK:STDOUT: !115 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b930bfdac0979466", scope: null, file: !57, line: 28, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !116)
-// CHECK:STDOUT: !116 = !{!117}
-// CHECK:STDOUT: !117 = !DILocalVariable(arg: 1, scope: !115, type: !20)
-// CHECK:STDOUT: !118 = !DILocation(line: 28, column: 45, scope: !115)
-// CHECK:STDOUT: !119 = !DILocation(line: 28, column: 38, scope: !115)
-// CHECK:STDOUT: !120 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.2a814810f68c37ba", scope: null, file: !34, line: 29, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !121)
-// CHECK:STDOUT: !121 = !{!122}
-// CHECK:STDOUT: !122 = !DILocalVariable(arg: 1, scope: !120, type: !20)
-// CHECK:STDOUT: !123 = !DILocation(line: 30, column: 12, scope: !120)
-// CHECK:STDOUT: !124 = !DILocation(line: 30, column: 5, scope: !120)
-// CHECK:STDOUT: !125 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !34, line: 104, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !126)
-// CHECK:STDOUT: !126 = !{!127}
-// CHECK:STDOUT: !127 = !DILocalVariable(arg: 1, scope: !125, type: !20)
-// CHECK:STDOUT: !128 = !DILocation(line: 108, column: 5, scope: !125)
-// CHECK:STDOUT: !129 = !DILocation(line: 109, column: 5, scope: !125)
-// CHECK:STDOUT: !130 = !DILocation(line: 110, column: 5, scope: !125)
-// CHECK:STDOUT: !131 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !57, line: 24, type: !132, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !134)
-// CHECK:STDOUT: !132 = !DISubroutineType(types: !133)
-// CHECK:STDOUT: !133 = !{!20, !20}
-// CHECK:STDOUT: !134 = !{!135}
-// CHECK:STDOUT: !135 = !DILocalVariable(arg: 1, scope: !131, type: !20)
-// CHECK:STDOUT: !136 = !DILocation(line: 24, column: 38, scope: !131)
-// CHECK:STDOUT: !137 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.d9fa83018d7f62e1", scope: null, file: !34, line: 104, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !138)
-// CHECK:STDOUT: !138 = !{!139}
-// CHECK:STDOUT: !139 = !DILocalVariable(arg: 1, scope: !137, type: !20)
-// CHECK:STDOUT: !140 = !DILocation(line: 108, column: 5, scope: !137)
-// CHECK:STDOUT: !141 = !DILocation(line: 108, column: 28, scope: !137)
-// CHECK:STDOUT: !142 = !DILocation(line: 109, column: 5, scope: !137)
-// CHECK:STDOUT: !143 = !DILocation(line: 110, column: 5, scope: !137)
-// CHECK:STDOUT: !144 = distinct !DISubprogram(name: "Op", linkageName: "_COp.34e7a685d3648824:Copy.Core.64ccbb8e5d9a0b8e", scope: null, file: !145, line: 19, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !146)
-// CHECK:STDOUT: !145 = !DIFile(filename: "{{.*}}/prelude/copy.carbon", directory: "")
-// CHECK:STDOUT: !146 = !{!147}
-// CHECK:STDOUT: !147 = !DILocalVariable(arg: 1, scope: !144, type: !20)
-// CHECK:STDOUT: !148 = !DILocation(line: 19, column: 33, scope: !144)
+// CHECK:STDOUT: !113 = !DILocation(line: 76, column: 29, scope: !110)
+// CHECK:STDOUT: !114 = !DILocation(line: 76, column: 12, scope: !110)
+// CHECK:STDOUT: !115 = !DILocation(line: 76, column: 5, scope: !110)
+// CHECK:STDOUT: !116 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.d4e523823e737747", scope: null, file: !34, line: 29, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !117)
+// CHECK:STDOUT: !117 = !{!118}
+// CHECK:STDOUT: !118 = !DILocalVariable(arg: 1, scope: !116, type: !20)
+// CHECK:STDOUT: !119 = !DILocation(line: 30, column: 12, scope: !116)
+// CHECK:STDOUT: !120 = !DILocation(line: 30, column: 5, scope: !116)
+// CHECK:STDOUT: !121 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.a44fce96e16342e7:ImplicitAs.ad22d1bbc0605210.Core.b930bfdac0979466", scope: null, file: !57, line: 36, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !122)
+// CHECK:STDOUT: !122 = !{!123}
+// CHECK:STDOUT: !123 = !DILocalVariable(arg: 1, scope: !121, type: !20)
+// CHECK:STDOUT: !124 = !DILocation(line: 36, column: 45, scope: !121)
+// CHECK:STDOUT: !125 = !DILocation(line: 36, column: 38, scope: !121)
+// CHECK:STDOUT: !126 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.2a814810f68c37ba", scope: null, file: !34, line: 29, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !127)
+// CHECK:STDOUT: !127 = !{!128}
+// CHECK:STDOUT: !128 = !DILocalVariable(arg: 1, scope: !126, type: !20)
+// CHECK:STDOUT: !129 = !DILocation(line: 30, column: 12, scope: !126)
+// CHECK:STDOUT: !130 = !DILocation(line: 30, column: 5, scope: !126)
+// CHECK:STDOUT: !131 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.329e9a7481f16207", scope: null, file: !34, line: 115, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !132)
+// CHECK:STDOUT: !132 = !{!133}
+// CHECK:STDOUT: !133 = !DILocalVariable(arg: 1, scope: !131, type: !20)
+// CHECK:STDOUT: !134 = !DILocation(line: 119, column: 5, scope: !131)
+// CHECK:STDOUT: !135 = !DILocation(line: 120, column: 5, scope: !131)
+// CHECK:STDOUT: !136 = !DILocation(line: 121, column: 5, scope: !131)
+// CHECK:STDOUT: !137 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.14b8745117b2bc54:ImplicitAs.a9271c1e04015f9c.Core.64ccbb8e5d9a0b8e", scope: null, file: !57, line: 32, type: !138, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !140)
+// CHECK:STDOUT: !138 = !DISubroutineType(types: !139)
+// CHECK:STDOUT: !139 = !{!20, !20}
+// CHECK:STDOUT: !140 = !{!141}
+// CHECK:STDOUT: !141 = !DILocalVariable(arg: 1, scope: !137, type: !20)
+// CHECK:STDOUT: !142 = !DILocation(line: 32, column: 38, scope: !137)
+// CHECK:STDOUT: !143 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.3e8267224c5dc9c2:OptionalStorage.Core.d9fa83018d7f62e1", scope: null, file: !34, line: 115, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !144)
+// CHECK:STDOUT: !144 = !{!145}
+// CHECK:STDOUT: !145 = !DILocalVariable(arg: 1, scope: !143, type: !20)
+// CHECK:STDOUT: !146 = !DILocation(line: 119, column: 5, scope: !143)
+// CHECK:STDOUT: !147 = !DILocation(line: 119, column: 28, scope: !143)
+// CHECK:STDOUT: !148 = !DILocation(line: 120, column: 5, scope: !143)
+// CHECK:STDOUT: !149 = !DILocation(line: 121, column: 5, scope: !143)
+// CHECK:STDOUT: !150 = distinct !DISubprogram(name: "Op", linkageName: "_COp.34e7a685d3648824:Copy.Core.64ccbb8e5d9a0b8e", scope: null, file: !151, line: 19, type: !45, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !152)
+// CHECK:STDOUT: !151 = !DIFile(filename: "{{.*}}/prelude/copy.carbon", directory: "")
+// CHECK:STDOUT: !152 = !{!153}
+// CHECK:STDOUT: !153 = !DILocalVariable(arg: 1, scope: !150, type: !20)
+// CHECK:STDOUT: !154 = !DILocation(line: 19, column: 33, scope: !150)

+ 7 - 0
toolchain/sem_ir/builtin_function_kind.cpp

@@ -719,6 +719,13 @@ constexpr BuiltinInfo PointerIsNull = {
     "pointer.is_null",
     ValidateSignature<auto(MaybeUnformed<PointerTo<AnyType>>)->Bool>};
 
+// "pointer.unsafe_convert": convert a pointer of one type to a pointer of a
+// different type without performing any checking that the conversion makes
+// sense.
+constexpr BuiltinInfo PointerUnsafeConvert = {
+    "pointer.unsafe_convert",
+    ValidateSignature<auto(PointerTo<AnyType>)->PointerTo<AnyType>>};
+
 // "type.and": facet type combination.
 constexpr BuiltinInfo TypeAnd = {"type.and",
                                  ValidateSignature<auto(Type, Type)->Type>};

+ 1 - 0
toolchain/sem_ir/builtin_function_kind.def

@@ -127,6 +127,7 @@ CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(BoolNeq)
 // Pointers.
 CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PointerMakeNull)
 CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PointerIsNull)
+CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PointerUnsafeConvert)
 
 // Facet type combination.
 CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(TypeAnd)