call_deref_ptr.carbon 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/call_deref_ptr.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_deref_ptr.carbon
  10. // Builds on call_basic.carbon and call_impl_function.carbon.
  11. // Test that when equivalence is found for the specific fingerprint, we don't
  12. // conclude "equivalent" for all the call graph. This is to account for
  13. // switching to a work-queue from recursion.
  14. fn A[U:! type](x: U) -> U {
  15. return x;
  16. }
  17. fn D[U:! type](x: U) -> U {
  18. return x;
  19. }
  20. fn B[U:! type](x: U*) {
  21. D(*x);
  22. }
  23. fn F[T:! type](x: T*) {
  24. A(i32);
  25. B(x);
  26. }
  27. fn M() {
  28. var ptr_i32 : i32*;
  29. var ptr_f64 : f64*;
  30. F(ptr_i32);
  31. F(ptr_f64);
  32. }
  33. // CHECK:STDOUT: ; ModuleID = 'call_deref_ptr.carbon'
  34. // CHECK:STDOUT: source_filename = "call_deref_ptr.carbon"
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: %type = type {}
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
  39. // CHECK:STDOUT: entry:
  40. // CHECK:STDOUT: %ptr_i32.var = alloca ptr, align 8, !dbg !7
  41. // CHECK:STDOUT: %ptr_f64.var = alloca ptr, align 8, !dbg !8
  42. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i32.var), !dbg !7
  43. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !8
  44. // CHECK:STDOUT: %.loc37 = load ptr, ptr %ptr_i32.var, align 8, !dbg !9
  45. // CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(ptr %.loc37), !dbg !10
  46. // CHECK:STDOUT: %.loc38 = load ptr, ptr %ptr_f64.var, align 8, !dbg !11
  47. // CHECK:STDOUT: call void @_CF.Main.66be507887ceee78(ptr %.loc38), !dbg !12
  48. // CHECK:STDOUT: ret void, !dbg !13
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  52. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: define linkonce_odr void @_CF.Main.b88d1103f417c6d4(ptr %x) !dbg !14 {
  55. // CHECK:STDOUT: entry:
  56. // CHECK:STDOUT: %A.call = call %type @_CA.Main.5754c7a55c7cbe4a(%type zeroinitializer), !dbg !15
  57. // CHECK:STDOUT: call void @_CB.Main.b88d1103f417c6d4(ptr %x), !dbg !16
  58. // CHECK:STDOUT: ret void, !dbg !17
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: define linkonce_odr void @_CF.Main.66be507887ceee78(ptr %x) !dbg !18 {
  62. // CHECK:STDOUT: entry:
  63. // CHECK:STDOUT: %A.call = call %type @_CA.Main.5754c7a55c7cbe4a(%type zeroinitializer), !dbg !19
  64. // CHECK:STDOUT: call void @_CB.Main.66be507887ceee78(ptr %x), !dbg !20
  65. // CHECK:STDOUT: ret void, !dbg !21
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: define linkonce_odr %type @_CA.Main.5754c7a55c7cbe4a(%type %x) !dbg !22 {
  69. // CHECK:STDOUT: entry:
  70. // CHECK:STDOUT: ret %type %x, !dbg !23
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: define linkonce_odr void @_CB.Main.b88d1103f417c6d4(ptr %x) !dbg !24 {
  74. // CHECK:STDOUT: entry:
  75. // CHECK:STDOUT: %.loc25_5.2 = load i32, ptr %x, align 4, !dbg !25
  76. // CHECK:STDOUT: %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %.loc25_5.2), !dbg !26
  77. // CHECK:STDOUT: ret void, !dbg !27
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: define linkonce_odr void @_CB.Main.66be507887ceee78(ptr %x) !dbg !28 {
  81. // CHECK:STDOUT: entry:
  82. // CHECK:STDOUT: %.loc25_5.2 = load double, ptr %x, align 8, !dbg !29
  83. // CHECK:STDOUT: %D.call = call double @_CD.Main.66be507887ceee78(double %.loc25_5.2), !dbg !30
  84. // CHECK:STDOUT: ret void, !dbg !31
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: define linkonce_odr i32 @_CD.Main.b88d1103f417c6d4(i32 %x) !dbg !32 {
  88. // CHECK:STDOUT: entry:
  89. // CHECK:STDOUT: ret i32 %x, !dbg !33
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: define linkonce_odr double @_CD.Main.66be507887ceee78(double %x) !dbg !34 {
  93. // CHECK:STDOUT: entry:
  94. // CHECK:STDOUT: ret double %x, !dbg !35
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: ; uselistorder directives
  98. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
  99. // CHECK:STDOUT: uselistorder ptr @_CA.Main.5754c7a55c7cbe4a, { 1, 0 }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  104. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  107. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  108. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  109. // CHECK:STDOUT: !3 = !DIFile(filename: "call_deref_ptr.carbon", directory: "")
  110. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 33, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  111. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  112. // CHECK:STDOUT: !6 = !{}
  113. // CHECK:STDOUT: !7 = !DILocation(line: 34, column: 3, scope: !4)
  114. // CHECK:STDOUT: !8 = !DILocation(line: 35, column: 3, scope: !4)
  115. // CHECK:STDOUT: !9 = !DILocation(line: 37, column: 5, scope: !4)
  116. // CHECK:STDOUT: !10 = !DILocation(line: 37, column: 3, scope: !4)
  117. // CHECK:STDOUT: !11 = !DILocation(line: 38, column: 5, scope: !4)
  118. // CHECK:STDOUT: !12 = !DILocation(line: 38, column: 3, scope: !4)
  119. // CHECK:STDOUT: !13 = !DILocation(line: 33, column: 1, scope: !4)
  120. // CHECK:STDOUT: !14 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  121. // CHECK:STDOUT: !15 = !DILocation(line: 29, column: 3, scope: !14)
  122. // CHECK:STDOUT: !16 = !DILocation(line: 30, column: 3, scope: !14)
  123. // CHECK:STDOUT: !17 = !DILocation(line: 28, column: 1, scope: !14)
  124. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  125. // CHECK:STDOUT: !19 = !DILocation(line: 29, column: 3, scope: !18)
  126. // CHECK:STDOUT: !20 = !DILocation(line: 30, column: 3, scope: !18)
  127. // CHECK:STDOUT: !21 = !DILocation(line: 28, column: 1, scope: !18)
  128. // CHECK:STDOUT: !22 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  129. // CHECK:STDOUT: !23 = !DILocation(line: 17, column: 3, scope: !22)
  130. // CHECK:STDOUT: !24 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.b88d1103f417c6d4", scope: null, file: !3, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  131. // CHECK:STDOUT: !25 = !DILocation(line: 25, column: 5, scope: !24)
  132. // CHECK:STDOUT: !26 = !DILocation(line: 25, column: 3, scope: !24)
  133. // CHECK:STDOUT: !27 = !DILocation(line: 24, column: 1, scope: !24)
  134. // CHECK:STDOUT: !28 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.66be507887ceee78", scope: null, file: !3, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  135. // CHECK:STDOUT: !29 = !DILocation(line: 25, column: 5, scope: !28)
  136. // CHECK:STDOUT: !30 = !DILocation(line: 25, column: 3, scope: !28)
  137. // CHECK:STDOUT: !31 = !DILocation(line: 24, column: 1, scope: !28)
  138. // CHECK:STDOUT: !32 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.b88d1103f417c6d4", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  139. // CHECK:STDOUT: !33 = !DILocation(line: 21, column: 3, scope: !32)
  140. // CHECK:STDOUT: !34 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.66be507887ceee78", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  141. // CHECK:STDOUT: !35 = !DILocation(line: 21, column: 3, scope: !34)