eval_musteval.carbon 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/definition/eval_musteval.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/definition/eval_musteval.carbon
  12. // --- eval.carbon
  13. library "[[@TEST_NAME]]";
  14. // Should emit a definition of `Eval`.
  15. eval fn Eval(a: i32) -> i32 {
  16. return a;
  17. }
  18. fn F() -> i32 {
  19. // Should not emit a call to `Eval`.
  20. return Eval(1);
  21. }
  22. fn G(n: i32) -> i32 {
  23. // Should emit a call to `Eval`.
  24. return Eval(n);
  25. }
  26. // --- musteval.carbon
  27. library "[[@TEST_NAME]]";
  28. // Should not emit a definition of `MustEval`.
  29. musteval fn MustEval(a: i32) -> i32 {
  30. return a;
  31. }
  32. // Should not emit a call to `MustEval`.
  33. fn F() -> i32 {
  34. return MustEval(1);
  35. }
  36. // CHECK:STDOUT: ; ModuleID = 'eval.carbon'
  37. // CHECK:STDOUT: source_filename = "eval.carbon"
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: ; Function Attrs: nounwind
  40. // CHECK:STDOUT: define i32 @_CEval.Main(i32 %a) #0 !dbg !4 {
  41. // CHECK:STDOUT: entry:
  42. // CHECK:STDOUT: ret i32 %a, !dbg !10
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: ; Function Attrs: nounwind
  46. // CHECK:STDOUT: define i32 @_CF.Main() #0 !dbg !11 {
  47. // CHECK:STDOUT: entry:
  48. // CHECK:STDOUT: ret i32 1, !dbg !14
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: ; Function Attrs: nounwind
  52. // CHECK:STDOUT: define i32 @_CG.Main(i32 %n) #0 !dbg !15 {
  53. // CHECK:STDOUT: entry:
  54. // CHECK:STDOUT: %Eval.call = call i32 @_CEval.Main(i32 %n), !dbg !18
  55. // CHECK:STDOUT: ret i32 %Eval.call, !dbg !19
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: attributes #0 = { nounwind }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  61. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  64. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  65. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  66. // CHECK:STDOUT: !3 = !DIFile(filename: "eval.carbon", directory: "")
  67. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Eval", linkageName: "_CEval.Main", scope: null, file: !3, line: 5, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
  68. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  69. // CHECK:STDOUT: !6 = !{!7, !7}
  70. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  71. // CHECK:STDOUT: !8 = !{!9}
  72. // CHECK:STDOUT: !9 = !DILocalVariable(arg: 1, scope: !4, type: !7)
  73. // CHECK:STDOUT: !10 = !DILocation(line: 6, column: 3, scope: !4)
  74. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 9, type: !12, spFlags: DISPFlagDefinition, unit: !2)
  75. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  76. // CHECK:STDOUT: !13 = !{!7}
  77. // CHECK:STDOUT: !14 = !DILocation(line: 11, column: 3, scope: !11)
  78. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main", scope: null, file: !3, line: 14, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !16)
  79. // CHECK:STDOUT: !16 = !{!17}
  80. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !15, type: !7)
  81. // CHECK:STDOUT: !18 = !DILocation(line: 16, column: 10, scope: !15)
  82. // CHECK:STDOUT: !19 = !DILocation(line: 16, column: 3, scope: !15)
  83. // CHECK:STDOUT: ; ModuleID = 'musteval.carbon'
  84. // CHECK:STDOUT: source_filename = "musteval.carbon"
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: ; Function Attrs: nounwind
  87. // CHECK:STDOUT: define i32 @_CF.Main() #0 !dbg !4 {
  88. // CHECK:STDOUT: entry:
  89. // CHECK:STDOUT: ret i32 1, !dbg !8
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: attributes #0 = { nounwind }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  95. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  98. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  99. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  100. // CHECK:STDOUT: !3 = !DIFile(filename: "musteval.carbon", directory: "")
  101. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 10, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  102. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  103. // CHECK:STDOUT: !6 = !{!7}
  104. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  105. // CHECK:STDOUT: !8 = !DILocation(line: 11, column: 3, scope: !4)