Files
carbon-lang/toolchain/check/testdata/pointer/convert_qualifiers.carbon
T
Geoff RomerandDana Jansens e67b6db910 Give files shorthand names in textual SemIR (#8104)
Shorthand names are intended to be used in the textual format of
references to instructions in another IR (which can't happen now, but
will be possible in a forthcoming PR). The shorthand name uses the file
name (minus the `.carbon` suffix) as a base, and if that base name is
ambiguous within the compilation, it is given a numerical suffix `.N`,
just like other textual IR names. Shorthand names are prefixed with `$`
in the textual format, to distinguish them from inst and scope names.

For example, a file `foo/bar.carbon` has the shorthand name `$bar`, and
an instruction `@baz.%qux` in that file can be referenced from another
file as `$bar.@baz.%qux`.

This PR adds `toolchain/check/testdata/basics/file_name.carbon` to test
this behavior. All other test changes are just applying this change to
the existing textual SemIR dumps.

---------

Co-authored-by: Dana Jansens <danakj@orodu.net>
2026-11-12 23:34:32 +00:00

237 lines
12 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
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/pointer/convert_qualifiers.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/convert_qualifiers.carbon
// --- same_or_added_qualifiers.carbon
library "[[@TEST_NAME]]";
class X {}
fn TakeConst(p: const X*);
fn TakeNonConst(p: X*);
fn NonConst(p: X*) {
//@dump-sem-ir-begin
TakeNonConst(p);
TakeConst(p);
//@dump-sem-ir-end
}
fn Const(p: const X*) {
//@dump-sem-ir-begin
TakeConst(p);
//@dump-sem-ir-end
}
// Same thing, but the pointee type happens to be a pointer.
fn TakeConstConst(p: const (const X*)*);
fn NonConstConst(p: const X**) {
//@dump-sem-ir-begin
TakeConstConst(p);
//@dump-sem-ir-end
}
// --- fail_removed_qualifiers.carbon
library "[[@TEST_NAME]]";
class X {}
fn TakeNonConst(p: X*);
// CHECK:STDERR: ╭─┤ fail_removed_qualifiers.carbon:[[@LINE+16]]:38
// CHECK:STDERR: │ fn TakeNonConst(p: X*);
// CHECK:STDERR: · ──┬──
// CHECK:STDERR: · ╰──┤ initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ fn Const(p: const X*) { TakeNonConst(p); }
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert
// CHECK:STDERR: · │ ┃ expression of type `const X*`
// CHECK:STDERR: · │ ┃ to `X*`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `const X*` does not implement
// CHECK:STDERR: · │ interface `Core.ImplicitAs(X*)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn Const(p: const X*) { TakeNonConst(p); }
// --- fail_todo_nested_qualifiers.carbon
library "[[@TEST_NAME]]";
class X {}
fn TakeConstConst(p: const (const X*)*);
// TODO: We should allow these conversions.
fn NonConstNonConst(p: X**) {
//@dump-sem-ir-begin
// CHECK:STDERR: ╭─┤ fail_todo_nested_qualifiers.carbon:[[@LINE+16]]:18
// CHECK:STDERR: │ fn TakeConstConst(p: const (const X*)*);
// CHECK:STDERR: · ──────────┬─────────
// CHECK:STDERR: · ╰──┤ initializing function parameter
// CHECK:STDERR: · │ [InCallToFunctionParam]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ TakeConstConst(p);
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `X**`
// CHECK:STDERR: · │ ┃ to `const (const X*)*`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `X**` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(const (const X*)*)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
TakeConstConst(p);
//@dump-sem-ir-end
}
fn ConstNonConst(p: const (X*)*) {
//@dump-sem-ir-begin
// CHECK:STDERR: ╭─┤ fail_todo_nested_qualifiers.carbon:[[@LINE+16]]:18
// CHECK:STDERR: │ fn TakeConstConst(p: const (const X*)*);
// CHECK:STDERR: · ──────────┬─────────
// CHECK:STDERR: · ╰──┤ initializing function parameter
// CHECK:STDERR: · │ [InCallToFunctionParam]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ TakeConstConst(p);
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `const (X*)*` to `const (const X*)*`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `const (X*)*` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(const (const X*)*)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
TakeConstConst(p);
//@dump-sem-ir-end
}
// --- fail_nested_added_qualifiers.carbon
library "[[@TEST_NAME]]";
class X {}
fn TakeNonConstConst(p: (const X*)*);
// CHECK:STDERR: ╭─┤ fail_nested_added_qualifiers.carbon:[[@LINE+18]]:49
// CHECK:STDERR: │ fn TakeNonConstConst(p: (const X*)*);
// CHECK:STDERR: · ───────┬──────
// CHECK:STDERR: · ╰──┤ initializing function parameter
// CHECK:STDERR: · │ [InCallToFunctionParam]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
// CHECK:STDERR: · ┳
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly
// CHECK:STDERR: · │ ┃ convert expression
// CHECK:STDERR: · │ ┃ of type `X**` to
// CHECK:STDERR: · │ ┃ `const X**`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╭───────────────────────────────────────────────╯
// CHECK:STDERR: · │ type `X**` does not implement interface `Core.ImplicitAs(const X**)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
// CHECK:STDOUT: --- same_or_added_qualifiers.carbon = $same_or_added_qualifiers
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %X: type = class_type @X [concrete]
// CHECK:STDOUT: %const.435: type = const_type %X [concrete]
// CHECK:STDOUT: %ptr.faf: type = ptr_type %const.435 [concrete]
// CHECK:STDOUT: %TakeConst.type: type = fn_type @TakeConst [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %TakeConst: %TakeConst.type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.db8: type = ptr_type %X [concrete]
// CHECK:STDOUT: %TakeNonConst.type: type = fn_type @TakeNonConst [concrete]
// CHECK:STDOUT: %TakeNonConst: %TakeNonConst.type = struct_value () [concrete]
// CHECK:STDOUT: %const.95a: type = const_type %ptr.faf [concrete]
// CHECK:STDOUT: %ptr.b53: type = ptr_type %const.95a [concrete]
// CHECK:STDOUT: %TakeConstConst.type: type = fn_type @TakeConstConst [concrete]
// CHECK:STDOUT: %TakeConstConst: %TakeConstConst.type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.845: type = ptr_type %ptr.faf [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @NonConst(%p.param: %ptr.db8) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeNonConst.ref: %TakeNonConst.type = name_ref TakeNonConst, file.%TakeNonConst.decl [concrete = constants.%TakeNonConst]
// CHECK:STDOUT: %p.ref.loc11: %ptr.db8 = name_ref p, %p
// CHECK:STDOUT: %TakeNonConst.call: init %empty_tuple.type = call %TakeNonConst.ref(%p.ref.loc11)
// CHECK:STDOUT: %TakeConst.ref: %TakeConst.type = name_ref TakeConst, file.%TakeConst.decl [concrete = constants.%TakeConst]
// CHECK:STDOUT: %p.ref.loc12: %ptr.db8 = name_ref p, %p
// CHECK:STDOUT: %.loc12_13.1: %ptr.faf = as_compatible %p.ref.loc12
// CHECK:STDOUT: %.loc12_13.2: %ptr.faf = converted %p.ref.loc12, %.loc12_13.1
// CHECK:STDOUT: %TakeConst.call: init %empty_tuple.type = call %TakeConst.ref(%.loc12_13.2)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Const(%p.param: %ptr.faf) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeConst.ref: %TakeConst.type = name_ref TakeConst, file.%TakeConst.decl [concrete = constants.%TakeConst]
// CHECK:STDOUT: %p.ref: %ptr.faf = name_ref p, %p
// CHECK:STDOUT: %TakeConst.call: init %empty_tuple.type = call %TakeConst.ref(%p.ref)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @NonConstConst(%p.param: %ptr.845) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeConstConst.ref: %TakeConstConst.type = name_ref TakeConstConst, file.%TakeConstConst.decl [concrete = constants.%TakeConstConst]
// CHECK:STDOUT: %p.ref: %ptr.845 = name_ref p, %p
// CHECK:STDOUT: %.loc25_18.1: %ptr.b53 = as_compatible %p.ref
// CHECK:STDOUT: %.loc25_18.2: %ptr.b53 = converted %p.ref, %.loc25_18.1
// CHECK:STDOUT: %TakeConstConst.call: init %empty_tuple.type = call %TakeConstConst.ref(%.loc25_18.2)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_todo_nested_qualifiers.carbon = $fail_todo_nested_qualifiers
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %X: type = class_type @X [concrete]
// CHECK:STDOUT: %const.435: type = const_type %X [concrete]
// CHECK:STDOUT: %ptr.faf: type = ptr_type %const.435 [concrete]
// CHECK:STDOUT: %const.95a: type = const_type %ptr.faf [concrete]
// CHECK:STDOUT: %ptr.b53: type = ptr_type %const.95a [concrete]
// CHECK:STDOUT: %TakeConstConst.type: type = fn_type @TakeConstConst [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %TakeConstConst: %TakeConstConst.type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.db8: type = ptr_type %X [concrete]
// CHECK:STDOUT: %ptr.9ae: type = ptr_type %ptr.db8 [concrete]
// CHECK:STDOUT: %const.d43: type = const_type %ptr.db8 [concrete]
// CHECK:STDOUT: %ptr.060: type = ptr_type %const.d43 [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @NonConstNonConst(%p.param: %ptr.9ae) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeConstConst.ref: %TakeConstConst.type = name_ref TakeConstConst, file.%TakeConstConst.decl [concrete = constants.%TakeConstConst]
// CHECK:STDOUT: %p.ref: %ptr.9ae = name_ref p, %p
// CHECK:STDOUT: %.loc28: %ptr.b53 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %TakeConstConst.call: init %empty_tuple.type = call %TakeConstConst.ref(<error>)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @ConstNonConst(%p.param: %ptr.060) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeConstConst.ref: %TakeConstConst.type = name_ref TakeConstConst, file.%TakeConstConst.decl [concrete = constants.%TakeConstConst]
// CHECK:STDOUT: %p.ref: %ptr.060 = name_ref p, %p
// CHECK:STDOUT: %.loc50: %ptr.b53 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %TakeConstConst.call: init %empty_tuple.type = call %TakeConstConst.ref(<error>)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT: