call_method.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/call_method.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_method.carbon
  12. class C {
  13. fn F[unused self: Self, T:! Core.Copy](x: T) -> T {
  14. return x;
  15. }
  16. }
  17. fn CallF() -> i32 {
  18. var c: C = {};
  19. var n: i32 = 0;
  20. return c.F(n);
  21. }
  22. // CHECK:STDOUT: ; ModuleID = 'call_method.carbon'
  23. // CHECK:STDOUT: source_filename = "call_method.carbon"
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: @C.val.loc20_3 = internal constant {} zeroinitializer
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: ; Function Attrs: nounwind
  28. // CHECK:STDOUT: define i32 @_CCallF.Main() #0 !dbg !4 {
  29. // CHECK:STDOUT: entry:
  30. // CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !8
  31. // CHECK:STDOUT: %n.var = alloca i32, align 4, !dbg !9
  32. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !8
  33. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %c.var, ptr align 1 @C.val.loc20_3, i64 0, i1 false), !dbg !8
  34. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %n.var), !dbg !9
  35. // CHECK:STDOUT: store i32 0, ptr %n.var, align 4, !dbg !9
  36. // CHECK:STDOUT: %.loc22_14 = load i32, ptr %n.var, align 4, !dbg !10
  37. // CHECK:STDOUT: %C.F.call = call i32 @_CF.C.Main.64ccbb8e5d9a0b8e(ptr %c.var, i32 %.loc22_14), !dbg !11
  38. // CHECK:STDOUT: call void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %n.var), !dbg !9
  39. // CHECK:STDOUT: call void @"_COp.71e25083d63c4d6c:core.Destroy.Core"(ptr %c.var), !dbg !8
  40. // CHECK:STDOUT: ret i32 %C.F.call, !dbg !12
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: ; Function Attrs: nounwind
  44. // CHECK:STDOUT: define weak_odr void @"_COp.7e389eab4a7e5487:core.Destroy.Core"(ptr %self) #0 !dbg !13 {
  45. // CHECK:STDOUT: entry:
  46. // CHECK:STDOUT: ret void, !dbg !18
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: ; Function Attrs: nounwind
  50. // CHECK:STDOUT: define weak_odr void @"_COp.71e25083d63c4d6c:core.Destroy.Core"(ptr %self) #0 !dbg !19 {
  51. // CHECK:STDOUT: entry:
  52. // CHECK:STDOUT: ret void, !dbg !25
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  56. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  59. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: ; Function Attrs: nounwind
  62. // CHECK:STDOUT: define linkonce_odr i32 @_CF.C.Main.64ccbb8e5d9a0b8e(ptr %self, i32 %x) #0 !dbg !26 {
  63. // CHECK:STDOUT: entry:
  64. // CHECK:STDOUT: ret i32 %x, !dbg !32
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: ; uselistorder directives
  68. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: attributes #0 = { nounwind }
  71. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  72. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  75. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  78. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  79. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  80. // CHECK:STDOUT: !3 = !DIFile(filename: "call_method.carbon", directory: "")
  81. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "CallF", linkageName: "_CCallF.Main", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  82. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  83. // CHECK:STDOUT: !6 = !{!7}
  84. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  85. // CHECK:STDOUT: !8 = !DILocation(line: 20, column: 3, scope: !4)
  86. // CHECK:STDOUT: !9 = !DILocation(line: 21, column: 3, scope: !4)
  87. // CHECK:STDOUT: !10 = !DILocation(line: 22, column: 14, scope: !4)
  88. // CHECK:STDOUT: !11 = !DILocation(line: 22, column: 10, scope: !4)
  89. // CHECK:STDOUT: !12 = !DILocation(line: 22, column: 3, scope: !4)
  90. // CHECK:STDOUT: !13 = distinct !DISubprogram(name: "Op", linkageName: "_COp.7e389eab4a7e5487:core.Destroy.Core", scope: null, file: !3, line: 21, type: !14, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !16)
  91. // CHECK:STDOUT: !14 = !DISubroutineType(types: !15)
  92. // CHECK:STDOUT: !15 = !{null, !7}
  93. // CHECK:STDOUT: !16 = !{!17}
  94. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !13, type: !7)
  95. // CHECK:STDOUT: !18 = !DILocation(line: 21, column: 3, scope: !13)
  96. // CHECK:STDOUT: !19 = distinct !DISubprogram(name: "Op", linkageName: "_COp.71e25083d63c4d6c:core.Destroy.Core", scope: null, file: !3, line: 20, type: !20, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !23)
  97. // CHECK:STDOUT: !20 = !DISubroutineType(types: !21)
  98. // CHECK:STDOUT: !21 = !{null, !22}
  99. // CHECK:STDOUT: !22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
  100. // CHECK:STDOUT: !23 = !{!24}
  101. // CHECK:STDOUT: !24 = !DILocalVariable(arg: 1, scope: !19, type: !22)
  102. // CHECK:STDOUT: !25 = !DILocation(line: 20, column: 3, scope: !19)
  103. // CHECK:STDOUT: !26 = distinct !DISubprogram(name: "F", linkageName: "_CF.C.Main.64ccbb8e5d9a0b8e", scope: null, file: !3, line: 14, type: !27, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29)
  104. // CHECK:STDOUT: !27 = !DISubroutineType(types: !28)
  105. // CHECK:STDOUT: !28 = !{!7, !22, !7}
  106. // CHECK:STDOUT: !29 = !{!30, !31}
  107. // CHECK:STDOUT: !30 = !DILocalVariable(arg: 1, scope: !26, type: !22)
  108. // CHECK:STDOUT: !31 = !DILocalVariable(arg: 2, scope: !26, type: !7)
  109. // CHECK:STDOUT: !32 = !DILocation(line: 15, column: 5, scope: !26)