Files
carbon-lang/toolchain/check/testdata/builtins/float/add.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

93 lines
4.0 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/primitives.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/float/add.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/float/add.carbon
// --- float_add.carbon
library "[[@TEST_NAME]]";
fn Add(a: f64, b: f64) -> f64 = "float.add";
fn RuntimeCallIsValid(a: f64, b: f64) -> f64 {
//@dump-sem-ir-begin
return Add(a, b);
//@dump-sem-ir-end
}
var x: f64 = Add(2.2, 2.3);
// --- fail_bad_decl.carbon
library "[[@TEST_NAME]]";
// CHECK:STDERR: ╭─┤ fail_bad_decl.carbon:[[@LINE+7]]:1
// CHECK:STDERR: -> │ fn TooFew(a: f64) -> f64 = "float.add";
// CHECK:STDERR: · ━━━━━━━━━━━━━┳━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: invalid signature for builtin function "float.add"
// CHECK:STDERR: · ┃ [InvalidBuiltinSignature]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn TooFew(a: f64) -> f64 = "float.add";
// CHECK:STDERR: ╭─┤ fail_bad_decl.carbon:[[@LINE+7]]:1
// CHECK:STDERR: -> │ fn TooMany(a: f64, b: f64, c: f64) -> f64 = "float.add";
// CHECK:STDERR: · ━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: invalid signature for builtin function "float.add"
// CHECK:STDERR: · ┃ [InvalidBuiltinSignature]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn TooMany(a: f64, b: f64, c: f64) -> f64 = "float.add";
// CHECK:STDERR: ╭─┤ fail_bad_decl.carbon:[[@LINE+7]]:1
// CHECK:STDERR: -> │ fn BadReturnType(a: f64, b: f64) -> bool = "float.add";
// CHECK:STDERR: · ━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: invalid signature for builtin function "float.add"
// CHECK:STDERR: · ┃ [InvalidBuiltinSignature]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn BadReturnType(a: f64, b: f64) -> bool = "float.add";
fn JustRight(a: f64, b: f64) -> f64 = "float.add";
fn RuntimeCallIsValidTooFew(a: f64) -> f64 {
return TooFew(a);
}
fn RuntimeCallIsValidTooMany(a: f64, b: f64, c: f64) -> f64 {
return TooMany(a, b, c);
}
fn RuntimeCallIsValidBadReturnType(a: f64, b: f64) -> bool {
return BadReturnType(a, b);
}
// CHECK:STDOUT: --- float_add.carbon = $float_add
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
// CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
// CHECK:STDOUT: %f64.761: type = class_type @Float, @Float(%int_64) [concrete]
// CHECK:STDOUT: %Add.type: type = fn_type @Add [concrete]
// CHECK:STDOUT: %Add: %Add.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @RuntimeCallIsValid(%a.param: %f64.761, %b.param: %f64.761) -> out %return.param: %f64.761 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Add.ref: %Add.type = name_ref Add, file.%Add.decl [concrete = constants.%Add]
// CHECK:STDOUT: %a.ref: %f64.761 = name_ref a, %a
// CHECK:STDOUT: %b.ref: %f64.761 = name_ref b, %b
// CHECK:STDOUT: %Add.call: init %f64.761 = call %Add.ref(%a.ref, %b.ref)
// CHECK:STDOUT: return %Add.call
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT: