Files
carbon-lang/toolchain/check/testdata/index/expr_category.carbon
T
Jon Ross-Perkins 55300d1ebb Switch type literals to use builtin functions. (#3978)
Modifies the core package and literal handling to use factory functions
for standard type literals.

Updates function/builtin/import.carbon to stop depending on the prelude,
since it would list all the impls in the core file. Updates
alias/builtins.carbon to be failing (the type values cannot be aliased).
2024-05-23 16:00:08 +00:00

184 lines
11 KiB
Plaintext

// 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
//
// AUTOUPDATE
fn F() -> [i32; 3];
fn G(b: [i32; 3]) {
var a: [i32; 3] = (1, 2, 3);
// Indexing a durable array reference gives a durable reference.
var pa: i32* = &a[0];
a[0] = 4;
}
fn ValueBinding(b: [i32; 3]) {
var a: [i32; 3] = (1, 2, 3);
// Index but don't do anything else so we can check that a value binding is
// produced when appropriate.
a[0];
b[0];
F()[0];
}
// CHECK:STDOUT: --- expr_category.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
// CHECK:STDOUT: %.1: type = tuple_type () [template]
// CHECK:STDOUT: %struct.1: Int32 = struct_value () [template]
// CHECK:STDOUT: %.2: i32 = int_literal 3 [template]
// CHECK:STDOUT: %.3: type = array_type %.2, i32 [template]
// CHECK:STDOUT: %F: type = fn_type @F [template]
// CHECK:STDOUT: %struct.2: F = struct_value () [template]
// CHECK:STDOUT: %G: type = fn_type @G [template]
// CHECK:STDOUT: %struct.3: G = struct_value () [template]
// CHECK:STDOUT: %.4: type = ptr_type [i32; 3] [template]
// CHECK:STDOUT: %.5: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.6: i32 = int_literal 2 [template]
// CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
// CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
// CHECK:STDOUT: %array: [i32; 3] = tuple_value (%.5, %.6, %.2) [template]
// CHECK:STDOUT: %.9: type = ptr_type i32 [template]
// CHECK:STDOUT: %.10: i32 = int_literal 4 [template]
// CHECK:STDOUT: %ValueBinding: type = fn_type @ValueBinding [template]
// CHECK:STDOUT: %struct.4: ValueBinding = struct_value () [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Core = %Core
// CHECK:STDOUT: .F = %F.decl
// CHECK:STDOUT: .G = %G.decl
// CHECK:STDOUT: .ValueBinding = %ValueBinding.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %import_ref.1: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.2] {
// CHECK:STDOUT: %int.make_type_32.loc7: init type = call constants.%struct.1() [template = i32]
// CHECK:STDOUT: %.loc7_17: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc7_12.1: type = value_of_initializer %int.make_type_32.loc7 [template = i32]
// CHECK:STDOUT: %.loc7_12.2: type = converted %int.make_type_32.loc7, %.loc7_12.1 [template = i32]
// CHECK:STDOUT: %.loc7_18: type = array_type %.loc7_17, i32 [template = constants.%.3]
// CHECK:STDOUT: @F.%return: ref [i32; 3] = var <return slot>
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.2: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.3] {
// CHECK:STDOUT: %int.make_type_32.loc9: init type = call constants.%struct.1() [template = i32]
// CHECK:STDOUT: %.loc9_15: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc9_10.1: type = value_of_initializer %int.make_type_32.loc9 [template = i32]
// CHECK:STDOUT: %.loc9_10.2: type = converted %int.make_type_32.loc9, %.loc9_10.1 [template = i32]
// CHECK:STDOUT: %.loc9_16: type = array_type %.loc9_15, i32 [template = constants.%.3]
// CHECK:STDOUT: %b.loc9_6.1: [i32; 3] = param b
// CHECK:STDOUT: @G.%b: [i32; 3] = bind_name b, %b.loc9_6.1
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.3: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.4: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %import_ref.5: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
// CHECK:STDOUT: %ValueBinding.decl: ValueBinding = fn_decl @ValueBinding [template = constants.%struct.4] {
// CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%struct.1() [template = i32]
// CHECK:STDOUT: %.loc17_26: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc17_21.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
// CHECK:STDOUT: %.loc17_21.2: type = converted %int.make_type_32.loc17, %.loc17_21.1 [template = i32]
// CHECK:STDOUT: %.loc17_27: type = array_type %.loc17_26, i32 [template = constants.%.3]
// CHECK:STDOUT: %b.loc17_17.1: [i32; 3] = param b
// CHECK:STDOUT: @ValueBinding.%b: [i32; 3] = bind_name b, %b.loc17_17.1
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.6: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() -> [i32; 3];
// CHECK:STDOUT:
// CHECK:STDOUT: fn @G(%b: [i32; 3]) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %int.make_type_32.loc10: init type = call constants.%struct.1() [template = i32]
// CHECK:STDOUT: %.loc10_16: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc10_11.1: type = value_of_initializer %int.make_type_32.loc10 [template = i32]
// CHECK:STDOUT: %.loc10_11.2: type = converted %int.make_type_32.loc10, %.loc10_11.1 [template = i32]
// CHECK:STDOUT: %.loc10_17: type = array_type %.loc10_16, i32 [template = constants.%.3]
// CHECK:STDOUT: %a.var: ref [i32; 3] = var a
// CHECK:STDOUT: %a: ref [i32; 3] = bind_name a, %a.var
// CHECK:STDOUT: %.loc10_22: i32 = int_literal 1 [template = constants.%.5]
// CHECK:STDOUT: %.loc10_25: i32 = int_literal 2 [template = constants.%.6]
// CHECK:STDOUT: %.loc10_28: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc10_29.1: (i32, i32, i32) = tuple_literal (%.loc10_22, %.loc10_25, %.loc10_28)
// CHECK:STDOUT: %.loc10_29.2: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc10_29.3: ref i32 = array_index %a.var, %.loc10_29.2
// CHECK:STDOUT: %.loc10_29.4: init i32 = initialize_from %.loc10_22 to %.loc10_29.3 [template = constants.%.5]
// CHECK:STDOUT: %.loc10_29.5: i32 = int_literal 1 [template = constants.%.5]
// CHECK:STDOUT: %.loc10_29.6: ref i32 = array_index %a.var, %.loc10_29.5
// CHECK:STDOUT: %.loc10_29.7: init i32 = initialize_from %.loc10_25 to %.loc10_29.6 [template = constants.%.6]
// CHECK:STDOUT: %.loc10_29.8: i32 = int_literal 2 [template = constants.%.6]
// CHECK:STDOUT: %.loc10_29.9: ref i32 = array_index %a.var, %.loc10_29.8
// CHECK:STDOUT: %.loc10_29.10: init i32 = initialize_from %.loc10_28 to %.loc10_29.9 [template = constants.%.2]
// CHECK:STDOUT: %.loc10_29.11: init [i32; 3] = array_init (%.loc10_29.4, %.loc10_29.7, %.loc10_29.10) to %a.var [template = constants.%array]
// CHECK:STDOUT: %.loc10_30: init [i32; 3] = converted %.loc10_29.1, %.loc10_29.11 [template = constants.%array]
// CHECK:STDOUT: assign %a.var, %.loc10_30
// CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%struct.1() [template = i32]
// CHECK:STDOUT: %.loc13_14.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
// CHECK:STDOUT: %.loc13_14.2: type = converted %int.make_type_32.loc13, %.loc13_14.1 [template = i32]
// CHECK:STDOUT: %.loc13_14.3: type = ptr_type i32 [template = constants.%.9]
// CHECK:STDOUT: %pa.var: ref i32* = var pa
// CHECK:STDOUT: %pa: ref i32* = bind_name pa, %pa.var
// CHECK:STDOUT: %a.ref.loc13: ref [i32; 3] = name_ref a, %a
// CHECK:STDOUT: %.loc13_21: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc13_22: ref i32 = array_index %a.ref.loc13, %.loc13_21
// CHECK:STDOUT: %.loc13_18: i32* = addr_of %.loc13_22
// CHECK:STDOUT: assign %pa.var, %.loc13_18
// CHECK:STDOUT: %a.ref.loc14: ref [i32; 3] = name_ref a, %a
// CHECK:STDOUT: %.loc14_5: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc14_6: ref i32 = array_index %a.ref.loc14, %.loc14_5
// CHECK:STDOUT: %.loc14_10: i32 = int_literal 4 [template = constants.%.10]
// CHECK:STDOUT: assign %.loc14_6, %.loc14_10
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @ValueBinding(%b: [i32; 3]) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %int.make_type_32: init type = call constants.%struct.1() [template = i32]
// CHECK:STDOUT: %.loc18_16: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc18_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
// CHECK:STDOUT: %.loc18_11.2: type = converted %int.make_type_32, %.loc18_11.1 [template = i32]
// CHECK:STDOUT: %.loc18_17: type = array_type %.loc18_16, i32 [template = constants.%.3]
// CHECK:STDOUT: %a.var: ref [i32; 3] = var a
// CHECK:STDOUT: %a: ref [i32; 3] = bind_name a, %a.var
// CHECK:STDOUT: %.loc18_22: i32 = int_literal 1 [template = constants.%.5]
// CHECK:STDOUT: %.loc18_25: i32 = int_literal 2 [template = constants.%.6]
// CHECK:STDOUT: %.loc18_28: i32 = int_literal 3 [template = constants.%.2]
// CHECK:STDOUT: %.loc18_29.1: (i32, i32, i32) = tuple_literal (%.loc18_22, %.loc18_25, %.loc18_28)
// CHECK:STDOUT: %.loc18_29.2: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc18_29.3: ref i32 = array_index %a.var, %.loc18_29.2
// CHECK:STDOUT: %.loc18_29.4: init i32 = initialize_from %.loc18_22 to %.loc18_29.3 [template = constants.%.5]
// CHECK:STDOUT: %.loc18_29.5: i32 = int_literal 1 [template = constants.%.5]
// CHECK:STDOUT: %.loc18_29.6: ref i32 = array_index %a.var, %.loc18_29.5
// CHECK:STDOUT: %.loc18_29.7: init i32 = initialize_from %.loc18_25 to %.loc18_29.6 [template = constants.%.6]
// CHECK:STDOUT: %.loc18_29.8: i32 = int_literal 2 [template = constants.%.6]
// CHECK:STDOUT: %.loc18_29.9: ref i32 = array_index %a.var, %.loc18_29.8
// CHECK:STDOUT: %.loc18_29.10: init i32 = initialize_from %.loc18_28 to %.loc18_29.9 [template = constants.%.2]
// CHECK:STDOUT: %.loc18_29.11: init [i32; 3] = array_init (%.loc18_29.4, %.loc18_29.7, %.loc18_29.10) to %a.var [template = constants.%array]
// CHECK:STDOUT: %.loc18_30: init [i32; 3] = converted %.loc18_29.1, %.loc18_29.11 [template = constants.%array]
// CHECK:STDOUT: assign %a.var, %.loc18_30
// CHECK:STDOUT: %a.ref: ref [i32; 3] = name_ref a, %a
// CHECK:STDOUT: %.loc22_5: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc22_6: ref i32 = array_index %a.ref, %.loc22_5
// CHECK:STDOUT: %b.ref: [i32; 3] = name_ref b, %b
// CHECK:STDOUT: %.loc23_5: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc23_6.1: ref [i32; 3] = value_as_ref %b.ref
// CHECK:STDOUT: %.loc23_6.2: ref i32 = array_index %.loc23_6.1, %.loc23_5
// CHECK:STDOUT: %.loc23_6.3: i32 = bind_value %.loc23_6.2
// CHECK:STDOUT: %F.ref: F = name_ref F, file.%F.decl [template = constants.%struct.2]
// CHECK:STDOUT: %.loc24_4.1: ref [i32; 3] = temporary_storage
// CHECK:STDOUT: %F.call: init [i32; 3] = call %F.ref() to %.loc24_4.1
// CHECK:STDOUT: %.loc24_7: i32 = int_literal 0 [template = constants.%.8]
// CHECK:STDOUT: %.loc24_4.2: ref [i32; 3] = temporary %.loc24_4.1, %F.call
// CHECK:STDOUT: %.loc24_8.1: ref i32 = array_index %.loc24_4.2, %.loc24_7
// CHECK:STDOUT: %.loc24_8.2: i32 = bind_value %.loc24_8.1
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: