inline.carbon 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/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/inline.carbon
  12. // --- use_inline_function_decl.carbon
  13. library "[[@TEST_NAME]]";
  14. //@dump-sem-ir-begin
  15. import Cpp inline '''
  16. // A C++ function.
  17. inline void func() {}
  18. ''';
  19. //@dump-sem-ir-end
  20. fn Run() {
  21. //@dump-sem-ir-begin
  22. Cpp.func();
  23. //@dump-sem-ir-end
  24. }
  25. // --- with_language_marker.carbon
  26. library "[[@TEST_NAME]]";
  27. //@dump-sem-ir-begin
  28. import Cpp inline '''c++
  29. // A C++ function.
  30. inline void another_func() {}
  31. ''';
  32. //@dump-sem-ir-end
  33. fn Run() {
  34. //@dump-sem-ir-begin
  35. Cpp.another_func();
  36. //@dump-sem-ir-end
  37. }
  38. // CHECK:STDOUT: --- use_inline_function_decl.carbon
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: constants {
  41. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  42. // CHECK:STDOUT: %func.type: type = fn_type @func [concrete]
  43. // CHECK:STDOUT: %func: %func.type = struct_value () [concrete]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  48. // CHECK:STDOUT: .func = %func.decl
  49. // CHECK:STDOUT: import Cpp//...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %func.decl: %func.type = fn_decl @func [concrete = constants.%func] {} {}
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
  56. // CHECK:STDOUT: import Cpp inline
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @Run() {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  63. // CHECK:STDOUT: %func.ref: %func.type = name_ref func, imports.%func.decl [concrete = constants.%func]
  64. // CHECK:STDOUT: %func.call: init %empty_tuple.type = call %func.ref()
  65. // CHECK:STDOUT: <elided>
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: --- with_language_marker.carbon
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: constants {
  71. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  72. // CHECK:STDOUT: %another_func.type: type = fn_type @another_func [concrete]
  73. // CHECK:STDOUT: %another_func: %another_func.type = struct_value () [concrete]
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: imports {
  77. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  78. // CHECK:STDOUT: .another_func = %another_func.decl
  79. // CHECK:STDOUT: import Cpp//...
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %another_func.decl: %another_func.type = fn_decl @another_func [concrete = constants.%another_func] {} {}
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: file {
  85. // CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
  86. // CHECK:STDOUT: import Cpp inline
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @Run() {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  93. // CHECK:STDOUT: %another_func.ref: %another_func.type = name_ref another_func, imports.%another_func.decl [concrete = constants.%another_func]
  94. // CHECK:STDOUT: %another_func.call: init %empty_tuple.type = call %another_func.ref()
  95. // CHECK:STDOUT: <elided>
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: