function_decl.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/lower/testdata/interop/cpp/function_decl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/function_decl.carbon
  10. // ============================================================================
  11. // function_decl
  12. // ============================================================================
  13. // --- function_decl.h
  14. void foo();
  15. // --- import_function_decl.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp library "function_decl.h";
  18. fn MyF() {
  19. Cpp.foo();
  20. }
  21. // ============================================================================
  22. // inline_function_decl
  23. // ============================================================================
  24. // --- inline_function_decl.h
  25. inline void foo() {}
  26. // --- todo_import_inline_function_decl.carbon
  27. library "[[@TEST_NAME]]";
  28. import Cpp library "inline_function_decl.h";
  29. fn MyF() {
  30. // TODO: This should generate the definition of the inline function `foo()`.
  31. Cpp.foo();
  32. }
  33. // CHECK:STDOUT: ; ModuleID = 'import_function_decl.carbon'
  34. // CHECK:STDOUT: source_filename = "import_function_decl.carbon"
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: define void @_CMyF.Main() !dbg !4 {
  37. // CHECK:STDOUT: entry:
  38. // CHECK:STDOUT: call void @_Z3foov(), !dbg !7
  39. // CHECK:STDOUT: ret void, !dbg !8
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: declare void @_Z3foov()
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  45. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  48. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  49. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  50. // CHECK:STDOUT: !3 = !DIFile(filename: "import_function_decl.carbon", directory: "")
  51. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "MyF", linkageName: "_CMyF.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  52. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  53. // CHECK:STDOUT: !6 = !{}
  54. // CHECK:STDOUT: !7 = !DILocation(line: 7, column: 3, scope: !4)
  55. // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 1, scope: !4)
  56. // CHECK:STDOUT: ; ModuleID = 'todo_import_inline_function_decl.carbon'
  57. // CHECK:STDOUT: source_filename = "todo_import_inline_function_decl.carbon"
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: define void @_CMyF.Main() !dbg !4 {
  60. // CHECK:STDOUT: entry:
  61. // CHECK:STDOUT: call void @_Z3foov(), !dbg !7
  62. // CHECK:STDOUT: ret void, !dbg !8
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: declare void @_Z3foov()
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  68. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  71. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  72. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  73. // CHECK:STDOUT: !3 = !DIFile(filename: "todo_import_inline_function_decl.carbon", directory: "")
  74. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "MyF", linkageName: "_CMyF.Main", scope: null, file: !3, line: 6, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  75. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  76. // CHECK:STDOUT: !6 = !{}
  77. // CHECK:STDOUT: !7 = !DILocation(line: 8, column: 3, scope: !4)
  78. // CHECK:STDOUT: !8 = !DILocation(line: 6, column: 1, scope: !4)