Files
carbon-lang/toolchain/check/testdata/interop/cpp/inline.carbon
T
Boaz Brickner 16999a79cc Fix a crash caused by a bug introduced in C++ overloads support in GetScopeIdOffset() (#6151)
After this change, we correctly increment the offset by the next switch
case type.
Before this change, we accidentally incremented the offset by
`functions()` size instead of `cpp_overload_sets()` size and vice versa.
Also sorted the switch cases according to the order of the enum, for
consistency. This might help prevent a future similar incident.

This fix prevents crashing in the newly introduced test
`multiple_too_few_args_calls`.

This also has the side effect of showing `null name` for
`cpp_overload_set_type` and `cpp_overload_set_value`, instead of having
an arbitrary name.
Examples that demonstrate the old name is arbitrary can easily be seen
in tests like `cpp_namespace.carbon` and `decayed_param.carbon`, but
careful review would show that all old names are arbitrary, though often
luckily almost make sense.

We might want to have a proper name for these, but it's beyond the scope
of this crash fixing change.
See #6156.

Part of #5915.
2025-10-02 14:34:34 +00:00

117 lines
4.1 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/none.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/inline.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/inline.carbon
// --- use_inline_function_decl.carbon
library "[[@TEST_NAME]]";
//@dump-sem-ir-begin
import Cpp inline '''
// A C++ function.
inline void func() {}
''';
//@dump-sem-ir-end
fn Run() {
//@dump-sem-ir-begin
Cpp.func();
//@dump-sem-ir-end
}
// --- with_language_marker.carbon
library "[[@TEST_NAME]]";
//@dump-sem-ir-begin
import Cpp inline '''c++
// A C++ function.
inline void another_func() {}
''';
//@dump-sem-ir-end
fn Run() {
//@dump-sem-ir-begin
Cpp.another_func();
//@dump-sem-ir-end
}
// CHECK:STDOUT: --- use_inline_function_decl.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %.19f: type = cpp_overload_set_type @<null name> [concrete]
// CHECK:STDOUT: %.ddc: %.19f = cpp_overload_set_value @<null name> [concrete]
// CHECK:STDOUT: %func.type: type = fn_type @func [concrete]
// CHECK:STDOUT: %func: %func.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
// CHECK:STDOUT: .func = %.ddc
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %.ddc: %.19f = cpp_overload_set_value @<null name> [concrete = constants.%.ddc]
// CHECK:STDOUT: %func.decl: %func.type = fn_decl @func [concrete = constants.%func] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
// CHECK:STDOUT: import Cpp inline
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Run() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %func.ref: %.19f = name_ref func, imports.%.ddc [concrete = constants.%.ddc]
// CHECK:STDOUT: %func.call: init %empty_tuple.type = call imports.%func.decl()
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- with_language_marker.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %.bcd: type = cpp_overload_set_type @<null name> [concrete]
// CHECK:STDOUT: %.b52: %.bcd = cpp_overload_set_value @<null name> [concrete]
// CHECK:STDOUT: %another_func.type: type = fn_type @another_func [concrete]
// CHECK:STDOUT: %another_func: %another_func.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
// CHECK:STDOUT: .another_func = %.b52
// CHECK:STDOUT: import Cpp//...
// CHECK:STDOUT: }
// CHECK:STDOUT: %.b52: %.bcd = cpp_overload_set_value @<null name> [concrete = constants.%.b52]
// CHECK:STDOUT: %another_func.decl: %another_func.type = fn_decl @another_func [concrete = constants.%another_func] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
// CHECK:STDOUT: import Cpp inline
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Run() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %another_func.ref: %.bcd = name_ref another_func, imports.%.b52 [concrete = constants.%.b52]
// CHECK:STDOUT: %another_func.call: init %empty_tuple.type = call imports.%another_func.decl()
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
// CHECK:STDOUT: