call_basic_depth.carbon 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_depth.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_depth.carbon
  10. fn F[T:! type](x: T) {
  11. }
  12. fn H[T:! type](x: T) -> T {
  13. // This call crashes because check/eval does not emit a definition for H.
  14. // In G below, the call to H can be typechecked without needing a definition.
  15. // TODO: this needs to be resolved in check/eval.
  16. // F(x);
  17. return x;
  18. }
  19. fn G[T:! type](x: T) -> T {
  20. H(x);
  21. F(x);
  22. return x;
  23. }
  24. fn M() {
  25. var n: i32 = 0;
  26. var m: i32;
  27. F(n);
  28. m = G(n);
  29. // Adding something like this makes check/eval emit a definition for H, hence no crash.
  30. // m = H(n);
  31. }
  32. // CHECK:STDOUT: ; ModuleID = 'call_basic_depth.carbon'
  33. // CHECK:STDOUT: source_filename = "call_basic_depth.carbon"
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
  36. // CHECK:STDOUT: entry:
  37. // CHECK:STDOUT: %n.var = alloca i32, align 4, !dbg !7
  38. // CHECK:STDOUT: %m.var = alloca i32, align 4, !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: %.loc32 = load i32, ptr %n.var, align 4, !dbg !8
  43. // CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(i32 %.loc32), !dbg !9
  44. // CHECK:STDOUT: %.loc33 = load i32, ptr %n.var, align 4, !dbg !10
  45. // CHECK:STDOUT: %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %.loc33), !dbg !11
  46. // CHECK:STDOUT: store i32 %G.call, ptr %m.var, align 4, !dbg !12
  47. // CHECK:STDOUT: ret void, !dbg !13
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  51. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: define void @_CF.Main.b88d1103f417c6d4(i32 %x) !dbg !14 {
  54. // CHECK:STDOUT: entry:
  55. // CHECK:STDOUT: ret void, !dbg !15
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: define i32 @_CG.Main.b88d1103f417c6d4(i32 %x) !dbg !16 {
  59. // CHECK:STDOUT: entry:
  60. // CHECK:STDOUT: %H.call = call i32 @_CH.Main.b88d1103f417c6d4(i32 %x), !dbg !17
  61. // CHECK:STDOUT: call void @_CF.Main.b88d1103f417c6d4(i32 %x), !dbg !18
  62. // CHECK:STDOUT: ret i32 %x, !dbg !19
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: define i32 @_CH.Main.b88d1103f417c6d4(i32 %x) !dbg !20 {
  66. // CHECK:STDOUT: entry:
  67. // CHECK:STDOUT: ret i32 %x, !dbg !21
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: ; uselistorder directives
  71. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  76. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  79. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  80. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  81. // CHECK:STDOUT: !3 = !DIFile(filename: "call_basic_depth.carbon", directory: "")
  82. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  83. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  84. // CHECK:STDOUT: !6 = !{}
  85. // CHECK:STDOUT: !7 = !DILocation(line: 29, column: 3, scope: !4)
  86. // CHECK:STDOUT: !8 = !DILocation(line: 32, column: 5, scope: !4)
  87. // CHECK:STDOUT: !9 = !DILocation(line: 32, column: 3, scope: !4)
  88. // CHECK:STDOUT: !10 = !DILocation(line: 33, column: 9, scope: !4)
  89. // CHECK:STDOUT: !11 = !DILocation(line: 33, column: 7, scope: !4)
  90. // CHECK:STDOUT: !12 = !DILocation(line: 33, column: 3, scope: !4)
  91. // CHECK:STDOUT: !13 = !DILocation(line: 28, column: 1, scope: !4)
  92. // CHECK:STDOUT: !14 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  93. // CHECK:STDOUT: !15 = !DILocation(line: 11, column: 1, scope: !14)
  94. // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 22, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  95. // CHECK:STDOUT: !17 = !DILocation(line: 23, column: 3, scope: !16)
  96. // CHECK:STDOUT: !18 = !DILocation(line: 24, column: 3, scope: !16)
  97. // CHECK:STDOUT: !19 = !DILocation(line: 25, column: 3, scope: !16)
  98. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.b88d1103f417c6d4", scope: null, file: !3, line: 14, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  99. // CHECK:STDOUT: !21 = !DILocation(line: 19, column: 3, scope: !20)