function.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/lower/testdata/interop/cpp/reverse/function.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/reverse/function.carbon
  12. // --- other.carbon
  13. package Other;
  14. fn F() {}
  15. // --- function.carbon
  16. library "[[@TEST_NAME]]";
  17. import Other;
  18. import Cpp inline '''
  19. void G() {
  20. Carbon::Other::F();
  21. }
  22. ''';
  23. // --- single_file.carbon
  24. library "[[@TEST_NAME]]";
  25. import Cpp;
  26. fn F() {}
  27. inline Cpp '''
  28. inline void G1() {
  29. Carbon::F();
  30. }
  31. // Call an inline function indirectly to ensure declarations are getting
  32. // properly registered with the CodeGen consumer.
  33. inline void G2() {
  34. G1();
  35. }
  36. ''';
  37. fn H() { Cpp.G2(); }
  38. // CHECK:STDOUT: ; ModuleID = 'other.carbon'
  39. // CHECK:STDOUT: source_filename = "other.carbon"
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: ; Function Attrs: nounwind
  42. // CHECK:STDOUT: define void @_CF.Other() #0 !dbg !4 {
  43. // CHECK:STDOUT: entry:
  44. // CHECK:STDOUT: ret void, !dbg !7
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: attributes #0 = { nounwind }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  50. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  53. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  54. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  55. // CHECK:STDOUT: !3 = !DIFile(filename: "other.carbon", directory: "")
  56. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Other", scope: null, file: !3, line: 2, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  57. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  58. // CHECK:STDOUT: !6 = !{null}
  59. // CHECK:STDOUT: !7 = !DILocation(line: 2, column: 1, scope: !4)
  60. // CHECK:STDOUT: ; ModuleID = 'function.carbon'
  61. // CHECK:STDOUT: source_filename = "function.carbon"
  62. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  63. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: ; Function Attrs: mustprogress uwtable
  66. // CHECK:STDOUT: define dso_local void @_Z1Gv() #0 {
  67. // CHECK:STDOUT: entry:
  68. // CHECK:STDOUT: call void @_CF.Other()
  69. // CHECK:STDOUT: ret void
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: declare void @_CF.Other() #1
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  75. // CHECK:STDOUT: attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  78. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  79. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  82. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  83. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  84. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  85. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  86. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  87. // CHECK:STDOUT: !6 = !DIFile(filename: "function.carbon", directory: "")
  88. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  89. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  90. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  91. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  92. // CHECK:STDOUT: ; ModuleID = 'single_file.carbon'
  93. // CHECK:STDOUT: source_filename = "single_file.carbon"
  94. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  95. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: $_Z2G2v = comdat any
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: $_Z2G1v = comdat any
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: ; Function Attrs: nounwind
  102. // CHECK:STDOUT: define void @_CF.Main() #0 !dbg !11 {
  103. // CHECK:STDOUT: entry:
  104. // CHECK:STDOUT: ret void, !dbg !14
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: ; Function Attrs: nounwind
  108. // CHECK:STDOUT: define void @_CH.Main() #0 !dbg !15 {
  109. // CHECK:STDOUT: entry:
  110. // CHECK:STDOUT: call void @_Z2G2v(), !dbg !16
  111. // CHECK:STDOUT: ret void, !dbg !17
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress uwtable
  115. // CHECK:STDOUT: define linkonce_odr dso_local void @_Z2G2v() #1 comdat {
  116. // CHECK:STDOUT: entry:
  117. // CHECK:STDOUT: call void @_Z2G1v()
  118. // CHECK:STDOUT: ret void
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: ; Function Attrs: inlinehint mustprogress nounwind uwtable
  122. // CHECK:STDOUT: define linkonce_odr dso_local void @_Z2G1v() #2 comdat {
  123. // CHECK:STDOUT: entry:
  124. // CHECK:STDOUT: call void @_CF.Main()
  125. // CHECK:STDOUT: ret void
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: attributes #0 = { nounwind }
  129. // CHECK:STDOUT: attributes #1 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  130. // CHECK:STDOUT: attributes #2 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  133. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  134. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  137. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  138. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  139. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  140. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  141. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  142. // CHECK:STDOUT: !6 = !DIFile(filename: "single_file.carbon", directory: "")
  143. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  144. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  145. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  146. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  147. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !6, line: 6, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  148. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  149. // CHECK:STDOUT: !13 = !{null}
  150. // CHECK:STDOUT: !14 = !DILocation(line: 6, column: 1, scope: !11)
  151. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main", scope: null, file: !6, line: 20, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  152. // CHECK:STDOUT: !16 = !DILocation(line: 20, column: 10, scope: !15)
  153. // CHECK:STDOUT: !17 = !DILocation(line: 20, column: 1, scope: !15)