function_decl_inline.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // inline_function_decl_with_definition
  12. // ============================================================================
  13. // --- inline_function_decl_with_definition.h
  14. inline void foo() {}
  15. // --- import_inline_function_decl_with_definition.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp library "inline_function_decl_with_definition.h";
  18. fn MyF() {
  19. Cpp.foo();
  20. }
  21. // ============================================================================
  22. // inline_function_decl_without_definition
  23. // ============================================================================
  24. // --- inline_function_decl_without_definition.h
  25. inline void foo();
  26. // --- todo_fail_import_inline_function_decl_without_definition.carbon
  27. library "[[@TEST_NAME]]";
  28. import Cpp library "inline_function_decl_without_definition.h";
  29. fn MyF() {
  30. // TODO: Error on using an inline function without definition.
  31. Cpp.foo();
  32. // Don't error on repeated calls.
  33. Cpp.foo();
  34. }
  35. // CHECK:STDOUT: --- import_inline_function_decl_with_definition.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete]
  39. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  40. // CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete]
  41. // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
  42. // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  47. // CHECK:STDOUT: .foo = @MyF.%foo.decl
  48. // CHECK:STDOUT: import Cpp//...
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  54. // CHECK:STDOUT: .Cpp = imports.%Cpp
  55. // CHECK:STDOUT: .MyF = %MyF.decl
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
  58. // CHECK:STDOUT: import Cpp "inline_function_decl_with_definition.h"
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @MyF() {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  66. // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {}
  67. // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo]
  68. // CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref()
  69. // CHECK:STDOUT: return
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: fn @foo();
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: --- todo_fail_import_inline_function_decl_without_definition.carbon
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: constants {
  77. // CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete]
  78. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  79. // CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete]
  80. // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
  81. // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: imports {
  85. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  86. // CHECK:STDOUT: .foo = @MyF.%foo.decl
  87. // CHECK:STDOUT: import Cpp//...
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: file {
  92. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  93. // CHECK:STDOUT: .Cpp = imports.%Cpp
  94. // CHECK:STDOUT: .MyF = %MyF.decl
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
  97. // CHECK:STDOUT: import Cpp "inline_function_decl_without_definition.h"
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {}
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @MyF() {
  103. // CHECK:STDOUT: !entry:
  104. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  105. // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {}
  106. // CHECK:STDOUT: %foo.ref.loc8: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo]
  107. // CHECK:STDOUT: %foo.call.loc8: init %empty_tuple.type = call %foo.ref.loc8()
  108. // CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  109. // CHECK:STDOUT: %foo.ref.loc11: %foo.type = name_ref foo, %foo.decl [concrete = constants.%foo]
  110. // CHECK:STDOUT: %foo.call.loc11: init %empty_tuple.type = call %foo.ref.loc11()
  111. // CHECK:STDOUT: return
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: fn @foo();
  115. // CHECK:STDOUT: