cross_library_name_collision_private.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/int.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/function/generic/cross_library_name_collision_private.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/cross_library_name_collision_private.carbon
  12. // --- lib1.carbon
  13. library "[[@TEST_NAME]]";
  14. private fn F[T:! Core.Copy](a: T, _: T) -> T {
  15. return a;
  16. }
  17. fn Lib1CallF[T:! Core.Copy](a: T, b: T) -> T {
  18. return F(a, b);
  19. }
  20. // --- lib2.carbon
  21. library "[[@TEST_NAME]]";
  22. // Duplicate function name in different files. Shouldn't be a name conflict
  23. // because of `private`. However, we currently use the same mangling for both
  24. // functions.
  25. private fn F[T:! Core.Copy](_: T, b: T) -> T {
  26. return b;
  27. }
  28. fn Lib2CallF[T:! Core.Copy](a: T, b: T) -> T {
  29. return F(a, b);
  30. }
  31. // --- todo_use.carbon
  32. // TODO: This should call the `F` from lib1 and the `F` from lib2. Currently
  33. // it calls the same function in both (hashes match for both instances of
  34. // `call i32 @_CF.Main.<hash>`).
  35. import library "lib1";
  36. import library "lib2";
  37. fn Run() {
  38. let _: i32 = Lib1CallF(1 as i32, 2 as i32);
  39. let _: i32 = Lib2CallF(1 as i32, 2 as i32);
  40. }
  41. // CHECK:STDOUT: ; ModuleID = 'lib1.carbon'
  42. // CHECK:STDOUT: source_filename = "lib1.carbon"
  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_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  50. // CHECK:STDOUT: !3 = !DIFile(filename: "lib1.carbon", directory: "")
  51. // CHECK:STDOUT: ; ModuleID = 'lib2.carbon'
  52. // CHECK:STDOUT: source_filename = "lib2.carbon"
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  55. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  58. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  59. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  60. // CHECK:STDOUT: !3 = !DIFile(filename: "lib2.carbon", directory: "")
  61. // CHECK:STDOUT: ; ModuleID = 'todo_use.carbon'
  62. // CHECK:STDOUT: source_filename = "todo_use.carbon"
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: ; Function Attrs: nounwind
  65. // CHECK:STDOUT: define void @main() #0 !dbg !4 {
  66. // CHECK:STDOUT: entry:
  67. // CHECK:STDOUT: %Lib1CallF.call = call i32 @_CLib1CallF.Main.ce17bf05555dc18d(i32 1, i32 2), !dbg !7
  68. // CHECK:STDOUT: %Lib2CallF.call = call i32 @_CLib2CallF.Main.ce17bf05555dc18d(i32 1, i32 2), !dbg !8
  69. // CHECK:STDOUT: ret void, !dbg !9
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: ; Function Attrs: nounwind
  73. // CHECK:STDOUT: define linkonce_odr i32 @_CLib1CallF.Main.ce17bf05555dc18d(i32 %a, i32 %b) #0 !dbg !10 {
  74. // CHECK:STDOUT: %1 = call i32 @_CF.Main.ce17bf05555dc18d(i32 %a, i32 %b), !dbg !18
  75. // CHECK:STDOUT: ret i32 %1, !dbg !19
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: ; Function Attrs: nounwind
  79. // CHECK:STDOUT: define linkonce_odr i32 @_CLib2CallF.Main.ce17bf05555dc18d(i32 %a, i32 %b) #0 !dbg !20 {
  80. // CHECK:STDOUT: %1 = call i32 @_CF.Main.ce17bf05555dc18d(i32 %a, i32 %b), !dbg !25
  81. // CHECK:STDOUT: ret i32 %1, !dbg !26
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: ; Function Attrs: nounwind
  85. // CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.ce17bf05555dc18d(i32 %a, i32 %_) #0 !dbg !27 {
  86. // CHECK:STDOUT: ret i32 %a, !dbg !31
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: ; uselistorder directives
  90. // CHECK:STDOUT: uselistorder ptr @_CF.Main.ce17bf05555dc18d, { 1, 0 }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: attributes #0 = { nounwind }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  95. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  98. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  99. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  100. // CHECK:STDOUT: !3 = !DIFile(filename: "todo_use.carbon", directory: "")
  101. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !3, line: 9, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  102. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  103. // CHECK:STDOUT: !6 = !{null}
  104. // CHECK:STDOUT: !7 = !DILocation(line: 10, column: 16, scope: !4)
  105. // CHECK:STDOUT: !8 = !DILocation(line: 11, column: 16, scope: !4)
  106. // CHECK:STDOUT: !9 = !DILocation(line: 9, column: 1, scope: !4)
  107. // CHECK:STDOUT: !10 = distinct !DISubprogram(name: "Lib1CallF", linkageName: "_CLib1CallF.Main.ce17bf05555dc18d", scope: null, file: !11, line: 8, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !15)
  108. // CHECK:STDOUT: !11 = !DIFile(filename: "lib1.carbon", directory: "")
  109. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  110. // CHECK:STDOUT: !13 = !{!14, !14, !14}
  111. // CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  112. // CHECK:STDOUT: !15 = !{!16, !17}
  113. // CHECK:STDOUT: !16 = !DILocalVariable(arg: 1, scope: !10, type: !14)
  114. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 2, scope: !10, type: !14)
  115. // CHECK:STDOUT: !18 = !DILocation(line: 9, column: 10, scope: !10)
  116. // CHECK:STDOUT: !19 = !DILocation(line: 9, column: 3, scope: !10)
  117. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "Lib2CallF", linkageName: "_CLib2CallF.Main.ce17bf05555dc18d", scope: null, file: !21, line: 11, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !22)
  118. // CHECK:STDOUT: !21 = !DIFile(filename: "lib2.carbon", directory: "")
  119. // CHECK:STDOUT: !22 = !{!23, !24}
  120. // CHECK:STDOUT: !23 = !DILocalVariable(arg: 1, scope: !20, type: !14)
  121. // CHECK:STDOUT: !24 = !DILocalVariable(arg: 2, scope: !20, type: !14)
  122. // CHECK:STDOUT: !25 = !DILocation(line: 12, column: 10, scope: !20)
  123. // CHECK:STDOUT: !26 = !DILocation(line: 12, column: 3, scope: !20)
  124. // CHECK:STDOUT: !27 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.ce17bf05555dc18d", scope: null, file: !11, line: 4, type: !12, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !28)
  125. // CHECK:STDOUT: !28 = !{!29, !30}
  126. // CHECK:STDOUT: !29 = !DILocalVariable(arg: 1, scope: !27, type: !14)
  127. // CHECK:STDOUT: !30 = !DILocalVariable(arg: 2, scope: !27, type: !14)
  128. // CHECK:STDOUT: !31 = !DILocation(line: 5, column: 3, scope: !27)