inline.carbon 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/function/inline.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/function/inline.carbon
  12. // ============================================================================
  13. // With definition
  14. // ============================================================================
  15. // --- with_definition.h
  16. inline void foo() {}
  17. // --- import_with_definition.carbon
  18. library "[[@TEST_NAME]]";
  19. import Cpp library "with_definition.h";
  20. fn MyF() {
  21. //@dump-sem-ir-begin
  22. Cpp.foo();
  23. //@dump-sem-ir-end
  24. }
  25. // ============================================================================
  26. // Without definition
  27. // ============================================================================
  28. // --- without_definition.h
  29. inline void foo();
  30. // --- todo_fail_import_without_definition.carbon
  31. library "[[@TEST_NAME]]";
  32. import Cpp library "without_definition.h";
  33. fn MyF() {
  34. //@dump-sem-ir-begin
  35. // TODO: Error on using an inline function without definition.
  36. Cpp.foo();
  37. // Don't error on repeated calls.
  38. Cpp.foo();
  39. //@dump-sem-ir-end
  40. }
  41. // CHECK:STDOUT: --- import_with_definition.carbon
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: constants {
  44. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  45. // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
  46. // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  51. // CHECK:STDOUT: .foo = %foo.decl
  52. // CHECK:STDOUT: import Cpp//...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {}
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: fn @MyF() {
  58. // CHECK:STDOUT: !entry:
  59. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  60. // CHECK:STDOUT: %foo.ref: %foo.type = name_ref foo, imports.%foo.decl [concrete = constants.%foo]
  61. // CHECK:STDOUT: %foo.call: init %empty_tuple.type = call %foo.ref()
  62. // CHECK:STDOUT: <elided>
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: --- todo_fail_import_without_definition.carbon
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: constants {
  68. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  69. // CHECK:STDOUT: %foo.type: type = fn_type @foo [concrete]
  70. // CHECK:STDOUT: %foo: %foo.type = struct_value () [concrete]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: imports {
  74. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  75. // CHECK:STDOUT: .foo = %foo.decl
  76. // CHECK:STDOUT: import Cpp//...
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %foo.decl: %foo.type = fn_decl @foo [concrete = constants.%foo] {} {}
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @MyF() {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  84. // CHECK:STDOUT: %foo.ref.loc9: %foo.type = name_ref foo, imports.%foo.decl [concrete = constants.%foo]
  85. // CHECK:STDOUT: %foo.call.loc9: init %empty_tuple.type = call %foo.ref.loc9()
  86. // CHECK:STDOUT: %Cpp.ref.loc12: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  87. // CHECK:STDOUT: %foo.ref.loc12: %foo.type = name_ref foo, imports.%foo.decl [concrete = constants.%foo]
  88. // CHECK:STDOUT: %foo.call.loc12: init %empty_tuple.type = call %foo.ref.loc12()
  89. // CHECK:STDOUT: <elided>
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: