call_dedup_ptr.carbon 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_dedup_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_dedup_ptr.carbon
  10. fn F[T:! type](x: T) -> T {
  11. return x;
  12. }
  13. fn M() {
  14. // TODO: The definitions of F for these calls lower to different identical
  15. // functions taking a pointer param and returning a pointer. The three
  16. // specifics could be deduplicated.
  17. var ptr_i32 : i32*;
  18. F(ptr_i32);
  19. var ptr_f64 : f64*;
  20. F(ptr_f64);
  21. var ptr_i8 : i8*;
  22. F(ptr_i8);
  23. }
  24. // CHECK:STDOUT: ; ModuleID = 'call_dedup_ptr.carbon'
  25. // CHECK:STDOUT: source_filename = "call_dedup_ptr.carbon"
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
  28. // CHECK:STDOUT: entry:
  29. // CHECK:STDOUT: %ptr_i32.var = alloca ptr, align 8, !dbg !7
  30. // CHECK:STDOUT: %ptr_f64.var = alloca ptr, align 8, !dbg !8
  31. // CHECK:STDOUT: %ptr_i8.var = alloca ptr, align 8, !dbg !9
  32. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i32.var), !dbg !7
  33. // CHECK:STDOUT: %.loc20 = load ptr, ptr %ptr_i32.var, align 8, !dbg !10
  34. // CHECK:STDOUT: %F.call.loc20 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc20), !dbg !11
  35. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !8
  36. // CHECK:STDOUT: %.loc22 = load ptr, ptr %ptr_f64.var, align 8, !dbg !12
  37. // CHECK:STDOUT: %F.call.loc22 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc22), !dbg !13
  38. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i8.var), !dbg !9
  39. // CHECK:STDOUT: %.loc24 = load ptr, ptr %ptr_i8.var, align 8, !dbg !14
  40. // CHECK:STDOUT: %F.call.loc24 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc24), !dbg !15
  41. // CHECK:STDOUT: ret void, !dbg !16
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  45. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.e8193710fd35b608(ptr %x) !dbg !17 {
  48. // CHECK:STDOUT: entry:
  49. // CHECK:STDOUT: ret ptr %x, !dbg !18
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: ; uselistorder directives
  53. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 2, 1, 0 }
  54. // CHECK:STDOUT: uselistorder ptr @_CF.Main.e8193710fd35b608, { 2, 1, 0 }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  59. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  62. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  63. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  64. // CHECK:STDOUT: !3 = !DIFile(filename: "call_dedup_ptr.carbon", directory: "")
  65. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  66. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  67. // CHECK:STDOUT: !6 = !{}
  68. // CHECK:STDOUT: !7 = !DILocation(line: 19, column: 3, scope: !4)
  69. // CHECK:STDOUT: !8 = !DILocation(line: 21, column: 3, scope: !4)
  70. // CHECK:STDOUT: !9 = !DILocation(line: 23, column: 3, scope: !4)
  71. // CHECK:STDOUT: !10 = !DILocation(line: 20, column: 5, scope: !4)
  72. // CHECK:STDOUT: !11 = !DILocation(line: 20, column: 3, scope: !4)
  73. // CHECK:STDOUT: !12 = !DILocation(line: 22, column: 5, scope: !4)
  74. // CHECK:STDOUT: !13 = !DILocation(line: 22, column: 3, scope: !4)
  75. // CHECK:STDOUT: !14 = !DILocation(line: 24, column: 5, scope: !4)
  76. // CHECK:STDOUT: !15 = !DILocation(line: 24, column: 3, scope: !4)
  77. // CHECK:STDOUT: !16 = !DILocation(line: 15, column: 1, scope: !4)
  78. // CHECK:STDOUT: !17 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.e8193710fd35b608", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  79. // CHECK:STDOUT: !18 = !DILocation(line: 12, column: 3, scope: !17)