Explorar el Código

Change tests in check/testdata/builtins/char to be tests for the builtin char functions. (#5956)

Follow the pattern used by other tests in check/testdata/builtins.
Richard Smith hace 8 meses
padre
commit
ae54873441

+ 0 - 133
toolchain/check/testdata/builtins/char/basics.carbon

@@ -1,133 +0,0 @@
-// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-// Exceptions. See /LICENSE for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
-//
-// AUTOUPDATE
-// TIP: To test this file alone, run:
-// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/char/basics.carbon
-// TIP: To dump output, run:
-// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/char/basics.carbon
-
-// --- basics.carbon
-
-library "[[@TEST_NAME]]";
-
-//@dump-sem-ir-begin
-let c: Core.Char = 'a';
-let nul: Core.Char = '\0';
-let lit: Core.CharLiteral() = '\u{1E15}';
-//@dump-sem-ir-end
-
-let lit_as_char: Core.Char = c;
-
-// --- fail_size_small.carbon
-
-library "[[@TEST_NAME]]";
-
-// CHECK:STDERR: fail_size_small.carbon:[[@LINE+4]]:20: error: character value U+0080 too large for type `Core.Char` [CharTooLargeForType]
-// CHECK:STDERR: let c: Core.Char = '\u{80}';
-// CHECK:STDERR:                    ^~~~~~~~
-// CHECK:STDERR:
-let c: Core.Char = '\u{80}';
-
-// --- fail_size_multi_byte.carbon
-
-library "[[@TEST_NAME]]";
-
-// CHECK:STDERR: fail_size_multi_byte.carbon:[[@LINE+4]]:20: error: character value U+1E15 too large for type `Core.Char` [CharTooLargeForType]
-// CHECK:STDERR: let c: Core.Char = '\u{1E15}';
-// CHECK:STDERR:                    ^~~~~~~~~~
-// CHECK:STDERR:
-let c: Core.Char = '\u{1E15}';
-
-// CHECK:STDOUT: --- basics.carbon
-// CHECK:STDOUT:
-// CHECK:STDOUT: constants {
-// CHECK:STDOUT:   %Char: type = class_type @Char [concrete]
-// CHECK:STDOUT:   %pattern_type.b09: type = pattern_type %Char [concrete]
-// CHECK:STDOUT:   %.54f: Core.CharLiteral = char_value U+0061 [concrete]
-// CHECK:STDOUT:   %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
-// CHECK:STDOUT:   %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
-// CHECK:STDOUT:   %ImplicitAs.type.715: type = facet_type <@ImplicitAs, @ImplicitAs(%Char)> [concrete]
-// CHECK:STDOUT:   %ImplicitAs.Convert.type.f57: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%Char) [concrete]
-// CHECK:STDOUT:   %ImplicitAs.impl_witness.b70: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.aed [concrete]
-// CHECK:STDOUT:   %ImplicitAs.facet: %ImplicitAs.type.715 = facet_value Core.CharLiteral, (%ImplicitAs.impl_witness.b70) [concrete]
-// CHECK:STDOUT:   %.a57: type = fn_type_with_self_type %ImplicitAs.Convert.type.f57, %ImplicitAs.facet [concrete]
-// CHECK:STDOUT:   %Core.CharLiteral.as.ImplicitAs.impl.Convert.type: type = fn_type @Core.CharLiteral.as.ImplicitAs.impl.Convert [concrete]
-// CHECK:STDOUT:   %Core.CharLiteral.as.ImplicitAs.impl.Convert: %Core.CharLiteral.as.ImplicitAs.impl.Convert.type = struct_value () [concrete]
-// CHECK:STDOUT:   %pattern_type.8c6: type = pattern_type Core.CharLiteral [concrete]
-// CHECK:STDOUT:   %Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.142: <bound method> = bound_method %.54f, %Core.CharLiteral.as.ImplicitAs.impl.Convert [concrete]
-// CHECK:STDOUT:   %int_97: %Char = int_value 97 [concrete]
-// CHECK:STDOUT:   %.dc9: Core.CharLiteral = char_value U+0000 [concrete]
-// CHECK:STDOUT:   %Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.f0f: <bound method> = bound_method %.dc9, %Core.CharLiteral.as.ImplicitAs.impl.Convert [concrete]
-// CHECK:STDOUT:   %int_0: %Char = int_value 0 [concrete]
-// CHECK:STDOUT:   %CharLiteral.type: type = fn_type @CharLiteral [concrete]
-// CHECK:STDOUT:   %CharLiteral: %CharLiteral.type = struct_value () [concrete]
-// CHECK:STDOUT:   %.a81: Core.CharLiteral = char_value U+1E15 [concrete]
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: imports {
-// CHECK:STDOUT:   %Core: <namespace> = namespace file.%Core.import, [concrete] {
-// CHECK:STDOUT:     .Char = %Core.Char
-// CHECK:STDOUT:     .ImplicitAs = %Core.ImplicitAs
-// CHECK:STDOUT:     .CharLiteral = %Core.CharLiteral
-// CHECK:STDOUT:     import Core//prelude
-// CHECK:STDOUT:     import Core//prelude/...
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %Core.Char: type = import_ref Core//prelude/types/char, Char, loaded [concrete = constants.%Char]
-// CHECK:STDOUT:   %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
-// CHECK:STDOUT:   %Core.import_ref.0f8: %Core.CharLiteral.as.ImplicitAs.impl.Convert.type = import_ref Core//prelude/types/char, loc18_36, loaded [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert]
-// CHECK:STDOUT:   %ImplicitAs.impl_witness_table.aed = impl_witness_table (%Core.import_ref.0f8), @Core.CharLiteral.as.ImplicitAs.impl [concrete]
-// CHECK:STDOUT:   %Core.CharLiteral: %CharLiteral.type = import_ref Core//prelude/types/char, CharLiteral, loaded [concrete = constants.%CharLiteral]
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: file {
-// CHECK:STDOUT:   name_binding_decl {
-// CHECK:STDOUT:     %c.patt: %pattern_type.b09 = binding_pattern c [concrete]
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc5_12: type = splice_block %Char.ref.loc5 [concrete = constants.%Char] {
-// CHECK:STDOUT:     %Core.ref.loc5: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
-// CHECK:STDOUT:     %Char.ref.loc5: type = name_ref Char, imports.%Core.Char [concrete = constants.%Char]
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %impl.elem0.loc5: %.a57 = impl_witness_access constants.%ImplicitAs.impl_witness.b70, element0 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert]
-// CHECK:STDOUT:   %bound_method.loc5: <bound method> = bound_method @__global_init.%.loc5, %impl.elem0.loc5 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.142]
-// CHECK:STDOUT:   %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc5: init %Char = call %bound_method.loc5(@__global_init.%.loc5) [concrete = constants.%int_97]
-// CHECK:STDOUT:   %.loc5_20.1: %Char = value_of_initializer %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc5 [concrete = constants.%int_97]
-// CHECK:STDOUT:   %.loc5_20.2: %Char = converted @__global_init.%.loc5, %.loc5_20.1 [concrete = constants.%int_97]
-// CHECK:STDOUT:   %c: %Char = bind_name c, %.loc5_20.2
-// CHECK:STDOUT:   name_binding_decl {
-// CHECK:STDOUT:     %nul.patt: %pattern_type.b09 = binding_pattern nul [concrete]
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc6_14: type = splice_block %Char.ref.loc6 [concrete = constants.%Char] {
-// CHECK:STDOUT:     %Core.ref.loc6: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
-// CHECK:STDOUT:     %Char.ref.loc6: type = name_ref Char, imports.%Core.Char [concrete = constants.%Char]
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %impl.elem0.loc6: %.a57 = impl_witness_access constants.%ImplicitAs.impl_witness.b70, element0 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert]
-// CHECK:STDOUT:   %bound_method.loc6: <bound method> = bound_method @__global_init.%.loc6, %impl.elem0.loc6 [concrete = constants.%Core.CharLiteral.as.ImplicitAs.impl.Convert.bound.f0f]
-// CHECK:STDOUT:   %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc6: init %Char = call %bound_method.loc6(@__global_init.%.loc6) [concrete = constants.%int_0]
-// CHECK:STDOUT:   %.loc6_22.1: %Char = value_of_initializer %Core.CharLiteral.as.ImplicitAs.impl.Convert.call.loc6 [concrete = constants.%int_0]
-// CHECK:STDOUT:   %.loc6_22.2: %Char = converted @__global_init.%.loc6, %.loc6_22.1 [concrete = constants.%int_0]
-// CHECK:STDOUT:   %nul: %Char = bind_name nul, %.loc6_22.2
-// CHECK:STDOUT:   name_binding_decl {
-// CHECK:STDOUT:     %lit.patt: %pattern_type.8c6 = binding_pattern lit [concrete]
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %.loc7_27.1: type = splice_block %.loc7_27.3 [concrete = Core.CharLiteral] {
-// CHECK:STDOUT:     %Core.ref.loc7: <namespace> = name_ref Core, imports.%Core [concrete = imports.%Core]
-// CHECK:STDOUT:     %CharLiteral.ref: %CharLiteral.type = name_ref CharLiteral, imports.%Core.CharLiteral [concrete = constants.%CharLiteral]
-// CHECK:STDOUT:     %CharLiteral.call: init type = call %CharLiteral.ref() [concrete = Core.CharLiteral]
-// CHECK:STDOUT:     %.loc7_27.2: type = value_of_initializer %CharLiteral.call [concrete = Core.CharLiteral]
-// CHECK:STDOUT:     %.loc7_27.3: type = converted %CharLiteral.call, %.loc7_27.2 [concrete = Core.CharLiteral]
-// CHECK:STDOUT:   }
-// CHECK:STDOUT:   %lit: Core.CharLiteral = bind_name lit, @__global_init.%.loc7
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: fn @__global_init() {
-// CHECK:STDOUT: !entry:
-// CHECK:STDOUT:   %.loc5: Core.CharLiteral = char_value U+0061 [concrete = constants.%.54f]
-// CHECK:STDOUT:   %.loc6: Core.CharLiteral = char_value U+0000 [concrete = constants.%.dc9]
-// CHECK:STDOUT:   %.loc7: Core.CharLiteral = char_value U+1E15 [concrete = constants.%.a81]
-// CHECK:STDOUT:   <elided>
-// CHECK:STDOUT: }
-// CHECK:STDOUT:

+ 191 - 0
toolchain/check/testdata/builtins/char/convert_checked.carbon

@@ -0,0 +1,191 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/char/convert_checked.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/char/convert_checked.carbon
+
+// --- builtin.carbon
+
+library "[[@TEST_NAME]]";
+
+fn CharLiteral() -> type = "char_literal.make_type";
+fn IntLiteral() -> type = "int_literal.make_type";
+fn UInt(n: IntLiteral()) -> type = "int.make_type_unsigned";
+
+fn ToChar(c: CharLiteral()) -> UInt(8) = "char.convert_checked";
+
+// --- fail_bad_decl.carbon
+
+library "[[@TEST_NAME]]";
+import library "builtin";
+
+// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "char.convert_checked" [InvalidBuiltinSignature]
+// CHECK:STDERR: fn ToCharBarResultU16(c: CharLiteral()) -> UInt(16) = "char.convert_checked";
+// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:
+fn ToCharBarResultU16(c: CharLiteral()) -> UInt(16) = "char.convert_checked";
+
+// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "char.convert_checked" [InvalidBuiltinSignature]
+// CHECK:STDERR: fn ToCharBadResultU9(c: CharLiteral()) -> UInt(9) = "char.convert_checked";
+// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:
+fn ToCharBadResultU9(c: CharLiteral()) -> UInt(9) = "char.convert_checked";
+
+// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "char.convert_checked" [InvalidBuiltinSignature]
+// CHECK:STDERR: fn ToCharNoParam() -> UInt(8) = "char.convert_checked";
+// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:
+fn ToCharNoParam() -> UInt(8) = "char.convert_checked";
+
+// --- fail_runtime_call.carbon
+
+library "[[@TEST_NAME]]";
+import library "builtin";
+
+let c: CharLiteral() = 'a';
+// CHECK:STDERR: fail_runtime_call.carbon:[[@LINE+8]]:18: error: non-constant call to compile-time-only function [NonConstantCallToCompTimeOnlyFunction]
+// CHECK:STDERR: let d: UInt(8) = ToChar(c);
+// CHECK:STDERR:                  ^~~~~~~~~
+// CHECK:STDERR: fail_runtime_call.carbon:[[@LINE-6]]:1: in import [InImport]
+// CHECK:STDERR: builtin.carbon:8:1: note: compile-time-only function declared here [CompTimeOnlyFunctionHere]
+// CHECK:STDERR: fn ToChar(c: CharLiteral()) -> UInt(8) = "char.convert_checked";
+// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:
+let d: UInt(8) = ToChar(c);
+
+// --- narrow.carbon
+
+library "[[@TEST_NAME]]";
+import library "builtin";
+
+//@dump-sem-ir-begin
+let a: UInt(8) = ToChar('\0');
+let b: UInt(8) = ToChar('b');
+let c: UInt(8) = ToChar('\u{7F}');
+// TODO: According to #1964, \x escapes should not be permitted in character literals.
+let d: UInt(8) = ToChar('\x7F');
+//@dump-sem-ir-end
+
+// --- fail_size_small.carbon
+
+library "[[@TEST_NAME]]";
+import library "builtin";
+
+// CHECK:STDERR: fail_size_small.carbon:[[@LINE+4]]:18: error: character value U+0080 too large for type `<builtin u8>` [CharTooLargeForType]
+// CHECK:STDERR: let c: UInt(8) = ToChar('\u{80}');
+// CHECK:STDERR:                  ^~~~~~~~~~~~~~~~
+// CHECK:STDERR:
+let c: UInt(8) = ToChar('\u{80}');
+
+// --- fail_size_multi_byte.carbon
+
+library "[[@TEST_NAME]]";
+import library "builtin";
+
+// CHECK:STDERR: fail_size_multi_byte.carbon:[[@LINE+4]]:18: error: character value U+1E15 too large for type `<builtin u8>` [CharTooLargeForType]
+// CHECK:STDERR: let c: UInt(8) = ToChar('\u{1E15}');
+// CHECK:STDERR:                  ^~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:
+let c: UInt(8) = ToChar('\u{1E15}');
+
+// CHECK:STDOUT: --- narrow.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %UInt.type: type = fn_type @UInt [concrete]
+// CHECK:STDOUT:   %UInt: %UInt.type = struct_value () [concrete]
+// CHECK:STDOUT:   %int_8: Core.IntLiteral = int_value 8 [concrete]
+// CHECK:STDOUT:   %u8.builtin: type = int_type unsigned, %int_8 [concrete]
+// CHECK:STDOUT:   %pattern_type.456: type = pattern_type %u8.builtin [concrete]
+// CHECK:STDOUT:   %ToChar.type: type = fn_type @ToChar [concrete]
+// CHECK:STDOUT:   %ToChar: %ToChar.type = struct_value () [concrete]
+// CHECK:STDOUT:   %.dc9: Core.CharLiteral = char_value U+0000 [concrete]
+// CHECK:STDOUT:   %int_0: %u8.builtin = int_value 0 [concrete]
+// CHECK:STDOUT:   %.711: Core.CharLiteral = char_value U+0062 [concrete]
+// CHECK:STDOUT:   %int_98: %u8.builtin = int_value 98 [concrete]
+// CHECK:STDOUT:   %.e28: Core.CharLiteral = char_value U+007F [concrete]
+// CHECK:STDOUT:   %int_127: %u8.builtin = int_value 127 [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Main.UInt: %UInt.type = import_ref Main//builtin, UInt, loaded [concrete = constants.%UInt]
+// CHECK:STDOUT:   %Main.ToChar: %ToChar.type = import_ref Main//builtin, ToChar, loaded [concrete = constants.%ToChar]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %a.patt: %pattern_type.456 = binding_pattern a [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc6_14.1: type = splice_block %.loc6_14.3 [concrete = constants.%u8.builtin] {
+// CHECK:STDOUT:     %UInt.ref.loc6: %UInt.type = name_ref UInt, imports.%Main.UInt [concrete = constants.%UInt]
+// CHECK:STDOUT:     %int_8.loc6: Core.IntLiteral = int_value 8 [concrete = constants.%int_8]
+// CHECK:STDOUT:     %UInt.call.loc6: init type = call %UInt.ref.loc6(%int_8.loc6) [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc6_14.2: type = value_of_initializer %UInt.call.loc6 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc6_14.3: type = converted %UInt.call.loc6, %.loc6_14.2 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc6_29.1: %u8.builtin = value_of_initializer @__global_init.%ToChar.call.loc6 [concrete = constants.%int_0]
+// CHECK:STDOUT:   %.loc6_29.2: %u8.builtin = converted @__global_init.%ToChar.call.loc6, %.loc6_29.1 [concrete = constants.%int_0]
+// CHECK:STDOUT:   %a: %u8.builtin = bind_name a, %.loc6_29.2
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %b.patt: %pattern_type.456 = binding_pattern b [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc7_14.1: type = splice_block %.loc7_14.3 [concrete = constants.%u8.builtin] {
+// CHECK:STDOUT:     %UInt.ref.loc7: %UInt.type = name_ref UInt, imports.%Main.UInt [concrete = constants.%UInt]
+// CHECK:STDOUT:     %int_8.loc7: Core.IntLiteral = int_value 8 [concrete = constants.%int_8]
+// CHECK:STDOUT:     %UInt.call.loc7: init type = call %UInt.ref.loc7(%int_8.loc7) [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc7_14.2: type = value_of_initializer %UInt.call.loc7 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc7_14.3: type = converted %UInt.call.loc7, %.loc7_14.2 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc7_28.1: %u8.builtin = value_of_initializer @__global_init.%ToChar.call.loc7 [concrete = constants.%int_98]
+// CHECK:STDOUT:   %.loc7_28.2: %u8.builtin = converted @__global_init.%ToChar.call.loc7, %.loc7_28.1 [concrete = constants.%int_98]
+// CHECK:STDOUT:   %b: %u8.builtin = bind_name b, %.loc7_28.2
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %c.patt: %pattern_type.456 = binding_pattern c [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc8_14.1: type = splice_block %.loc8_14.3 [concrete = constants.%u8.builtin] {
+// CHECK:STDOUT:     %UInt.ref.loc8: %UInt.type = name_ref UInt, imports.%Main.UInt [concrete = constants.%UInt]
+// CHECK:STDOUT:     %int_8.loc8: Core.IntLiteral = int_value 8 [concrete = constants.%int_8]
+// CHECK:STDOUT:     %UInt.call.loc8: init type = call %UInt.ref.loc8(%int_8.loc8) [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc8_14.2: type = value_of_initializer %UInt.call.loc8 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc8_14.3: type = converted %UInt.call.loc8, %.loc8_14.2 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc8_33.1: %u8.builtin = value_of_initializer @__global_init.%ToChar.call.loc8 [concrete = constants.%int_127]
+// CHECK:STDOUT:   %.loc8_33.2: %u8.builtin = converted @__global_init.%ToChar.call.loc8, %.loc8_33.1 [concrete = constants.%int_127]
+// CHECK:STDOUT:   %c: %u8.builtin = bind_name c, %.loc8_33.2
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %d.patt: %pattern_type.456 = binding_pattern d [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc10_14.1: type = splice_block %.loc10_14.3 [concrete = constants.%u8.builtin] {
+// CHECK:STDOUT:     %UInt.ref.loc10: %UInt.type = name_ref UInt, imports.%Main.UInt [concrete = constants.%UInt]
+// CHECK:STDOUT:     %int_8.loc10: Core.IntLiteral = int_value 8 [concrete = constants.%int_8]
+// CHECK:STDOUT:     %UInt.call.loc10: init type = call %UInt.ref.loc10(%int_8.loc10) [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc10_14.2: type = value_of_initializer %UInt.call.loc10 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:     %.loc10_14.3: type = converted %UInt.call.loc10, %.loc10_14.2 [concrete = constants.%u8.builtin]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %.loc10_31.1: %u8.builtin = value_of_initializer @__global_init.%ToChar.call.loc10 [concrete = constants.%int_127]
+// CHECK:STDOUT:   %.loc10_31.2: %u8.builtin = converted @__global_init.%ToChar.call.loc10, %.loc10_31.1 [concrete = constants.%int_127]
+// CHECK:STDOUT:   %d: %u8.builtin = bind_name d, %.loc10_31.2
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @__global_init() {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %ToChar.ref.loc6: %ToChar.type = name_ref ToChar, imports.%Main.ToChar [concrete = constants.%ToChar]
+// CHECK:STDOUT:   %.loc6: Core.CharLiteral = char_value U+0000 [concrete = constants.%.dc9]
+// CHECK:STDOUT:   %ToChar.call.loc6: init %u8.builtin = call %ToChar.ref.loc6(%.loc6) [concrete = constants.%int_0]
+// CHECK:STDOUT:   %ToChar.ref.loc7: %ToChar.type = name_ref ToChar, imports.%Main.ToChar [concrete = constants.%ToChar]
+// CHECK:STDOUT:   %.loc7: Core.CharLiteral = char_value U+0062 [concrete = constants.%.711]
+// CHECK:STDOUT:   %ToChar.call.loc7: init %u8.builtin = call %ToChar.ref.loc7(%.loc7) [concrete = constants.%int_98]
+// CHECK:STDOUT:   %ToChar.ref.loc8: %ToChar.type = name_ref ToChar, imports.%Main.ToChar [concrete = constants.%ToChar]
+// CHECK:STDOUT:   %.loc8: Core.CharLiteral = char_value U+007F [concrete = constants.%.e28]
+// CHECK:STDOUT:   %ToChar.call.loc8: init %u8.builtin = call %ToChar.ref.loc8(%.loc8) [concrete = constants.%int_127]
+// CHECK:STDOUT:   %ToChar.ref.loc10: %ToChar.type = name_ref ToChar, imports.%Main.ToChar [concrete = constants.%ToChar]
+// CHECK:STDOUT:   %.loc10: Core.CharLiteral = char_value U+007F [concrete = constants.%.e28]
+// CHECK:STDOUT:   %ToChar.call.loc10: init %u8.builtin = call %ToChar.ref.loc10(%.loc10) [concrete = constants.%int_127]
+// CHECK:STDOUT:   <elided>
+// CHECK:STDOUT: }
+// CHECK:STDOUT:

+ 95 - 0
toolchain/check/testdata/builtins/char_literal/make_type.carbon

@@ -0,0 +1,95 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/char_literal/make_type.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/char_literal/make_type.carbon
+
+// --- types.carbon
+
+library "[[@TEST_NAME]]";
+
+fn CharLiteral() -> type = "char_literal.make_type";
+
+// --- use_types.carbon
+
+library "[[@TEST_NAME]]";
+
+import library "types";
+
+//@dump-sem-ir-begin
+var ascii_x: CharLiteral() = 'x';
+var not_7_bit: CharLiteral() = '\u{80}';
+var not_8_bit: CharLiteral() = '\u{1E15}';
+//@dump-sem-ir-end
+
+// CHECK:STDOUT: --- use_types.carbon
+// CHECK:STDOUT:
+// CHECK:STDOUT: constants {
+// CHECK:STDOUT:   %CharLiteral.type: type = fn_type @CharLiteral [concrete]
+// CHECK:STDOUT:   %CharLiteral: %CharLiteral.type = struct_value () [concrete]
+// CHECK:STDOUT:   %pattern_type.8c6: type = pattern_type Core.CharLiteral [concrete]
+// CHECK:STDOUT:   %.4ac: Core.CharLiteral = char_value U+0078 [concrete]
+// CHECK:STDOUT:   %.ae7: Core.CharLiteral = char_value U+0080 [concrete]
+// CHECK:STDOUT:   %.a81: Core.CharLiteral = char_value U+1E15 [concrete]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: imports {
+// CHECK:STDOUT:   %Main.CharLiteral: %CharLiteral.type = import_ref Main//types, CharLiteral, loaded [concrete = constants.%CharLiteral]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: file {
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %ascii_x.patt: %pattern_type.8c6 = binding_pattern ascii_x [concrete]
+// CHECK:STDOUT:     %ascii_x.var_patt: %pattern_type.8c6 = var_pattern %ascii_x.patt [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %ascii_x.var: ref Core.CharLiteral = var %ascii_x.var_patt [concrete]
+// CHECK:STDOUT:   %.loc7_26.1: type = splice_block %.loc7_26.3 [concrete = Core.CharLiteral] {
+// CHECK:STDOUT:     %CharLiteral.ref.loc7: %CharLiteral.type = name_ref CharLiteral, imports.%Main.CharLiteral [concrete = constants.%CharLiteral]
+// CHECK:STDOUT:     %CharLiteral.call.loc7: init type = call %CharLiteral.ref.loc7() [concrete = Core.CharLiteral]
+// CHECK:STDOUT:     %.loc7_26.2: type = value_of_initializer %CharLiteral.call.loc7 [concrete = Core.CharLiteral]
+// CHECK:STDOUT:     %.loc7_26.3: type = converted %CharLiteral.call.loc7, %.loc7_26.2 [concrete = Core.CharLiteral]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %ascii_x: ref Core.CharLiteral = bind_name ascii_x, %ascii_x.var [concrete = %ascii_x.var]
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %not_7_bit.patt: %pattern_type.8c6 = binding_pattern not_7_bit [concrete]
+// CHECK:STDOUT:     %not_7_bit.var_patt: %pattern_type.8c6 = var_pattern %not_7_bit.patt [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %not_7_bit.var: ref Core.CharLiteral = var %not_7_bit.var_patt [concrete]
+// CHECK:STDOUT:   %.loc8_28.1: type = splice_block %.loc8_28.3 [concrete = Core.CharLiteral] {
+// CHECK:STDOUT:     %CharLiteral.ref.loc8: %CharLiteral.type = name_ref CharLiteral, imports.%Main.CharLiteral [concrete = constants.%CharLiteral]
+// CHECK:STDOUT:     %CharLiteral.call.loc8: init type = call %CharLiteral.ref.loc8() [concrete = Core.CharLiteral]
+// CHECK:STDOUT:     %.loc8_28.2: type = value_of_initializer %CharLiteral.call.loc8 [concrete = Core.CharLiteral]
+// CHECK:STDOUT:     %.loc8_28.3: type = converted %CharLiteral.call.loc8, %.loc8_28.2 [concrete = Core.CharLiteral]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %not_7_bit: ref Core.CharLiteral = bind_name not_7_bit, %not_7_bit.var [concrete = %not_7_bit.var]
+// CHECK:STDOUT:   name_binding_decl {
+// CHECK:STDOUT:     %not_8_bit.patt: %pattern_type.8c6 = binding_pattern not_8_bit [concrete]
+// CHECK:STDOUT:     %not_8_bit.var_patt: %pattern_type.8c6 = var_pattern %not_8_bit.patt [concrete]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %not_8_bit.var: ref Core.CharLiteral = var %not_8_bit.var_patt [concrete]
+// CHECK:STDOUT:   %.loc9_28.1: type = splice_block %.loc9_28.3 [concrete = Core.CharLiteral] {
+// CHECK:STDOUT:     %CharLiteral.ref.loc9: %CharLiteral.type = name_ref CharLiteral, imports.%Main.CharLiteral [concrete = constants.%CharLiteral]
+// CHECK:STDOUT:     %CharLiteral.call.loc9: init type = call %CharLiteral.ref.loc9() [concrete = Core.CharLiteral]
+// CHECK:STDOUT:     %.loc9_28.2: type = value_of_initializer %CharLiteral.call.loc9 [concrete = Core.CharLiteral]
+// CHECK:STDOUT:     %.loc9_28.3: type = converted %CharLiteral.call.loc9, %.loc9_28.2 [concrete = Core.CharLiteral]
+// CHECK:STDOUT:   }
+// CHECK:STDOUT:   %not_8_bit: ref Core.CharLiteral = bind_name not_8_bit, %not_8_bit.var [concrete = %not_8_bit.var]
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: fn @__global_init() {
+// CHECK:STDOUT: !entry:
+// CHECK:STDOUT:   %.loc7: Core.CharLiteral = char_value U+0078 [concrete = constants.%.4ac]
+// CHECK:STDOUT:   assign file.%ascii_x.var, %.loc7
+// CHECK:STDOUT:   %.loc8: Core.CharLiteral = char_value U+0080 [concrete = constants.%.ae7]
+// CHECK:STDOUT:   assign file.%not_7_bit.var, %.loc8
+// CHECK:STDOUT:   %.loc9: Core.CharLiteral = char_value U+1E15 [concrete = constants.%.a81]
+// CHECK:STDOUT:   assign file.%not_8_bit.var, %.loc9
+// CHECK:STDOUT:   <elided>
+// CHECK:STDOUT: }
+// CHECK:STDOUT: