cross_library_name_collision_private.carbon 5.7 KB

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