Files
carbon-lang/toolchain/check/testdata/builtins/pointer/is_null.carbon
T
Richard Smith 05cc09daca Fix cross-package signature mismatches. (#7232)
Fixes link failures when referencing a symbol involving a fingerprint
from a different package.

Previously we included the `Namespace`'s `import_id` as part of its
fingerprint, which caused local and imported namespaces to get different
fingerprints. We now store the `import_id` on the `NameScope` instead of
on the `Namespace` inst to avoid this problem.

Also, when we reach a package-level `NameScopeId`, consistently
fingerprint it as a (package name, library name) pair. Previously the
fingerprinting depended on whether it was imported or not, as an
imported `NameScopeId` had a parent scope (the current package). We need
to include the library name here so that private entities with the same
name in different libraries have different fingerprints.
2026-05-21 00:02:29 +00:00

266 lines
16 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/bool.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/pointer/is_null.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/pointer/is_null.carbon
// --- call_exact.carbon
library "[[@TEST_NAME]]";
class C {}
fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
fn IsNullEmptyStruct(p: MakeUnformed({}*)) -> bool = "pointer.is_null";
fn IsNullC(p: MakeUnformed(C*)) -> bool = "pointer.is_null";
//@dump-sem-ir-begin
fn TestEmptyStruct(s: MakeUnformed({}*)) -> bool {
return IsNullEmptyStruct(s);
}
fn TestC(c: MakeUnformed(C*)) -> bool {
return IsNullC(c);
}
//@dump-sem-ir-end
// --- call_generic.carbon
library "[[@TEST_NAME]]";
fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
fn IsNull[T:! type](p: MakeUnformed(T*)) -> bool = "pointer.is_null";
class C {}
//@dump-sem-ir-begin
fn TestEmptyStruct(s: MakeUnformed({}*)) -> bool {
return IsNull(s);
}
fn TestC(c: MakeUnformed(C*)) -> bool {
return IsNull(c);
}
//@dump-sem-ir-end
// --- fail_bad_decl.carbon
library "[[@TEST_NAME]]";
fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "pointer.is_null" [InvalidBuiltinSignature]
// CHECK:STDERR: fn NoParam() -> bool = "pointer.is_null";
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
fn NoParam() -> bool = "pointer.is_null";
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "pointer.is_null" [InvalidBuiltinSignature]
// CHECK:STDERR: fn NoRetType(p: MakeUnformed({}*)) = "pointer.is_null";
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
fn NoRetType(p: MakeUnformed({}*)) = "pointer.is_null";
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "pointer.is_null" [InvalidBuiltinSignature]
// CHECK:STDERR: fn WrongRetType(p: MakeUnformed({}*)) -> {} = "pointer.is_null";
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
fn WrongRetType(p: MakeUnformed({}*)) -> {} = "pointer.is_null";
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "pointer.is_null" [InvalidBuiltinSignature]
// CHECK:STDERR: fn NoUnformed(p: {}*) -> bool = "pointer.is_null";
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
fn NoUnformed(p: {}*) -> bool = "pointer.is_null";
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "pointer.is_null" [InvalidBuiltinSignature]
// CHECK:STDERR: fn NotPointer(p: MakeUnformed({})) -> bool = "pointer.is_null";
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
fn NotPointer(p: MakeUnformed({})) -> bool = "pointer.is_null";
// CHECK:STDOUT: --- call_exact.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %C: type = class_type @C [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %MakeUnformed.type: type = fn_type @MakeUnformed [concrete]
// CHECK:STDOUT: %MakeUnformed: %MakeUnformed.type = struct_value () [concrete]
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.c28: type = ptr_type %empty_struct_type [concrete]
// CHECK:STDOUT: %.b2d: type = maybe_unformed_type %ptr.c28 [concrete]
// CHECK:STDOUT: %pattern_type.b42: type = pattern_type %.b2d [concrete]
// CHECK:STDOUT: %.f34: Core.Form = init_form bool [concrete]
// CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
// CHECK:STDOUT: %IsNullEmptyStruct.type: type = fn_type @IsNullEmptyStruct [concrete]
// CHECK:STDOUT: %IsNullEmptyStruct: %IsNullEmptyStruct.type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.d6c: type = ptr_type %C [concrete]
// CHECK:STDOUT: %.4f6: type = maybe_unformed_type %ptr.d6c [concrete]
// CHECK:STDOUT: %pattern_type.b82: type = pattern_type %.4f6 [concrete]
// CHECK:STDOUT: %IsNullC.type: type = fn_type @IsNullC [concrete]
// CHECK:STDOUT: %IsNullC: %IsNullC.type = struct_value () [concrete]
// CHECK:STDOUT: %TestEmptyStruct.type: type = fn_type @TestEmptyStruct [concrete]
// CHECK:STDOUT: %TestEmptyStruct: %TestEmptyStruct.type = struct_value () [concrete]
// CHECK:STDOUT: %TestC.type: type = fn_type @TestC [concrete]
// CHECK:STDOUT: %TestC: %TestC.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: %TestEmptyStruct.decl: %TestEmptyStruct.type = fn_decl @TestEmptyStruct [concrete = constants.%TestEmptyStruct] {
// CHECK:STDOUT: %s.param_patt: %pattern_type.b42 = value_param_pattern [concrete]
// CHECK:STDOUT: %s.patt: %pattern_type.b42 = at_binding_pattern s, %s.param_patt [concrete]
// CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern [concrete]
// CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern %return.param_patt, %.loc11_45.1 [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc11_45.1: type = type_literal bool [concrete = bool]
// CHECK:STDOUT: %.loc11_45.2: Core.Form = init_form %.loc11_45.1 [concrete = constants.%.f34]
// CHECK:STDOUT: %s.param: %.b2d = value_param call_param0
// CHECK:STDOUT: %.loc11_39.1: type = splice_block %.loc11_39.3 [concrete = constants.%.b2d] {
// CHECK:STDOUT: %MakeUnformed.ref: %MakeUnformed.type = name_ref MakeUnformed, file.%MakeUnformed.decl [concrete = constants.%MakeUnformed]
// CHECK:STDOUT: %.loc11_37: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc11_38: type = converted %.loc11_37, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
// CHECK:STDOUT: %ptr: type = ptr_type %.loc11_38 [concrete = constants.%ptr.c28]
// CHECK:STDOUT: %MakeUnformed.call: init type = call %MakeUnformed.ref(%ptr) [concrete = constants.%.b2d]
// CHECK:STDOUT: %.loc11_39.2: type = value_of_initializer %MakeUnformed.call [concrete = constants.%.b2d]
// CHECK:STDOUT: %.loc11_39.3: type = converted %MakeUnformed.call, %.loc11_39.2 [concrete = constants.%.b2d]
// CHECK:STDOUT: }
// CHECK:STDOUT: %s: %.b2d = value_binding s, %s.param
// CHECK:STDOUT: %return.param: ref bool = out_param call_param1
// CHECK:STDOUT: %return: ref bool = return_slot %return.param
// CHECK:STDOUT: }
// CHECK:STDOUT: %TestC.decl: %TestC.type = fn_decl @TestC [concrete = constants.%TestC] {
// CHECK:STDOUT: %c.param_patt: %pattern_type.b82 = value_param_pattern [concrete]
// CHECK:STDOUT: %c.patt: %pattern_type.b82 = at_binding_pattern c, %c.param_patt [concrete]
// CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern [concrete]
// CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern %return.param_patt, %.loc15_34.1 [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc15_34.1: type = type_literal bool [concrete = bool]
// CHECK:STDOUT: %.loc15_34.2: Core.Form = init_form %.loc15_34.1 [concrete = constants.%.f34]
// CHECK:STDOUT: %c.param: %.4f6 = value_param call_param0
// CHECK:STDOUT: %.loc15_28.1: type = splice_block %.loc15_28.3 [concrete = constants.%.4f6] {
// CHECK:STDOUT: %MakeUnformed.ref: %MakeUnformed.type = name_ref MakeUnformed, file.%MakeUnformed.decl [concrete = constants.%MakeUnformed]
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
// CHECK:STDOUT: %ptr: type = ptr_type %C.ref [concrete = constants.%ptr.d6c]
// CHECK:STDOUT: %MakeUnformed.call: init type = call %MakeUnformed.ref(%ptr) [concrete = constants.%.4f6]
// CHECK:STDOUT: %.loc15_28.2: type = value_of_initializer %MakeUnformed.call [concrete = constants.%.4f6]
// CHECK:STDOUT: %.loc15_28.3: type = converted %MakeUnformed.call, %.loc15_28.2 [concrete = constants.%.4f6]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %.4f6 = value_binding c, %c.param
// CHECK:STDOUT: %return.param: ref bool = out_param call_param1
// CHECK:STDOUT: %return: ref bool = return_slot %return.param
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestEmptyStruct(%s.param: %.b2d) -> out %return.param: bool {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %IsNullEmptyStruct.ref: %IsNullEmptyStruct.type = name_ref IsNullEmptyStruct, file.%IsNullEmptyStruct.decl [concrete = constants.%IsNullEmptyStruct]
// CHECK:STDOUT: %s.ref: %.b2d = name_ref s, %s
// CHECK:STDOUT: %IsNullEmptyStruct.call: init bool = call %IsNullEmptyStruct.ref(%s.ref)
// CHECK:STDOUT: return %IsNullEmptyStruct.call
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestC(%c.param: %.4f6) -> out %return.param: bool {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %IsNullC.ref: %IsNullC.type = name_ref IsNullC, file.%IsNullC.decl [concrete = constants.%IsNullC]
// CHECK:STDOUT: %c.ref: %.4f6 = name_ref c, %c
// CHECK:STDOUT: %IsNullC.call: init bool = call %IsNullC.ref(%c.ref)
// CHECK:STDOUT: return %IsNullC.call
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- call_generic.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %MakeUnformed.type: type = fn_type @MakeUnformed [concrete]
// CHECK:STDOUT: %MakeUnformed: %MakeUnformed.type = struct_value () [concrete]
// CHECK:STDOUT: %.f34: Core.Form = init_form bool [concrete]
// CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
// CHECK:STDOUT: %IsNull.type: type = fn_type @IsNull [concrete]
// CHECK:STDOUT: %IsNull: %IsNull.type = struct_value () [concrete]
// CHECK:STDOUT: %C: type = class_type @C [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
// CHECK:STDOUT: %ptr.c28: type = ptr_type %empty_struct_type [concrete]
// CHECK:STDOUT: %.b2d: type = maybe_unformed_type %ptr.c28 [concrete]
// CHECK:STDOUT: %pattern_type.b42: type = pattern_type %.b2d [concrete]
// CHECK:STDOUT: %TestEmptyStruct.type: type = fn_type @TestEmptyStruct [concrete]
// CHECK:STDOUT: %TestEmptyStruct: %TestEmptyStruct.type = struct_value () [concrete]
// CHECK:STDOUT: %IsNull.specific_fn.e7f: <specific function> = specific_function %IsNull, @IsNull(%empty_struct_type) [concrete]
// CHECK:STDOUT: %ptr.66d: type = ptr_type %C [concrete]
// CHECK:STDOUT: %.30e: type = maybe_unformed_type %ptr.66d [concrete]
// CHECK:STDOUT: %pattern_type.37e: type = pattern_type %.30e [concrete]
// CHECK:STDOUT: %TestC.type: type = fn_type @TestC [concrete]
// CHECK:STDOUT: %TestC: %TestC.type = struct_value () [concrete]
// CHECK:STDOUT: %IsNull.specific_fn.164: <specific function> = specific_function %IsNull, @IsNull(%C) [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: %TestEmptyStruct.decl: %TestEmptyStruct.type = fn_decl @TestEmptyStruct [concrete = constants.%TestEmptyStruct] {
// CHECK:STDOUT: %s.param_patt: %pattern_type.b42 = value_param_pattern [concrete]
// CHECK:STDOUT: %s.patt: %pattern_type.b42 = at_binding_pattern s, %s.param_patt [concrete]
// CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern [concrete]
// CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern %return.param_patt, %.loc10_45.1 [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc10_45.1: type = type_literal bool [concrete = bool]
// CHECK:STDOUT: %.loc10_45.2: Core.Form = init_form %.loc10_45.1 [concrete = constants.%.f34]
// CHECK:STDOUT: %s.param: %.b2d = value_param call_param0
// CHECK:STDOUT: %.loc10_39.1: type = splice_block %.loc10_39.3 [concrete = constants.%.b2d] {
// CHECK:STDOUT: %MakeUnformed.ref: %MakeUnformed.type = name_ref MakeUnformed, file.%MakeUnformed.decl [concrete = constants.%MakeUnformed]
// CHECK:STDOUT: %.loc10_37: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc10_38: type = converted %.loc10_37, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
// CHECK:STDOUT: %ptr: type = ptr_type %.loc10_38 [concrete = constants.%ptr.c28]
// CHECK:STDOUT: %MakeUnformed.call: init type = call %MakeUnformed.ref(%ptr) [concrete = constants.%.b2d]
// CHECK:STDOUT: %.loc10_39.2: type = value_of_initializer %MakeUnformed.call [concrete = constants.%.b2d]
// CHECK:STDOUT: %.loc10_39.3: type = converted %MakeUnformed.call, %.loc10_39.2 [concrete = constants.%.b2d]
// CHECK:STDOUT: }
// CHECK:STDOUT: %s: %.b2d = value_binding s, %s.param
// CHECK:STDOUT: %return.param: ref bool = out_param call_param1
// CHECK:STDOUT: %return: ref bool = return_slot %return.param
// CHECK:STDOUT: }
// CHECK:STDOUT: %TestC.decl: %TestC.type = fn_decl @TestC [concrete = constants.%TestC] {
// CHECK:STDOUT: %c.param_patt: %pattern_type.37e = value_param_pattern [concrete]
// CHECK:STDOUT: %c.patt: %pattern_type.37e = at_binding_pattern c, %c.param_patt [concrete]
// CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern [concrete]
// CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern %return.param_patt, %.loc14_34.1 [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc14_34.1: type = type_literal bool [concrete = bool]
// CHECK:STDOUT: %.loc14_34.2: Core.Form = init_form %.loc14_34.1 [concrete = constants.%.f34]
// CHECK:STDOUT: %c.param: %.30e = value_param call_param0
// CHECK:STDOUT: %.loc14_28.1: type = splice_block %.loc14_28.3 [concrete = constants.%.30e] {
// CHECK:STDOUT: %MakeUnformed.ref: %MakeUnformed.type = name_ref MakeUnformed, file.%MakeUnformed.decl [concrete = constants.%MakeUnformed]
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
// CHECK:STDOUT: %ptr: type = ptr_type %C.ref [concrete = constants.%ptr.66d]
// CHECK:STDOUT: %MakeUnformed.call: init type = call %MakeUnformed.ref(%ptr) [concrete = constants.%.30e]
// CHECK:STDOUT: %.loc14_28.2: type = value_of_initializer %MakeUnformed.call [concrete = constants.%.30e]
// CHECK:STDOUT: %.loc14_28.3: type = converted %MakeUnformed.call, %.loc14_28.2 [concrete = constants.%.30e]
// CHECK:STDOUT: }
// CHECK:STDOUT: %c: %.30e = value_binding c, %c.param
// CHECK:STDOUT: %return.param: ref bool = out_param call_param1
// CHECK:STDOUT: %return: ref bool = return_slot %return.param
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestEmptyStruct(%s.param: %.b2d) -> out %return.param: bool {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %IsNull.ref: %IsNull.type = name_ref IsNull, file.%IsNull.decl [concrete = constants.%IsNull]
// CHECK:STDOUT: %s.ref: %.b2d = name_ref s, %s
// CHECK:STDOUT: %IsNull.specific_fn: <specific function> = specific_function %IsNull.ref, @IsNull(constants.%empty_struct_type) [concrete = constants.%IsNull.specific_fn.e7f]
// CHECK:STDOUT: %IsNull.call: init bool = call %IsNull.specific_fn(%s.ref)
// CHECK:STDOUT: return %IsNull.call
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @TestC(%c.param: %.30e) -> out %return.param: bool {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %IsNull.ref: %IsNull.type = name_ref IsNull, file.%IsNull.decl [concrete = constants.%IsNull]
// CHECK:STDOUT: %c.ref: %.30e = name_ref c, %c
// CHECK:STDOUT: %IsNull.specific_fn: <specific function> = specific_function %IsNull.ref, @IsNull(constants.%C) [concrete = constants.%IsNull.specific_fn.164]
// CHECK:STDOUT: %IsNull.call: init bool = call %IsNull.specific_fn(%c.ref)
// CHECK:STDOUT: return %IsNull.call
// CHECK:STDOUT: }
// CHECK:STDOUT: