call_basic.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_basic.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_basic.carbon
  10. fn F[T:! type](x: T) {
  11. }
  12. fn H[T:! type](x: T) {
  13. }
  14. fn G[T:! type](x: T) -> T {
  15. // TODO: the call below is crashing because proper type resolution to
  16. // use the G specific, not the G generic is not done yet.
  17. // H(T);
  18. return x;
  19. }
  20. fn M() {
  21. var n: i32 = 0;
  22. var m: i32;
  23. var p: f64 = 1.0;
  24. var q: f64;
  25. F(n);
  26. m = G(n);
  27. F(p);
  28. q = G(p);
  29. }
  30. // CHECK:STDOUT: ; ModuleID = 'call_basic.carbon'
  31. // CHECK:STDOUT: source_filename = "call_basic.carbon"
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
  34. // CHECK:STDOUT: entry:
  35. // CHECK:STDOUT: %n.var = alloca i32, align 4, !dbg !7
  36. // CHECK:STDOUT: %m.var = alloca i32, align 4, !dbg !7
  37. // CHECK:STDOUT: %p.var = alloca double, align 8, !dbg !7
  38. // CHECK:STDOUT: %q.var = alloca double, align 8, !dbg !7
  39. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 4, ptr %n.var), !dbg !7
  40. // CHECK:STDOUT: store i32 0, ptr %n.var, align 4, !dbg !7
  41. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 4, ptr %m.var), !dbg !7
  42. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %p.var), !dbg !7
  43. // CHECK:STDOUT: store double 1.000000e+00, ptr %p.var, align 8, !dbg !8
  44. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 8, ptr %q.var), !dbg !7
  45. // CHECK:STDOUT: %.loc31 = load i32, ptr %n.var, align 4, !dbg !9
  46. // CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(i32 %.loc31), !dbg !10
  47. // CHECK:STDOUT: %.loc32 = load i32, ptr %n.var, align 4, !dbg !11
  48. // CHECK:STDOUT: %G.call.loc32 = call i32 @_CG.Main.b88d1103f417c6d4(i32 %.loc32), !dbg !12
  49. // CHECK:STDOUT: store i32 %G.call.loc32, ptr %m.var, align 4, !dbg !13
  50. // CHECK:STDOUT: %.loc33 = load double, ptr %p.var, align 8, !dbg !14
  51. // CHECK:STDOUT: call void @_CF.Main.66be507887ceee78(double %.loc33), !dbg !15
  52. // CHECK:STDOUT: %.loc34 = load double, ptr %p.var, align 8, !dbg !16
  53. // CHECK:STDOUT: %G.call.loc34 = call double @_CG.Main.66be507887ceee78(double %.loc34), !dbg !17
  54. // CHECK:STDOUT: store double %G.call.loc34, ptr %q.var, align 8, !dbg !18
  55. // CHECK:STDOUT: ret void, !dbg !19
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  59. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: define void @_CF.Main.b88d1103f417c6d4(i32 %x) !dbg !20 {
  62. // CHECK:STDOUT: entry:
  63. // CHECK:STDOUT: ret void, !dbg !21
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: define i32 @_CG.Main.b88d1103f417c6d4(i32 %x) !dbg !22 {
  67. // CHECK:STDOUT: entry:
  68. // CHECK:STDOUT: ret i32 %x, !dbg !23
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: define void @_CF.Main.66be507887ceee78(double %x) !dbg !24 {
  72. // CHECK:STDOUT: entry:
  73. // CHECK:STDOUT: ret void, !dbg !25
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: define double @_CG.Main.66be507887ceee78(double %x) !dbg !26 {
  77. // CHECK:STDOUT: entry:
  78. // CHECK:STDOUT: ret double %x, !dbg !27
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: ; uselistorder directives
  82. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  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: "call_basic.carbon", directory: "")
  93. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 25, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  94. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  95. // CHECK:STDOUT: !6 = !{}
  96. // CHECK:STDOUT: !7 = !DILocation(line: 26, column: 3, scope: !4)
  97. // CHECK:STDOUT: !8 = !DILocation(line: 28, column: 3, scope: !4)
  98. // CHECK:STDOUT: !9 = !DILocation(line: 31, column: 5, scope: !4)
  99. // CHECK:STDOUT: !10 = !DILocation(line: 31, column: 3, scope: !4)
  100. // CHECK:STDOUT: !11 = !DILocation(line: 32, column: 9, scope: !4)
  101. // CHECK:STDOUT: !12 = !DILocation(line: 32, column: 7, scope: !4)
  102. // CHECK:STDOUT: !13 = !DILocation(line: 32, column: 3, scope: !4)
  103. // CHECK:STDOUT: !14 = !DILocation(line: 33, column: 5, scope: !4)
  104. // CHECK:STDOUT: !15 = !DILocation(line: 33, column: 3, scope: !4)
  105. // CHECK:STDOUT: !16 = !DILocation(line: 34, column: 9, scope: !4)
  106. // CHECK:STDOUT: !17 = !DILocation(line: 34, column: 7, scope: !4)
  107. // CHECK:STDOUT: !18 = !DILocation(line: 34, column: 3, scope: !4)
  108. // CHECK:STDOUT: !19 = !DILocation(line: 25, column: 1, scope: !4)
  109. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  110. // CHECK:STDOUT: !21 = !DILocation(line: 11, column: 1, scope: !20)
  111. // CHECK:STDOUT: !22 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 17, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  112. // CHECK:STDOUT: !23 = !DILocation(line: 21, column: 3, scope: !22)
  113. // CHECK:STDOUT: !24 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  114. // CHECK:STDOUT: !25 = !DILocation(line: 11, column: 1, scope: !24)
  115. // CHECK:STDOUT: !26 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 17, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  116. // CHECK:STDOUT: !27 = !DILocation(line: 21, column: 3, scope: !26)