|
| 1 | +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM |
| 2 | +// Exceptions. See /LICENSE for license information. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | +// |
| 5 | +// AUTOUPDATE |
| 6 | +// TIP: To test this file alone, run: |
| 7 | +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function_decl_inline.carbon |
| 8 | +// TIP: To dump output, run: |
| 9 | +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/no_prelude/function_decl_inline.carbon |
| 10 | + |
| 11 | +// ============================================================================ |
| 12 | +// inline_function_decl_with_definition |
| 13 | +// ============================================================================ |
| 14 | + |
| 15 | +// --- inline_function_decl_with_definition.h |
| 16 | + |
| 17 | +inline void foo() {} |
| 18 | + |
| 19 | +// --- import_inline_function_decl_with_definition.carbon |
| 20 | + |
| 21 | +library "[[@TEST_NAME]]"; |
| 22 | + |
| 23 | +import Cpp library "inline_function_decl_with_definition.h"; |
| 24 | + |
| 25 | +fn MyF() { |
| 26 | + Cpp.foo(); |
| 27 | +} |
| 28 | + |
| 29 | +// ============================================================================ |
| 30 | +// inline_function_decl_without_definition |
| 31 | +// ============================================================================ |
| 32 | + |
| 33 | +// --- inline_function_decl_without_definition.h |
| 34 | + |
| 35 | +inline void foo(); |
| 36 | + |
| 37 | +// --- todo_fail_import_inline_function_decl_without_definition.carbon |
| 38 | + |
| 39 | +library "[[@TEST_NAME]]"; |
| 40 | + |
| 41 | +import Cpp library "inline_function_decl_without_definition.h"; |
| 42 | + |
| 43 | +fn MyF() { |
| 44 | + // TODO: Error on using an inline function without definition. |
| 45 | + Cpp.foo(); |
| 46 | + |
| 47 | + // Don't error on repeated calls. |
| 48 | + Cpp.foo(); |
| 49 | +} |
| 50 | + |
| 51 | +// CHECK:STDOUT: --- import_inline_function_decl_with_definition.carbon |
| 52 | +// CHECK:STDOUT: |
| 53 | +// CHECK:STDOUT: constants { |
| 54 | +// CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete] |
| 55 | +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] |
| 56 | +// CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete] |
| 57 | +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] |
| 58 | +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] |
| 59 | +// CHECK:STDOUT: } |
| 60 | +// CHECK:STDOUT: |
| 61 | +// CHECK:STDOUT: imports { |
| 62 | +// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] { |
| 63 | +// CHECK:STDOUT: .foo = @MyF.%foo.decl |
| 64 | +// CHECK:STDOUT: import Cpp//... |
| 65 | +// CHECK:STDOUT: } |
| 66 | +// CHECK:STDOUT: } |
| 67 | +// CHECK:STDOUT: |
| 68 | +// CHECK:STDOUT: file { |
| 69 | +// CHECK:STDOUT: package: <namespace> = namespace [concrete] { |
| 70 | +// CHECK:STDOUT: .Cpp = imports.%Cpp |
| 71 | +// CHECK:STDOUT: .MyF = %MyF.decl |
| 72 | +// CHECK:STDOUT: } |
| 73 | +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { |
| 74 | +// CHECK:STDOUT: import Cpp "inline_function_decl_with_definition.h" |
| 75 | +// CHECK:STDOUT: } |
| 76 | +// CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {} |
| 77 | +// CHECK:STDOUT: } |
| 78 | +// CHECK:STDOUT: |
| 79 | +// CHECK:STDOUT: fn @MyF() { |
| 80 | +// CHECK:STDOUT: !entry: |
| 81 | +// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] |
| 82 | +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} |
| 83 | +// CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] |
| 84 | +// CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref() |
| 85 | +// CHECK:STDOUT: return |
| 86 | +// CHECK:STDOUT: } |
| 87 | +// CHECK:STDOUT: |
| 88 | +// CHECK:STDOUT: fn @foo(); |
| 89 | +// CHECK:STDOUT: |
| 90 | +// CHECK:STDOUT: --- todo_fail_import_inline_function_decl_without_definition.carbon |
| 91 | +// CHECK:STDOUT: |
| 92 | +// CHECK:STDOUT: constants { |
| 93 | +// CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete] |
| 94 | +// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete] |
| 95 | +// CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete] |
| 96 | +// CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete] |
| 97 | +// CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete] |
| 98 | +// CHECK:STDOUT: } |
| 99 | +// CHECK:STDOUT: |
| 100 | +// CHECK:STDOUT: imports { |
| 101 | +// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] { |
| 102 | +// CHECK:STDOUT: .foo = @MyF.%foo.decl |
| 103 | +// CHECK:STDOUT: import Cpp//... |
| 104 | +// CHECK:STDOUT: } |
| 105 | +// CHECK:STDOUT: } |
| 106 | +// CHECK:STDOUT: |
| 107 | +// CHECK:STDOUT: file { |
| 108 | +// CHECK:STDOUT: package: <namespace> = namespace [concrete] { |
| 109 | +// CHECK:STDOUT: .Cpp = imports.%Cpp |
| 110 | +// CHECK:STDOUT: .MyF = %MyF.decl |
| 111 | +// CHECK:STDOUT: } |
| 112 | +// CHECK:STDOUT: %Cpp.import_cpp = import_cpp { |
| 113 | +// CHECK:STDOUT: import Cpp "inline_function_decl_without_definition.h" |
| 114 | +// CHECK:STDOUT: } |
| 115 | +// CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {} |
| 116 | +// CHECK:STDOUT: } |
| 117 | +// CHECK:STDOUT: |
| 118 | +// CHECK:STDOUT: fn @MyF() { |
| 119 | +// CHECK:STDOUT: !entry: |
| 120 | +// CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] |
| 121 | +// CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {} |
| 122 | +// CHECK:STDOUT: %foo.ref.loc8: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] |
| 123 | +// CHECK:STDOUT: %foo.call.loc8: init %empty_tuple.type = call %foo.ref.loc8() |
| 124 | +// CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp] |
| 125 | +// CHECK:STDOUT: %foo.ref.loc11: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo] |
| 126 | +// CHECK:STDOUT: %foo.call.loc11: init %empty_tuple.type = call %foo.ref.loc11() |
| 127 | +// CHECK:STDOUT: return |
| 128 | +// CHECK:STDOUT: } |
| 129 | +// CHECK:STDOUT: |
| 130 | +// CHECK:STDOUT: fn @foo(); |
| 131 | +// CHECK:STDOUT: |
0 commit comments